// JavaScript Document

	function addBasketDiscrete(mypid){
		
    var str = $("#myproducts"+mypid).serialize();
	
	$("#basket").html('<img src="/products/images/spinner.gif">');
	$("#basket").load('/products/includes/add_product_discrete.php' , str );

	$("#myproducts"+mypid+"Btn").html('<img src="/products/images/spinner.gif">');
	
	$("#myproducts"+mypid+"Btn").delay(2000).queue(function(){ 
  		$(this).load('/products/ajax/buyBtn.php' , { mypid : mypid}); 
 		$(this).dequeue(); 
	});
	
		
	}

	function pageLoad(id, url) {
	$('#'+id).load(url);
	}



		function showMBBrand(brand) {
		//$("#BrandColB").load('/ajax/brands.php?brand='+brand);
		//window.document.getElementById('MBImage').src="/images/ID/"+brand+".png";
		window.document.getElementById(brand).src="/products/images/2010/interface/switch btns/switch-"+brand+"-2.png";
		
		}
		function restoreMBBrand(brand) {
		//$("#BrandColB").load('/ajax/brands.php?');
		//window.document.getElementById('MBImage').src="/images/ID/spacer.gif";
		window.document.getElementById(brand).src="/products/images/2010/interface/switch btns/switch-"+brand+".png";
		
		}
		function showTeam(team) {
		$("#teamContent").load('/products/ajax/team.php?team='+team);
		
		window.document.getElementById(team).src="/products/images/Team/"+team+"-large.png";
		
		}
		function restoreTeam(team) {
		window.document.getElementById(team).src="/products/images/Team/"+team+"-1.png";		
		}
		
		function showDirection(info) {
		$("#Directions").load('/products/ajax/direction.php?info='+info);
		}
        
		function swapDimage(component,mysrc) {
		$("#emp").attr('src','/products/images/components2/' + component + '/' + mysrc + '.gif');
		//alert ($("#emp").attr('src'));
		}
		
		function originalDimage(component) {
		$("#emp").attr('src','/products/images/components2/' + component + '/mainimage.gif');
		}
		
		function showComponent(id) {
		$("#partResults").load('/products/ajax/megaSearch.php',{ component:id, search: 'NULL'  });
		$("#partSwitch").html('<a href="javascript:showDiagram(true)">view diagram</a>');
		}
		
		
		function showPart(region){
		window.document.getElementById('lambrettaImage').src="/images/2010/ID/"+region+".png";	
		}	
		
		function setToolTip(id){
			
   			 $("#"+id).tooltip();
   			 $("#"+id).tooltip("option", "position", {offset: "0 190"});
		}
	
	function showResults(myPart, myBrand){
		//alert (myPart);
		
	 	//$("#partResults").css("display","inline");
	 	//$("#partResults").css("width","760px");
	 	//$("#partResults").css("min-height","510px");
	 	//$("#partResults").css("padding","0");
		$("#partResults").load('/products/ajax/megaSearch.php',{ search:myPart , brand:myBrand  });
		$("#partSwitch").html('<a href="javascript:showDiagram(true)">view diagram</a>');
	}
	
	
	
	function changeResults(myorder,mydirection,mylimit,mypages,mycomponet) {
	 $('#partResults').html = '<img src="/products/images/spinner.gif">'; 

	 $('#partResults').load('/products/ajax/megaSearch.php', {myorder: myorder, mydirection:mydirection, limit:mylimit, mypage:mypages, component: mycomponet}); 
 
 	}

	
	
 	function showSearch() { 
	alert("sorry testing");
	
	myPart = document.getElementById('search_name').value;
	
	if (myPart == "Enter your search text here"){
		myPart = "NULL";
	}
	myBrand = document.getElementById('myBrand').value;
	
 	if (myPart) { } else {
 	myPart = 'NULL';
	hrefpart = true;
 	}
 	if (myBrand) { } else {
 	myBrand = 'NULL';
	hrefBrand = true;
 	}
	if (hrefpart && hrefBrand) {
	window.location.href='/search/' + encodeURIComponent(hrefpart) + '/' + encodeURIComponent(hrefBrand) + '.html';
	} else {
	window.location.href='/search/' + encodeURIComponent(hrefpart) + '.html';
	}
	//showResults(myPart, myBrand)
	} 

	
	
	function closeInfo(){
		$("#dialog-message").dialog('close');
	}

		function showCat(url){
		window.document.location.href=url;
	}
		function goBrand(url){
		window.document.location.href="/tyre/brand/" + url + ".html";
	}
	function showInfo(region, id){
		$("#dialog-message").load('/products/ajax/info.php?info='+region);
                var helpBtnOffset = $('#' + id).offset();
                //width of element
                var helpBtnWidth = $('#' + id).width();
                //width of dialog box
                var dialogWidth = $('#dialog-message').dialog('option', 'width');
                
				//$('#dialog-message').dialog('option','position',[helpBtnOffset.left+helpBtnWidth-dialogWidth,helpBtnOffset.top-$(window).scrollTop()]);
				$('#dialog-message').dialog('option','position',[helpBtnOffset.left,helpBtnOffset.top-$(window).scrollTop()]);
	
                //x and y positions of dialog box
                //x position: add btn width and subtract dialog width from btn left offset
                //y postion: subtract window top postion from btn top offset if user scrolled
		
		$("#dialog-message").dialog('open');
		//$("#dialog-message").parents(".ui-dialog:first").find(".ui-dialog-titlebar-close").remove(); 
		$("#dialog-message").parents(".ui-dialog").find(".ui-dialog-titlebar").remove();
	
	};

	function showDiagram(show) {
		
		if (show){
		$("#partResults").html('<img src="/products/images/spinner.gif">');
		$("#partResults").load('/products/ajax/diagram.php');
		$("#partSwitch").html('<a href="javascript:showDiagram(false)">view parts list</a>');
			
		} else {
			// back to search
		//	showSearch()
		$("#partResults").html('<img src="/products/images/spinner.gif">');
		$("#partResults").load('/products/ajax/megaSearch.php');
		$("#partSwitch").html('<a href="javascript:showDiagram(true)">view diagram</a>');
		}
	}
	
	
		function showPart(region){
		window.document.getElementById('lambrettaImage').src="/products/images/2010/interface/ID/"+region+".png";	
	}	
	
 function showSearch(myPart) { 
 	if (myPart) {
 	var pars = 'search:' + myPart;
 	} else {
 	var pars = 'search:NULL';
 	}
	//alert('/ajax/results10.php?'+pars);
	 	//$("#partResults").css("display","inline");
	 	//$("#partResults").css("width","760px");
	 	//$("#partResults").css("min-height","490px");
	 	//$("#partResults").css("padding","0px");
	 	//$("#partResults").css("overflow","auto");
		
	window.location.href='/search/' + encodeURIComponent(myPart) + '.html';
		
	//	$("#partResults").load('/products/ajax/megaSearch.php', {search: myPart });
	} 
	
	function closeInfo(){
		$("#dialog-message").dialog('close');
	}
	function showCat(url){
		window.document.location.href=url;
	}
	
	function showBrand(brand) {
		//alert(brand);
		$("#BrandColC").load('/products/ajax/brands.php?brand='+brand);
		
	}
	
	function swapID(type,id) {
		
	 	$("#brandLayer").css("display","none");
	 	$("#bikeLayer").css("display","none");
	 	$("#"+id).css("display","inline");
	document.getElementById('idNav').src='/products/images/2010/btns/btn-id2.png';
	document.getElementById('brandNav').src='/products/images/2010/btns/btn-brand2.png';
	if (type == 'id') {		
	document.getElementById('idNav').src='/products/images/2010/btns/btn-id1.png';
	}
	if (type == 'brand') {		
	document.getElementById('brandNav').src='/products/images/2010/btns/btn-brand1.png';
	}
	}
	
	function swapSelect(id) {
		
	 	$("#catSearch").css("display","none");	
	 	$("#rangeSearch").css("display","none");	
	 	$("#manuSearch").css("display","none");	
	 	$("#" + id).css("display","inline");
		
	 	$("#manuSearchLink").attr("class","");
	 	$("#rangeSearchLink").attr("class","");
	 	$("#catSearchLink").attr("class","");		
		
	 	$("#" + id + "Link").addClass("selected");

	}
		
	function swapNavBtn(type, dir) {
	if (dir>1) {
	if ((type = 'id')) {		
	//document.getElementById('idNav').src='/images/2010/btns/btn-id2.png';
	}
	if ((type == 'brand')) {		
	document.getElementById('brandNav').src='/products/images/2010/btns/btn-brand2.png';
	}
			
		} else {
	if (type == 'id') {		
	document.getElementById('idNav').src='/products/images/2010/btns/btn-id1.png';
	}
	if (type == 'brand') {		
	document.getElementById('brandNav').src='/products/images/2010/btns/btn-brand1.png';
	}
	}
		
	}
	
	function showTags(mylayer) {
		$(mylayer).toggle();
		
		$('.scroll-pane').css('width','100%');
		//$('.scroll-pane').show().jScrollPane(
		//{
		//	showArrows: true,
		//	autoReinitialise : false
		//});

		}
		
	function addFilter (category, name){
		
		$("#filterList").load('/products/ajax/filterList.php', {addfilter: category + "," + name });
		$("#partResults").load('/products/ajax/megaSearch.php');
		
	}	
	function removeFilter (category){
		
		$("#filterList").load('/products/ajax/filterList.php', {removefilter: category });
		$("#partResults").load('/products/ajax/megaSearch.php');
		
	}		
	function addBrand (category){
		
		$("#filterList").load('/products/ajax/filterList.php', {addBrand: category });
		$("#partResults").load('/products/ajax/megaSearch.php');
		
	}	
	function removeBrand (category){
		
		$("#filterList").load('/products/ajax/filterList.php', {removeBrand: category });
		$("#partResults").load('/products/ajax/megaSearch.php');
		
	}

		function colorboxLink(url){
			//$("#colorBoxSheet").attr({href: "/css/colorbox.css"});
			$.colorbox({href:url,close:"close x",scrolling:false});
		 }

