/* 
------------------------------------------------
jquery.components.js
------------------------------------------------
Description:
------------------------------------------------
Brand-specific scripts for Regatta sites

This js file contains jquery components that
allow separate styles, layout and properties to
be applied for the brands so that the base jsp
/html remains untouched within commerce.
------------------------------------------------
Notes:
------------------------------------------------
1. Requires jquery.js (called before this file). 
2. Scripts applied when LayoutCointainerBottom.jsp
is passed to the browser (i.e. when main content has
already been loaded), so may be minute delay seen
when page load is slow.
------------------------------------------------
Version  Author  		Date/Update
------------------------------------------------
1.0		S.Fletcher		20.09.08
------------------------------------------------
*/

$(document).ready(function() {

// OPEN ALL ON READY()
//------------------------------------------------------------------------------------------


//------------------------------------------------------------------------------------------
// Global: use superfish plugin for animation & bgiframe plugin for ie6 bugs on drop-downs 
//------------------------------------------------------------------------------------------
	$("#navigation").superfish({
		animation : { opacity:"show", height:"show" }
		})
		.find(">li:has(ul)")
			.mouseover(function(){
				$("ul", this).bgiframe({opacity:false});
				})
				.find("a")
			.focus(function(){
		$("ul", $("#navigation>li:has(ul)")).bgiframe({opacity:false});
	});

// Only apply the following store specific if a logo div exists containing an anchor tag with an img
	if ($("#logo a img").length) {	
//------------------------------------------------------------------------------------------
// Hawkshead-specific
//------------------------------------------------------------------------------------------
		storeIsHawkshead = $("#logo a img").attr("alt").indexOf("Hawks");
		/* Match data-driven store name to Hawkshead */
		if (storeIsHawkshead!==-1){
			/* 1. Use search label in search field and hide label */
		  	var searchLabel = $('#CatalogSearchForm label').remove().text();
		  	$('#searchbox').addClass('placeholder').val(searchLabel).focus(function() {
		    	if (this.value == searchLabel) {
		     	 $(this).removeClass('placeholder').val('');
		    	};
		  	}).blur(function() {
		   	 	if (this.value == '') {
		    	  $(this).addClass('placeholder').val(searchLabel);
		   	 	};
		  	});
		 	$('#searchbutton').click(function() {
		   		if ($('#searchbox').val() == searchLabel) {
		      	$('#searchbox').val('');
		    	}
		  	});  
		  	$('#searchbutton').blur(function() {
		   	if ($('#searchbox').val() == '') {
		     	$('#searchbox').val(searchLabel);
		    	}
		  	}); 
		}
		else {}		
//------------------------------------------------------------------------------------------
// Craghoppers-specific
//------------------------------------------------------------------------------------------
		storeIsCraghoppers = $("#logo a img").attr("alt").indexOf("Craghoppers");
		/* Match data-driven store name to Craghoppers */
		if (storeIsCraghoppers!==-1){
			/* 1. Use search label in search field and hide label */
		  	var searchLabel = $('#CatalogSearchForm label').remove().text();
		  	$('#searchbox').addClass('placeholder').val(searchLabel).focus(function() {
		    	if (this.value == searchLabel) {
		     	 $(this).removeClass('placeholder').val('');
		    	};
		  	}).blur(function() {
		   	 	if (this.value == '') {
		    	  $(this).addClass('placeholder').val(searchLabel);
		   	 	};
		  	});
		 	$('#searchbutton').click(function() {
		   		if ($('#searchbox').val() == searchLabel) {
		      	$('#searchbox').val('');
		    	}
		  	});  
		  	$('#searchbutton').blur(function() {
		   	if ($('#searchbox').val() == '') {
		     	$('#searchbox').val(searchLabel);
		    	}
		  	}); 
		}
		else {}		
//------------------------------------------------------------------------------------------
// Bear Grylls-specific
//------------------------------------------------------------------------------------------
		storeIsBear = $("#logo a img").attr("alt").indexOf("Bear");
		/* Match data-driven store name to Bear Grylls */
		if (storeIsBear!==-1){
			/* 1. Replace search label without using properties file */
			$('#CatalogSearchForm .formstyle label').remove();
			$('#CatalogSearchForm .formstyle').append("<label for='searchbox'>Search this site...<\/label>");
			/* 2. Use search label in search field and hide label */
		  	var searchLabel = $('#CatalogSearchForm label').remove().text();
		  	$('#searchbox').addClass('placeholder').val(searchLabel).focus(function() {
		    	if (this.value == searchLabel) {
		     	 $(this).removeClass('placeholder').val('');
		    	};
		  	}).blur(function() {
		   	 	if (this.value == '') {
		    	  $(this).addClass('placeholder').val(searchLabel);
		   	 	};
		  	});
		 	$('#searchbutton').click(function() {
		   		if ($('#searchbox').val() == searchLabel) {
		      	$('#searchbox').val('');
		    	}
		  	});  
		  	$('#searchbutton').blur(function() {
		   	if ($('#searchbox').val() == '') {
		     	$('#searchbox').val(searchLabel);
		    	}
		  	}); 
		  	
			/* 3. add &nbsp in shopcart */
			$('.dash, .colon').append('<span>&nbsp;</span>');
		
			/* 4. remove title attr. from search button as interfering with usability */
			$('#searchbutton').attr('title','');
			
			/* 5. add additional div for bon mot/proverbs for category bkg */
			$('.categories #filters').after('<div id="bon_mot"></div>');
			
			/* 6. change colour of both links in minshopcart simultaneously using addClass */
			$('#minishopcart').mouseover(function(){
				$('#minishopcart a , #minishopcart a span').addClass('highlighted');
				//$('#minishopcart a span').addClass('highlighted');
			 });
			 
			/* 7. change colour back of both links in minshopcart simultaneously using removeClass */
			$('#minishopcart').mouseout(function(){
				$('#minishopcart a , #minishopcart a span').removeClass('highlighted');
				//$('#minishopcart a span').removeClass('highlighted');
			 });
		}
		else {}
	
//------------------------------------------------------------------------------------------
// Dare2B-specific
//------------------------------------------------------------------------------------------
		storeIsD2B = $("#logo a img").attr("alt").indexOf("2");
		/* Match data-driven store name to Dare2b */
		if (storeIsD2B!==-1){
		
			/* 1. Test if site is brochureware (flex-flow on). If not, move search to left using css */
			//var brochureWare = $('#header').find('#languageSelection');
			//if (brochureWare==-1){
				//$('#navigation li.last').removeClass('last').addClass('last_no_brochureware');
			//}
			//else {}

			/* 2. Replace label for Dare2b as cannot change property file */
			//$('#CatalogSearchForm .formstyle label').append(":");
			
			/* 3. change colour of both links in minshopcart simultaneously using addClass */
			$('#minishopcart').mouseover(function(){
				$('#minishopcart a , #minishopcart a span').addClass('highlighted');
				//$('#minishopcart a span').addClass('highlighted');
			 });
			 
			/* 4. change colour back of both links in minshopcart simultaneously using removeClass */
			$('#minishopcart').mouseout(function(){
				//$('#minishopcart a , #minishopcart a span').removeClass('highlighted');
				//$('#minishopcart a span').removeClass('highlighted');
			 });
			 
			/* 5. Remove drop-down category nav for D2B */
		      //	$('ul.subcategory').remove();
		      	
			/* 6. add additional div under filters */
			$('.categories #filters').after('<div id="filter_sub"></div>');
			
			/* 7. Hide promo/dicount <li> on PDP if empty  */
			var promoValue = $('div.detailsdisplay dl dd.action div.promo').find('a.discount');
			if (promoValue==-1){
				$('.detailsdisplay .action .promo').parent().remove();
				}
			else {}
			}
			
		else {}
	}
  
//------------------------------------------------------------------------------------------
// CLOSE ALL ON READY()

});	