﻿/*
'--------------------------------------------------------------------------------------------------
' Title			: Site Wide JavaScript
' Description	: JavaScript functions and declarations for the entire site
'--------------------------------------------------------------------------------------------------
' History
' 09/02/2008	: DPE - Created Page
'--------------------------------------------------------------------------------------------------
*/

// Controls and validates the site Search form
function initSiteSearch(){
	
	if($j("TopBanner1_SimpleSearch1_txtSimpleSearch").attr("value") == ''){$j("TopBanner1_SimpleSearch1_txtSimpleSearch").attr({value:"Search Products"});}
	
	// Validate the form before submission...
	$j("TopBanner1_SimpleSearch1_btnSearch").click(
		function(){ // Validate search field...
			if($j("TopBanner1_SimpleSearch1_txtSimpleSearch").attr("value") == '' || $j("TopBanner1_SimpleSearch1_txtSimpleSearch").attr("value") == 'Search Products') {
				alert('Please enter a search term.');
				$j("TopBanner1_SimpleSearch1_txtSimpleSearch").focus();
				return false;
			} else {
				//return false;
				$j("#siteSearchForm").submit();
			}
			
		}
	);
	
	$j("TopBanner1_SimpleSearch1_txtSimpleSearch").focus(
		function(){ // highlight and clear the search field
			if($j("TopBanner1_SimpleSearch1_txtSimpleSearch").attr("value") == 'Search Products'){
				$j("TopBanner1_SimpleSearch1_txtSimpleSearch").attr({value:""});
				$j(this).css({color:"#3f2f13"});
				$j("#siteSearch").css({background:"transparent url('/site/img/searchFieldBkDn.gif') no-repeat"});
			}
		}
	);
	$j("TopBanner1_SimpleSearch1_txtSimpleSearch").blur(
		function(){ // highlight and clear the search field
			if($j(this).attr("value") == ''){
				$j(this).attr({value:"Search"});
				$j(this).css({color:"#b4a492"});
				$j("#siteSearch").css({background:"transparent url('/site/img/searchFieldBk.gif') no-repeat"});
			}
		}
	);
	
}

// Function for basic image rollover/mouseover actions throughout the site
function initMouseOvers() {
	// Preload the "Down" state images
	dnImgs = new Array(); // Array to hold the preloaded images
	$j("img.hvr").each(function(i,dnImgs){
		var dnImgSrc = $j(this).attr("src").replace(/-up/,"-dn");
		dnImgs[i] = new Image;
		dnImgs[i].src = dnImgSrc;
	});
	// Set the hover actions for each image
	$j("img.hvr").hover(
		function(){ // onMouseOver...
			if($j(this).attr("src").indexOf("-dn") == -1){
				var newSrc = $j(this).attr("src").replace(/-up/,"-dn");
				$j(this).attr("src",newSrc);
			}
		},
		function(){ // onMouseOut...
			if($j(this).attr("src").indexOf("-dn") != -1){
				var oldSrc = $j(this).attr("src").replace(/-dn/,"-up");
				$j(this).attr("src",oldSrc);
			}
		}
	);
	// Required workaround for PNG's moved to background images in WIN-IE6 and below (See function "pngFix" for details)
	$j("span.hvr").hover(
		function(){ // onMouseOver...
			if($j(this).css("filter").indexOf("-dn") == -1){
				var newSrc = $j(this).css("filter").replace(/-up/,"-dn");
				$j(this).css("filter",newSrc);
			}
		},
		function(){ // onMouseOut...
			if($j(this).css("filter").indexOf("-dn") != -1){
				var oldSrc = $j(this).css("filter").replace(/-dn/,"-up");
				$j(this).css("filter",oldSrc);
			}
		}
	);
}

// Fuction for animating the primary site navigation list
function initSiteNav(){
	
	// Setup the primary rollOver/mouseOver actions
	$j("#siteNav ul li:has(div)").hover(
		function(){	//onMouseOver...
			
			// Setup a reset of the base.css styles for our animations...
			var cssOverRide = {display:"block",overflow:"visible",position:"absolute",top:"0px",left:"140px",width:"1px"};

			// Stop any animiation in progress, apply the override CSS and flyout/animate the menu...
			if($j(this).find("div:first").hasClass("preview")) {
				$j(this).find("div:first").stop().css(cssOverRide).animate({left:"164px",width:"400px"},150);
			} else {
				$j(this).find("div:first").stop().css(cssOverRide).animate({left:"164px",width:"171px"},150);
			}

		},
		function(){	// onMouseOut...
			
			// Setup exit styles
			var cssOverRide = {position:"absolute",display:"none"};
			
			// Stop animation in progress, set CSS, and hide the menu...
			$j(this).find("div:first").stop().css(cssOverRide);
			
		}
	);
	
	// Add a class for our arrow background image
	$j("#siteNav ul li:has(div)").find("a:first").addClass("subCheck");
	
	// And fix IE6's crappy CSS support
	$j("#siteNav ul li").hover(
		function(){	//onMouseOver...
			$j(this).addClass("hover");
			$j(this).find("a:first").addClass("hover");
		},
		function(){	// onMouseOut...
			$j(this).removeClass("hover");
			$j(this).find("a:first").removeClass("hover");
		}
	);
	
	// One more fix for IE6...
	$j("#siteNav ul li:first").addClass("first");
}

function noenter() {
  return !(window.event && window.event.keyCode == 13); }


$j(document).ready(function(){
	//initMouseOvers();		// Initializes image rollover events
	initSiteNav();			// Initializes the SiteNav Menu
	initSiteSearch();		// Initializes the Site Search events

	if(typeof sIFR == "function"){ // Fancy Text for the page title...
		sIFR.replaceElement("h1.title", named({sFlashSrc:"/site/swf/sifr-myriadProCond.swf",sColor:"#a97c25",sWmode:"opaque"}));
	}
});

