$(document).ready(function(){
						   //CATALOGUE SCRIPTS
//change the cart Text
$("td.cartSummaryItem a[href^=/OrderRetrievev2]").text("Make your Enquiry");
$("td.cartSummaryItem:contains('Shopping cart')").text("No Enquiries Yet");


var breadcrumbs = $(".breadcrumbs a").length;
//alert(breadcrumbs)
if(breadcrumbs == 1){
	//alert("Theres more than 1 breadcrumbs")
	$("#catalogueContainer").show();
	$(".catalogueItem div.shop-catalogue").height("235px");
	$("#shopContainer").remove();
}
if(breadcrumbs > 1){
	//alert("Theres more than 1 breadcrumbs")
	$(".catalogueItem .shop-catalogue").height('50px');
	$(".catalogueItem div.image").remove();
	$("#catalogueContainer").show();
};	
if(breadcrumbs > 2){
	//alert("Theres more than 2 breadcrumbs")	
	$("#catalogueList").show('fast');
};	
	$(".shop-product-small div.image").tooltip({
											   position:'top center',
	
											   offset: [-60,0]
											   });

//PRODUCT LIST AND CHECKBOXRES

//make the list of products stack nicely by removing last to every 4th item

//$("ul.productList:nth-child(3n)").addClass("last");


	
//display the checkboxes if there's products on there
	
	//hide first
	
	$("#noProducts").css('display','none');
	$("#noKeywords").css('display','none');
	//check if there are products on the page
	if ($("ul.productList li div.shop-product-small").length){
		//if there is, show the options
		$("#searchOptions").show('fast');
		if ($("#related").length){
			$("#searchOptions").hide('fast');
			}
		}
		
	
	else{
		//make sure they stay hidden if not
		$("#searchOptions").css('display','none');	
		
	};
	if($("div#largeProduct").length > 0){
			$("#searchOptions").hide('fast').remove();
		
		};
//	get checked items and add them into an array



$("#keywords input,#manufacturers input").click(function(){
									$("#keywords li").css('background','#FFF');$("#manufacturers li").removeClass('selectedManufacturer');
									 $("ul.productList li.productItem, ul.productList li.productItemLast").show().removeClass('selectedManufacturer').removeClass('selectedKeywords').removeClass('selectedBoth');
									 $("#keywords li:has(input:checked)").css('background','#D0DCE8');
									  $("#manufacturers li input:checked").parent().addClass('selectedManufacturer');
									$("#noProducts").hide('fast');	
									$("#noKeywords").hide('fast');
									 //showManu();
									 showProducts();
									 if($("#manufacturers input:checked").length == 0){
													 $("a#showByManufacturer,a#showAllManufacturers").hide();
													 }
									if($("#keywords input:checked").length == 0){
													 $("a#showByKeyword,a#showAllKeywords").hide();
													 }
									 checkKeywords = [];
									 checkManu = [];
									});

function showProducts(){
//hide all the buttons

var checkManu = new Array;//array to store checked manufacturer values	
var checkKeywords = new Array;// array to store the checked Keywords values
 $("#manufacturers input:checked").each(function(i){
      checkManu[i] = $(this).val();	 //for each checkbox that is checked, add to array 
		
	});
  $("#keywords input:checked").each(function(i){
      checkKeywords[i] = $(this).val();//for each checkbox that is checked, add to array 
	});
	var checkKeywords = checkKeywords.join(', .');//join them back together with class attributes for jQuery
	var checkManu = checkManu.join(', .');
	//alert(checkManu);
	//checkKeywords = checkKeywords.toString();//change array to string
	
	
    if(checkManu != ''){
	$("a#showByManufacturer").show();
	$('.' + checkManu).parent().addClass('selectedManufacturer');
	if($('.' + checkManu).length == 0){
						//alert('No products by this Manufacturer on this page');
						$("#noProducts").show('fast');
						$("a#showByManufacturer,#a#showAllManufacturers").hide();
	}
	//$("ul.productList li.productItem, ul.productList li.productItemLast").hide('fast');																		
	//$("ul.productList li.selectedManufacturer").show('slow');	
					};
				
	if(checkKeywords != ''){
		$("a#showByKeyword").show();
		//var checkedKeywords = '.' + checkKeywords;
	$('.' + checkKeywords).parent().addClass('selectedKeywords');		
	if($('.selectedKeywords').length == 0 ){
						//alert('No products by this Manufacturer on this page');
						$("#noKeywords").show('fast');
		}
	$(".selectedKeywords.selectedManufacturer").addClass('selectedBoth');	
	 
	 };		
	 
	  
				
	
				
						
};
//show and Hide the buttons to show relevant products

//hide the buttons first
$("a#showByManufacturer, a#showAllManufacturers, a#showByKeyword, a#showAllKeywords, a#showByKeywordAndManufacturer, a#showAll").hide();


//show manufacturer button
$("a#showByManufacturer").click(function(){//if the 'hide other manufacturers' button is clicked
												 $(this).hide();//hide it
												 $("li.productItem, .productItemLast").hide('fast'); //hide all the products
												 $("a#showAllManufacturers").show();//show the 'show all' button
												 //$("ul.productList:nth-child(3n):visible").addClass("last");
												 $("li.selectedManufacturer").show('slow'); //show the selected ones
												 
												 });
$("a#showAllManufacturers").click(function(){
										 $(this).hide();//hide it
										 $("a#showByManufacturer").show();//show the 'hide others' button
										 $("li.productItem, .productItemLast").show('fast'); //show all the products
										 });
//show keywords button
$("a#showByKeyword").click(function(){//if the 'hide other manufacturers' button is clicked
												 $(this).hide();//hide it
												 $("li.productItem, .productItemLast").hide('fast'); //hide all the products
												 $("a#showAllKeywords").show();//show the 'show all' button
												 //$("ul.productList:nth-child(3n):visible").addClass("last");
												 $("li.selectedKeywords").show('slow'); //show the selected ones
												 
												 });
$("a#showAllKeywords").click(function(){
										 $(this).hide();//hide it
										 $("a#showByKeyword").show();//show the 'hide others' button
										 $("li.productItem, .productItemLast").show('fast'); //show all the products
										 });



$("#manufacturers ul li input:checkbox").click(function(){
												 
if($("#manufacturers li.selectedManufacturer").length >= 1){
		 //show the 'hide other manufacturers' button
		 $("#a#showAllManufacturers").show();
													   }
													   
												 });
//HIDE ALL FEATURED PRODUCTS IN THE MAIN TABS
	//$(".productfeaturelist li").css('display','none');
	//randomProduct();
	
//Truncate the Featured Product Description	
	//$("#featured .featuredProduct .description").truncate( 140,{
	//															chars: /\s/,
	//															trail: [ "  <br />(<strong><a href='#' class='truncate_show'>show more</a></strong>)", " <br />(<strong><a //href='#' class='truncate_hide'>hide</a></strong>)" ] });

$(".catalogueItem div.image:empty").each(function(){
												  $(this).addClass('emptyCatalogue');
												  });	
$("img").load().error(function(){
									$(this).addClass('emptyImage').attr('src','/Images/imageNotAvailable.jpg');				  
												  });
//remove empty linlks from the shop
$("div.poplets a[href='']").parent().remove();
								







	
});	

//wait until everything has loaded
$(window).load(function(){
						$("#catalogueSidebar div").css({
													   left:0
													   });
						if($("#catalogueSidebar:empty") && $("div#largeProduct").length){
														$("#catalogueSidebar").hide('fast');
														$("li.productItem").addClass('span-24');
														$("#largeProduct .span-18").removeClass('last');
							}
						$("p#loading").remove();
						
					});
