$(document).ready(function(){

var rows = idproperties.length;

var height = document.body.clientHeight;

$(".propertyopen").click(function () {
  $("body").css({overflow:"hidden"});
  $("#cover").show();
  $("#cover").css({height:height});
  $("#slideshow").show();
  //$(".slidebody").html('');
  var id = $(this).attr('name');
  showproperty(id);
  hideSelects('hidden');
  window.scrollTo(0,0);
  return false;
});

$(".slideclose").click(function () {
  $("#slideshow").hide();
  $("#cover").hide();
  $("body").css({overflow:"visible"});
  hideSelects('visible');
  return false;
});

  function nextslide(id){
    //$(".slidebody").html('');
    if(id==parseInt(rows)-2){
        if(urlnext!=''){
          $(".slidebody").html("<div class='warning_loop'>To continue using the property slide show please click to <a href='"+urlnext+"'>load the next 25 listings</a> and click on the first property listing on top of the page.</div><div class='slidepagination'><span class='slideprev'><img src='images/slide_bt_prev_limit.jpg' border='0'></span></div>").find(".slideprev").click(function (){prevslide(id-1);}).end();
        }else{
          $(".slidebody").html("<div class='warning_loop'>Please, close slide show and return to first page</div>");
        }
      id=rows;
    }else{
    if(id==rows){id=0;}
    else{id=parseInt(id)+1;} 
    showproperty(id);
    $('#slideshow').css({background:"#fff url('images/slideshow.loading.gif') no-repeat fixed center center"});
  }}
  
  function prevslide(id){
    //$(".slidebody").html('');
    id=parseInt(id)-1; 
    showproperty(id);
    $('#slideshow').css({background:"#fff url('images/slideshow.loading.gif') no-repeat fixed center center"});
  }
  
  function showproperty(id){
    $(".slidebody").html('');
    var rand = Math.random();
    var pid = idproperties[id][0];
    var type = idproperties[id][1];
    if(id==0){
      $.get("slideshow.details.php?id="+pid+"&type="+type+"&rand="+rand, function(data){
           $(".slidebody").append(data+"<div class='slidepagination'><span class='slidenext'><img src='images/slide_bt_next_limit.jpg' border='0'></span></div>").find(".slidenext").click(function (){nextslide(id);}).end().find(".fave").click(function (){showproperty(id);}).end();
           $('#slideshow').css({background:"#fff"});
      });
    }else{
      $.get("slideshow.details.php?id="+pid+"&type="+type+"&rand="+rand, function(data){
           $(".slidebody").append(data+"<div class='slidepagination'><span class='slideprev'><img src='images/slide_bt_prev.jpg' border='0'></span><span class='slidenext'><img src='images/slide_bt_next.jpg' border='0'></span></div>").find(".slidenext").click(function (){nextslide(id);}).end().find(".slideprev").click(function (){prevslide(id);}).end().find(".fave").click(function (){showproperty(id);}).end();
           $('#slideshow').css({background:"#fff"});
      });
    }
  }
  
  function hideSelects(action) {
  //documentation for this script at http://www.shawnolson.net/a/1198/hide-select-menus-javascript.html
  //possible values for action are 'hidden' and 'visible'
  if (action!='visible'){action='hidden';}
    if (navigator.appName.indexOf("MSIE")) {
      for (var S = 0; S < document.forms.length; S++){
        for (var R = 0; R < document.forms[S].length; R++) {
          if (document.forms[S].elements[R].options) {
            document.forms[S].elements[R].style.visibility = action;
          }
        }
      }
    }
  }		
  
});