$().ready(function() {

	$.preload([ 'bottom, gradient, tile, top'], {
	    base:'/assets/chskv2/images/lpHoverDs/',
	    ext:'.png'
	});
	// set some minimum dimensions - techincally won't really matter anymore since the content is static
	var minWidth = 994;
	var minHeight = 736;
	var viewportWidth = $(window).width();
	if (viewportWidth < minWidth) { // min-width
		viewportWidth = minWidth;
	}
	var viewportHeight = $(window).height();
	if (viewportWidth < minHeight) { // min-height
		viewportHeight = minHeight;
	}
	// resize the background div so that it stretches the entire width/height of the viewport
	$("#background, #background img").css({
		'width':viewportWidth + 'px',
		'height':viewportHeight + 'px'
	});
	// on window resize, the background div needs to resize as well
	$(window).resize(function() { 
		var newViewportWidth = $(window).width();
		if (newViewportWidth < minWidth) { // min-width
			newViewportWidth = minWidth;
		}
		var newViewportHeight = $(window).height();
		if (newViewportHeight < minHeight) { // min-height
			newViewportHeight = minHeight;
		}
		$("#background, #background img").css({
			'width':newViewportWidth + 'px',
			'height':newViewportHeight + 'px'
		});
	});
	// using the suckerfish plugin again since the full screen video is gone
	// ie couldn't handle suckerfish plus full-screen flash video
	// the right aligned menus are intentional and the logic is in the supersubs plugin
    $("ul.sf-menu").supersubs({ 
        minWidth:12,
        maxWidth:27,
        extraWidth:1
    }).superfish({
	    hoverClass:'sfHover',
		delay:500,
		animation:{opacity:'show'},
		speed:'fast', 
	    autoArrows:false,
	    dropShadows:false,
	    disableHI:false
	});
	// simulate the drop down hover state to affect active/hover state
	$('#nav-home a').hover(
		function() {
			$(this).parent().addClass('sfHover');
		},
		function() {
			$(this).parent().removeClass('sfHover');
		}
	);
	// equalize the height of the landing page blocks
	
	$("#landing .lpLink").css({'height':equalize('#landing ol', 'li', '.lpLink')});
		
	$("a[rel='external']").click(function() {
		var page = $(this).attr('href');
		window.open(page,'newWindow');
		return false;
	});
	
	$("#landing li").click(function() {
		var href = $(this).find('a').attr('href');
		window.location.href = href;
	});
	
	$(".pd-fancybox").fancybox();
	
	$('.map-neighborhood .neigh-desc .close, .point3').click(function(){
		$('.map-neighborhood').fadeOut('fast');
	});
	
	$('.tooltip').hover(function(){
		$(this).addClass('zindex');
	}, function(){
		$(this).removeClass('zindex');
	});
	
	$('.tooltip').click(function() {
		if($('.property-map .pd-result').is(':visible')) {
			$(this).removeClass('zindex');
			$(this).siblings('.pd-result').hide();
			$(this).next('.property-map .pd-result').show();
		} 
		else {
			$('.map-neighborhood').fadeOut('fast');
			$(this).removeClass('zindex');
			$(this).next('.property-map .pd-result').fadeIn('fast');
		}
		
		if($(this).parent().parent().hasClass('map2')) {
			var leftOffset = $('.map2').position().left;
			var topOffset = $('.map2').position().top;
		
			$('.property-map .pd-result').css( {
				top: parseInt(855 - topOffset)+'px',
				right: parseInt(leftOffset - 845)+'px'
			});
		}
	})

	$(document).keyup(function(e) {
  		if (e.keyCode == 27) {
  			$('.property-map .pd-result').fadeOut('fast');
  			$('.map-neighborhood').fadeOut('fast');
  		}
	});
	
	// Hide/show functionality of home details in search panel
	$('.left-panel form .type-home #home').click(function(){
        if ($('.left-panel form .type-home #home').is(":checked"))
        {
            $('.left-panel form .type-home .home-detail').show();
        }
        else
        {     
            $('.left-panel form .type-home .home-detail').hide();
        }
      });
      
	$(function(){
		$("#neighborhood_select").change(function(){
		    window.location='/search_listings/neighborhood/' + this.value
	  	});
 	});
});
