/*	SONY | SONY STYLE.COM - GLOBAL HEADER EVENT LISTENERS
 *	Author(s): 	Branden Thompson	| Front End Architect , Branden.Thompson at am dot sony dot com
 *				Jonathan Cheung 	| Sr. Flash Developer , Jonathan.Cheung at am dot sony dot com
 *
 *	Date:		April 17, 2009
 *
 *	JS FILE PRE-CONDITIONS:
 *	-------------------------------------------------------------------------------------------------
 *
 *		- Prototype must be included before this .js (or included functions) is referenced.
 *		
 *
 *
 *	FUNCTIONALITY THAT THIS JS WILL PROVIDE
 *	-------------------------------------------------------------------------------------------------
 *	
 *	[DESCRIPTION HERE]
*/

/* =================================================================================================== 
 * BEGIN Global Navigation Setup
 * ! Initialize the GlobalNavigation here
 * First we create the name of the variable to store the menu   
 * =================================================================================================== 
*/
//Global nav variable
var Sonystyle_global_naviation;
/* ! Next we setup the onLoad listener to initialize the globalNav  */
Event.observe(window, 'load', function(){
	
	//	BRT 7.26.09 - Because we do not have an event listener file for the category/subcategory page,
	//	this is the only place I can place this particular sIFR event listeners.  In subsequent releases,
	//	we should address this:
	
		// This is for any PromoSpots in the right rail.
	 	sIFR.replace(AvantGardeMedium, {
	  		 selector: '.rightRailSpotTitle',
	  		 css: ['.sIFR-root { color: #000000; font-size: 13px }'],
	  		 wmode: 'transparent',
	  		 preventWrap: false,
	  		 offsetTop: 2,
	 		 forceSingleLine: false 
		});

		//AJain double click prevention work arounds on mini cart link drop down 12.08.09
		$$('#headerMyCartSection a.topHeaderLink').invoke('observe','click',function(e) {
			$$('#myCartList .topHeaderMyCartLink').each( function(elem) {
				elem.removeClassName('disabled');
			});
		})
		$('myCartList').observe('mouseover', function(e){
			$$('#myCartList .topHeaderMyCartLink').each( function(elem) {
				if(!elem.hasClassName('observed')) {
					elem.observe('click', function(e){
						if(this.hasClassName('disabled')) {
							Event.stop(e);
							return false;
						} else {
							this.addClassName('disabled');
							return true;
						}
					});
					elem.addClassName('observed');
				} 
			})
		})	

		//END AJain double click prevention work arounds on mini cart link drop down 12.08.09



	// ================================================================================================================================================================ 
	// ! Initializing the global navigation
	//	Menu ( DIV NAME, NAME OF GLOBALE VAIRABLE HOLDING THE NAV, ONSTATE CLASS NAME, HAS SUBNAV CLASS NAME, HIGHLIGHT CLASS NAME )  
	// ================================================================================================================================================================ 
 	if ($('logoLoginSearchSection'))
 	{
	 	Sonystyle_global_naviation = new Menu('globalNavigation', 'Sonystyle_global_naviation', "Active", "hasOptions", "standBy");
	
		// ================================================================= 
		// ! The following function initializes the sonystyle header links   
		// ================================================================= 
	 	HeaderUtils.init();
	 	
	 	// ============================ 
		// ! Setup the global message   
		// ============================ 
	 	HeaderUtils.initGlobalMessage()
		
		// ================================= 
		// ! Initialize Login/Logoutrollover
		// ================================= 	
		HeaderUtils.loginInit();
	}	
	
	// ================================= 
	// ! Initialize Globale Flash text   
	// ================================= 
	initGlobalSiFR();
		
	// ================================= 
	// ! Initialize Search Box values
	// ================================= 	
	if ($('WC_CachedSidebarDisplay_FormInput_searchTerm_In_CatalogSearchForm_1'))
	{
		var searchBoxElement = $('WC_CachedSidebarDisplay_FormInput_searchTerm_In_CatalogSearchForm_1');
		if (searchBoxElement.value==''){
			searchBoxElement.value='Search';
		}
		
		Event.observe($('WC_CachedSidebarDisplay_FormInput_searchTerm_In_CatalogSearchForm_1'), "blur", function(e){	
			var element = Event.element(e)
			if(element.value==''){
				element.value='Search';
			}
		})
		
		// ================================= 
		// ! Clear Search Box values
		// ================================= 	
		Event.observe($('WC_CachedSidebarDisplay_FormInput_searchTerm_In_CatalogSearchForm_1'), "click", function(e){
			var element = Event.element(e)
			if(element.value=='Search'){
				element.value='';
			}
		})
	}
	
	// ================================= 
	// ! Submit Search Box validation
	// ================================= 
	if ($('CatalogSearchForm'))
	{
		Event.observe($('CatalogSearchForm'), "submit", function(e){
			var element = Event.element(e)
			if(element.keyword.value=='Search'){
				element.keyword.value='';
			}
			if (!prepareSearch(this)) Event.stop(e);
		})
	}
	// =====================================================
	// ! Adding Omniture tracking code to all Hero banners
	// =====================================================
	$$('a.categoryHeroBannerCTA').each(function(element){
		
		Event.observe($(element), 'click', function(evt){
			//If there's not a link for the CTA we trigger just the trackCMSpot function
			if (
				$(this).href.indexOf("#") == 0 ||
				$(this).href.indexOf("javascript:") > -1 ||
				typeof(element.onclick) == "function"
				)
			{
				trackCMSpot($(this).id);
			}else{
				//reads the href and rel to pass to the function
				_cmspotObject.trackCMSOmniture($(this).href, $(this).id);
				//Stops href from being followed
				Event.stop(evt);
			}
		});
	});
}, false);
/* =================================================================================================== 
 * END Global Navigation Setup
 * =================================================================================================== 
*/