/* REMOVE WHEN FIX IS IN expand/collapse CSE 'narrow by' sections */
	function FnMinMax(ul,h) {
		var nbClass = document.getElementById(ul).className
		if (nbClass == "block") {
			document.getElementById(ul).className = "hide";
			h.style.backgroundImage = "url(/contents/images/estores/buttons/maxi.gif)";
		} 
		else if (nbClass == "hide") {
			document.getElementById(ul).className = "block";
			h.style.backgroundImage = "url(/contents/images/estores/buttons/mini.gif)";
		}
	}
	
	/* show/hide CSE price comparison tabs */
	function FnGenTabOn(on,off1,off2,tabon,taboff1,taboff2) {
		document.getElementById(on).className = "csetab_content" + " csecontenton";
		document.getElementById(off1).className = "csetab_content" + " csecontentoff";
		document.getElementById(off2).className = "csetab_content" + " csecontentoff";
		document.getElementById(tabon).className = "csetab_generic" + " csetabgenon";
		document.getElementById(taboff1).className = "csetab_generic" + " csetabgenoff";
		document.getElementById(taboff2).className = "csetab_generic" + " csetabgenoff";
	}
	
	/*cse form val */
	function fnValSearch(field){
			if (document.getElementById(field).value === '') {
		  	alert("Please enter a search term"); 
				return false; 
			}
		}
		
		
		
//jQuery scripts
jQuery(document).ready(function($){
	

	// August 08 Prize Giveaway	
	if ($(".giveaway_aug08_topprizes").length > 0 ) showPrizeDetailsFn();
	if ($(".giveaway_aug08_otherprizes").length > 0 ) showPrizeDetailsFn();
	
	function showPrizeDetailsFn() {
		$(".prizeHover").hover(
			function () {
				$(this).children("span").show();
			},
			function () {
				$(this).children("span").hide();
			}
	
		);
		$(".giveaway_aug08_topprize1").hover(
			function () {
				$(this).children(".topPrizeDesc").show();
			},
			function () {
				$(this).children(".topPrizeDesc").hide();
			}
	
		);
	};
	
	
	
	// cseTabs toggle
	if ($(".cse_tabs").length > 0 ) cseTabsFn(); // If class .cse_tabs exists on the page then call function cseTabsFn
	
	function cseTabsFn() {
		var tabContainers = $('div.csetab_content'); // Build array of tab items	
		
		//var strHref = window.location.href; // Check whether there is a reference to a tab in the url and activate appropriate tab
		//if ( strHref.indexOf("#") > -1 ){
			//var intTab = strHref.substr(strHref.indexOf("#"));	
			//var intTab = intTab.length;	
			//var strTab = strHref.substr(strHref.indexOf("#")).substring(7,intTab);
			
			//tabContainers.hide().filter("#csecontenttab" + strTab).show(); // Hide all tab content except for active tab
			  
			//$('ul.cse_tabs li').removeClass('csetabgenon').addClass('csetabgenoff'); // Apply OFF class to all tab list items and remove ON class
			  //$("#csegenerictab" + strTab).removeClass('csetabgenoff').addClass('csetabgenon'); // Apply ON class to active tab list item and remove OFF class
			//strTab = "";
		//}
		var strQuery = window.location.search.substring(1);
		if ( strQuery.indexOf("&") > -1 ){
			var strVars = strQuery.split("&");
			for (var i=0;i<strVars.length;i++) {
				var strTab = strVars[i].split("=");
				if (strTab[0] == "csetab") {
					tabContainers.hide().filter("#csecontenttab" + strTab[1]).show(); // Hide all tab content except for active tab
					  
					$('ul.cse_tabs li').removeClass('csetabgenon').addClass('csetabgenoff'); // Apply OFF class to all tab list items and remove ON class
					  $("#csegenerictab" + strTab[1]).removeClass('csetabgenoff').addClass('csetabgenon'); // Apply ON class to active tab list item and remove OFF class
					strTab = "";
				}
			}
		}
		
	  function cseTabsSHFn() {
			var strTab = "";
			var intTab = $(this).attr("href").length; // get clicked item's href length
			strTab = $(this).attr("href").substring(7,intTab); // get tab number from href
			//alert(strTab);
			tabContainers.hide().filter("#csecontenttab" + strTab).show(); // Hide all tab content except for active tab
			
			$('ul.cse_tabs li').removeClass('csetabgenon').addClass('csetabgenoff'); // Apply OFF class to all tab list items and remove ON class
			$("#csegenerictab" + strTab).removeClass('csetabgenoff').addClass('csetabgenon'); // Apply ON class to active tab list item and remove OFF class
			return false;
		}
		
		$('ul.cse_tabs a').click(cseTabsSHFn); // Call function cseTabsSHFn when this item clicked
		$('p.pri_comp_review a').click(cseTabsSHFn);
		$('p.pri_comp_info a').click(cseTabsSHFn);

	}
	
	// Inject rel="lightbox" attribute into "view larger image" anchor to trigger lightbox code 
	$(".pri_comp_itemimg > a").attr({rel: "lightbox"}).end();
	$('a[@rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel and apply lightbox
	
	//call cseNBCleanFn if narrow by section exists
	if ($(".cse_nb").length > 0 ) cseNBCleanFn();
	//reduce size of retailer and manufacturer narrow by items to display only 5 and inject "show all" option
	function cseNBCleanFn() {
		$(".cse_nb > #cse_nbretailer > li:gt(4)").hide().parent().append("<li class='cse_nbshowall'><a href='#'>Show all</a></li>");
		$(".cse_nb > #cse_nbmanufacturer > li:gt(4)").hide().parent().append("<li class='cse_nbshowall'><a href='#'>Show all</a></li>");		
	}
	$(".cse_nbshowall > a").click(cseNBShowAllFn); //call cseNBShowAllFn function when 'show all' is clicked
	
	//Ajax call for 'narrow by' sub sections
	$(".cse_nb > h4:gt(8) > a")
		.click(function(){
			var nbList = $(this).attr("href");
			var nbH = $(this).parent();
			$.ajax({
		    url: nbList,
		    type: 'POST',
		    dataType: 'html',
				timeout: 10000,
		    error: function(){
		        alert('Error loading list');
		    },
		    success: function(html){
		      var result = [ $(html).filter("div").html() ];
					$(nbH).replaceWith("" + result);
					
					var nbH2 = $(nbH).text().toLowerCase().replace(/^\s+|\s+$/g, ''); // get the h4's text, lower case it and trim it
					//nbH2 = nbH2.replace(" ","_"); 
					// replace any spaces inside h4 text with _
					space = " ";
					while (nbH2.indexOf(space)>-1) {
						int = nbH2.indexOf(space);
						nbH2 = "" + (nbH2.substring(0, int) + "_" + nbH2.substring((int + space.length), nbH2.length));
					}
					
					$("ul[id$=" + nbH2 + "]").children("li:gt(4)").hide().parent().append("<li class='cse_nbshowall'><a href='#'>Show all</a></li>"); // look for the list with id ending with h4 text and apply 'show all' link
					$(".cse_nbshowall > a").click(cseNBShowAllFn); //call cseNBShowAllFn function when 'show all' is clicked (this has to be repeated inside Ajax call because content is not loaded on page load)
		    }
			}); 
		return false;
	})
	.end();		
	
	//Narrow by nested 'Show all' click function
	function cseNBShowAllFn() {
		$(this).parent().parent().children().show().filter(".cse_nbshowall").hide();
		//alert(this);
		return false;
	}
	
	if ($("#retailerListStatic").length > 0 ) retailerListFn();
	
	function retailerListFn() {
		$("#retailerListStatic").removeAttr("id");
		
		$(".retListHover").hover(
			function () {
        $(this).next().show();
      }, 
      function () {
        $(this).next().hide();
      }
			);
	};
	
});
