jQuery(function(){
    jQuery('ul.sf-menu').superfish();
});

    
$(function(){
  $("img.callout").mouseover(function() {
      $(this).next().fadeIn('fast');
   })
  $("img.callout-hover").mouseout(function() {
    $(this).fadeOut('slow');
  })
  
  $(function(){
    $('div.location-map-thumb a').colorbox();
  });
  
  $(document).ready(function(){
  
    $(".prestige-result-callback").hide();
    $('.prestige-result-callback-link').click(function(){
      $(this).parents('.prestige-result').find('.prestige-result-callback').slideToggle();
      return false;
    });
    
    $("div.callback").hide();
    if (window.location.hash == 'property-view') {
      $("div.callback").show();
    }
    else if (window.location.hash != '') {
      $(window.location.hash + ' div.callback').show();
      $(window.location.hash + ' .prestige-result-callback').show();
    }
    
    $("a.callback-link, .prestige-result-callback-link").show();
    $("a.callback-link").click(function() {
      $(this).parent().next().next().next().slideToggle();
      return false;
    });
      
    $(".detail-block-content").hide();

    $("a.expandable-toggle").click(function() {
      $(this).parent().next().slideToggle();
      return false;
    });
   
    $("a#error-friend").click(function() {
      $("h3#expand-friend").next().slideDown();
    });
   
    $("a#error-callback").click(function() {
      $("h3#expand-callback").next().slideDown();
    });
   
     $("a.portal").click(function(){
       var id = this.id.replace('-btn', '');
       hideAll();
       $('#' + id).next().slideDown();
     });
     
     $("a#expand-specs-details-btn").click(function(){
       hideAll();
       $("h3#expand-specs").next().slideDown();
     });
     
     $("a#expand-specs-details-btn").click(function(){
       $("h3#expand-specs").next().slideDown();
     });
     
     $("a#expand-callback-foot-btn").click(function(){
       hideAll();
       $("h3#expand-callback").next().slideDown();
     });

    function hideAll(){
      $("a.expandable-toggle").each(function() {

       if($(this).hasClass("open")){
         click(function() {
           $this().parent().next().slideDown();
         });
       };
       $(this).parent().next().slideUp();
      });
    };
  });
});

$(document).ready(function(){

   $("a.search-result-thumb").mouseover(function(){
     $(this).next().toggle();
   });
   
   $("a.search-result-hover").mouseout(function(){
     $(this).hide();
   });

  $('#banner-images img').css({opacity: 0.0});
  $('#banner-images img:first').css({opacity: 1.0});
  setInterval('gallery()',5000);
        gallery();
        
        
  $('#homepageSearch input[type=radio], #search input[type=radio]').click(function(){
    var self = $(this), options = $('#homepageSearch .searchOptions, #search .search'), button = $('div#search input.moveLeft, div.submit input.moveLeft');
    if (self.val() == 'to_rent'){
      button.hide();
      options.slideUp(function(){
        button.css('float', 'none');
        button.show();
      });
      
    } else {
      button.css('float', 'right');
      options.slideDown();
    }
  });

  $('.homepage-featured-prestige').show();
  $('#featured-properties').jcarousel({auto: 7, animation: 500, wrap: 'circular'});
  $("#homepage-prestige-tab" ).tabs({fx: {opacity: 'toggle', duration: 500}}).tabs('rotate', 6500);
  
  $('#property-thumbs a').colorbox({maxWidth:'95%'});
  
  $('.room_detail_right a').colorbox({maxWidth:'95%'});
});

function gallery() {
  var current = ($('#banner-images img.show')?  $('#banner-images img.show') : $('#banner-images img:first'));
  if (current.next().length){
    if (current.next().hasClass('homeGallery')){
       var next = current.next();
    } else {
      var next = $('#banner-images img:first')
    }
  } else {
   var next = $('#banner-images img:first')
  }
  
  next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 2000);
  current.animate({opacity: 0.0}, 2000).removeClass('show');
}

function proptypeBoxes(index){
  var type_checkboxes = document.getElementsByName("prop_type[]");
  for (var i = 0; i < type_checkboxes.length; i++){
    if(index.value!=''){
      document.getElementById('all_proptypes').checked = false;
    }
    else if(index.value==''){
      type_checkboxes[i].checked = false;
    }
  }
}
  
function locationBoxes(index){
  var type_checkboxes = document.getElementsByName("location[]");
  for (var i = 0; i < type_checkboxes.length; i++){
  if(index.value!=''){
    document.getElementById('all_locations').checked = false;
  }
    else if(index.value==''){
      type_checkboxes[i].checked = false;
    }
  }
}

function clearText(field){
  if (field.defaultValue == field.value) field.value = '';
  else if (field.value == '') field.value = field.defaultValue;
}
