/* Hammcok Bay javascript */

search_block_status = "shown";

var is_msie6 = (navigator.appVersion.indexOf("MSIE 6.0") != -1);



function toggleHmSrchImg(siteID) {
	var currentImg = $('#search_block_image').attr("src");
	if(currentImg.substring(currentImg.length - 8) == "plus.gif") {
		$('#search_block_image').attr("src","/content/" + siteID + "/images/minus.gif");
	} else {
		$('#search_block_image').attr("src","/content/" + siteID + "/images/plus.gif");
	}
	if(search_block_status == "shown") {
		$('#inventory_search_block_form').animate({ height:"hide" }, { queue:true, duration:500 });
		search_block_status = "hidden";
	} else {
		$('#inventory_search_block_form').animate({ height:"show" }, { queue:true, duration:500 });
		search_block_status = "shown";
	}
	return false;
}

// search left-side nav for correct active link for residence detail pages
function check_url() {
	if(location.href.search(/new-homes\/inventory\//) > -1 ) {
		$("#block-menu-79 a[href='/new-homes/search/quick-delivery']").addClass("active");
	}
	return false;	
}



/**
 * hammock bay menu setup 
 */
var wci_menu = {
	no_menu: false,
	menu_top: "38px",
	menu_delay: 2000, // millis
	init: function() {
		if (!this.no_menu) {
			$('#experience,#new-homes,#thelocation').hover(
				function() {
					var mid = '#' + $(this).attr('id');
					wci_menu.change_active(mid);
					$(this).find('.sub_menu').css({
						top: wci_menu.menu_top,
						display:"none"
					}).show();
				},
				function() {
					var mid = '#' + $(this).attr('id');
					wci_menu.queue_close(mid);
					
				}
				
			);
					
		}
		
		// dropdown menu item hover
		$('.sub_menu li').bind("mouseenter mouseleave", 
			function(e){
				$(this).toggleClass("sfHover");
			}
		);
		
			
		// reposition bg img for home menu button
		$('#home').hover(
			function(){
				$(this).find("a:not(.active_menu)").css({
					backgroundPosition:"1px 0px"
				});
				wci_menu.change_active('#home');
			},
			
			
			function() {
				$(this).find("a:not(.active_menu)").css({
					backgroundPosition:"1px -38px"
				});
			}
		);
		
		// reposition bg img for experience menu button
		$('#experience').hover(
			function(){
				$(this).find("a:not(.active_menu)").css({
					backgroundPosition:"-120px 0px"
				});
				wci_menu.change_active('#experience');
			},
			function() {
				if (wci_menu.no_menu) {
					$(this).find("a:not(.active_menu)").css({
						backgroundPosition:"-120px -38px"
					});
				}
			}
		);
		
		// reposition bg img for new-homes menu button
		$('#new-homes').hover(
			function(){
				$(this).find("a:not(.active_menu)").css({
					backgroundPosition:"-270px 0px"
				});
				wci_menu.change_active('#new-homes');
			},
			function() {
				if (wci_menu.no_menu) {
					$(this).find("a:not(.active_menu)").css({
						backgroundPosition:"-270px -38px"
					});
				}
			}
		);
		
		// reposition bg img for thelocation menu button
		$('#thelocation').hover(
			function(){
				$(this).find("a:not(.active_menu)").css({
					backgroundPosition:"-370px 0px"
				});
				wci_menu.change_active('#thelocation');
			},
			function() {
				if (wci_menu.no_menu) {
					$(this).find("a:not(.active_menu)").css({
						backgroundPosition:"-370px -38px"
					});
				}
			}
		);
		
		// reposition bg img for contact menu button
		$('#contact').hover(
			function(){
				$(this).find("a:not(.active_menu)").css({
					backgroundPosition:"-500px 0px"
				});
				wci_menu.change_active('#contact');				
			},
			function() {
				$(this).find("a:not(.active_menu)").css({
					backgroundPosition:"-500px -38px"
				});
			}
		);
			

	},
	change_active: function(mid) {
		if (mid != this.menu_active) {
			this.close();
			this.queue_reset();
			this.menu_active = mid;
		} else if (this.menu_active != null) {
			this.queue_reset();
		}
		
	},
	queue_close: function(mid) {
		clearTimeout(this.menu_timer);
		this.menu_timer = setTimeout(
			function() {
				wci_menu.close();
			},
			this.menu_delay
		);
	},
	queue_reset: function() {
		clearTimeout(this.menu_timer);
	},
	close: function() {
		if (this.menu_active == null) { 
			return; 
		}

		$(wci_menu.menu_active).find('.sub_menu').fadeOut(1,  // fade out menu 
			function() {

				// only after the fade to do move the menu off screen
				$(this).css({
						top: "-999em"
				});

				var p = $(this).parent();
				var pid = p.attr("id");

				// for the 3 drop down menus, only reposition the image after the menu is gone
				switch (pid) {
						case "experience":
								p.find("a:not(.active_menu)").css({
										backgroundPosition:"-120px -38px"
								});
								
								p.find("a:not(.active_menu)").css({
										backgroundPosition:"-120px -38px"
								});
						break;
						case "new-homes":
								p.find("a:not(.active_menu)").css({
										backgroundPosition:"-270px -38px"
								});
						break;
						case "thelocation":
								p.find("a:not(.active_menu)").css({
										backgroundPosition:"-370px -38px"
								});
						break;
				}
			}
		);
		
	},
	menu_active: null,
	menu_timer: null
};


var passions_sifr = {
	src: '/content/41/flash/sifr/sifr-passions.swf'
};


sIFR.activate(passions_sifr);
sIFR.replace(passions_sifr, 
{
	selector: 'h1.sifr, a.sifr, h4.sifr',
	wmode: 'transparent',
	css: {
        '.sIFR-root': { 'color': '#FFFFFF', 'letter-spacing': 1, 'leading': -5}
		},	
		
		
	filters: {
    	DropShadowFilter: {
			strength: 1,
			blurY: 7,
			blurX: 7,
			alpha: .6,
			distance:4
		}
	}


	,	selectable: true
});



sIFR.replace(passions_sifr, 
{
	
		
	selector: 'h2.sifr',
	wmode: 'transparent',
	css: {
        '.sIFR-root': { 'color': '#7d1b1e', 'letter-spacing': 1,  'leading': -5}
		},	
		
		
	filters: {
    	DropShadowFilter: {
			strength: 1,
			blurY: 7,
			blurX: 7,
			alpha: .6,
			distance:4
		}
	}


	,	selectable: true
});

sIFR.replace(passions_sifr, 
{
	
		
	selector: 'h3.sifr',
	wmode: 'transparent',
	css: {
        '.sIFR-root': { 'color': '#7d1b1e', 'letter-spacing': 1,  'leading': -5}
		},	
		
		
	filters: {
    	DropShadowFilter: {
			strength: 1,
			blurY: 7,
			blurX: 7,
			alpha: .6,
			distance:4
		}
	}


	,	selectable: true
});





function trackPage(uri) {
	if (typeof(pageTracker) != "undefined") {
		pageTracker._trackPageview(uri);
	}
}


$(document).ready(function() {


	wci_menu.init();

	if (!jQuery.support.opacity) {
		$('.img_png').pngFix();
	}

	check_url();
});


