	var myinterval;

	
	
$(document).ready(function(){ 
    var rt = '/dev/site6/';
    var cnt = 0;	
	
	var pg = document.title;
	

	if($('.rotatead').length > 0)
		setInterval('swapImage()', 5000);						   						   



	 /*         HOME              */


	
	//CART STUFF
	
	if($("#carttable").length > 0){
		$("#cart-info").slideDown(500).children().show();		
		$("#cart-menu").show(1);	
	}else if(window.location.href.indexOf("submit_order/thanks") != -1){
		$("#cart-menu").hide();	
	
	}else if(window.location.href.indexOf("submit_order") != -1){
		$("#cart-menu").show();	
	}
	
	$('.removeitem').livequery('click', function(event){	
		$.post(siteurl + "home/aj/removeFromCart/", {stockCode:  $(this).attr('stockcode')}, 	function(data){
			var str = "";
			if(!data.empty){
          $.each(data.parts, function(i,item){
				str += "<tr class='" + item.bo +  "'><td>" + i.replace(/_/g, " ") +  "</td><td>" + item.quantity +   "</td><td>" + item.desc + "</td><td>" + item.jobber + "</td><td><span class='removeitem' stockcode='" + i.replace(/_/g, " ") + "'>remove</span></td><td>" + item.bo + "</td></tr>";									  
        //   		str += "<tr><td>" + i.replace(/_/g, " ") +  "</td><td>" + item.quantity +   "</td><td>" + item.desc + "</td><td>" + item.jobber + "</td><td><span class='removeitem' stockcode='" + i.replace(/_/g, " ") + "'>remove</span></td></tr>";
			}); 			
			
				$("#cart").html("<table id='carttable'><thead>" + "<tr><th>Part No.</th> <th>Quantity</th><th>Description</th><th>Jobber</th> </tr></thead><tbody>" +  str + "</tbody></table>").show(1);
				$("#cart-info").slideDown(100).children().show(1);					
				$("#itemcount").html(data.quantity + " items in cart");	
			}else{
				$("#clearList").trigger("click");			
			}
		}, "json");
		setTimeout("handle_AddToCart()", 6000);
		restripe();
	 });
	$('#clear-order').livequery('click', function(event){	
		$ret = confirm("Are you sure you want to clear your order?");												  
		if($ret == true){
		$.ajax({
     	  type: "POST",
		  url: siteurl + "nms/livecart",
		  data:  {act:  "clear-order"},
		  success: function(){
			$("#your-order").slideUp(300);
		  },
		  error: function(r){
				alert("Error clearing order");
		  }
		});
		}else{
			return false;			
		}
	});


	$('.addToCart').livequery('click', function(event){	
		var code = 		($(this).parent().parent().find(':nth-child(2)').html()).replace(/\"/g, " ").replace("/$/g", "\$");
		var desc = 		($(this).parent().parent().find(':nth-child(4)').html()).replace(/\"/g, " ").replace("/$/g", "\$");		
		var retail = 	($(this).parent().parent().find(':nth-child(5)').html()).replace(/\"/g, " ").replace("/$/g", "\$");

	

		
		$.ajax({
     	  type: "POST",
		  url: siteurl + "nms/livecart",
		  data:  {stockCode:  $(this).attr('stockcode')},
		  dataType: "json",
		  success: function(data){
			update_cart(data);
		  },
		  error: function(r){
	
			alert("item not added"  + r.statusText + "\n" + r.responseText);
		  }
		});

					

												
												
		$("#cart-menu").slideDown(1000);								
										



		//restripe();
		});
	$('.minus').livequery('click', function(event){	
		var code = 		($(this).parent().parent().find(':nth-child(1)').html()).replace(/\"/g, " ").replace("/$/g", "\$");


		
		
		$.ajax({
     	  type: "POST",
		  url: siteurl + "nms/livecart",
		  data:  {stockCode:  code, act: "remove-one"},
		  dataType: "json",
		  success: function(data){
			update_cart(data);
			if(data.act == "clear-order"){
				$("#your-order").slideUp(300);
			}
		  },
		  error: function(r){
	
			alert("item not added"  + r.statusText + "\n" + r.responseText);
		  }
		});

		});
	
	$('.plus').livequery('click', function(event){	
		var code = 		($(this).parent().parent().find(':nth-child(1)').html()).replace(/\"/g, " ").replace("/$/g", "\$");


		code = code.trim();
		
		$.ajax({
     	  type: "POST",
		  url: siteurl + "nms/livecart",
		  data:  {stockCode:  code, act: "add-one"},
		  dataType: "json",
		  success: function(data){
			update_cart(data);
		  },
		  error: function(r){
	
			alert("item not added"  + r.statusText + "\n" + r.responseText);
		  }
		});

		});
	$(".plus").livequery("ajaxStart", (function(event){
	  	 $(this).addClass("plus1");
	  	 $(this).removeClass("plus");
		}));
	$(".plus1").livequery("ajaxStop", (function(event){
	  	 $(this).addClass("plus");
	  	 $(this).removeClass("plus1");

	}));
	$(".minus").livequery("ajaxStart", (function(event){
	  	 $(this).addClass("plus1");
	  	 $(this).removeClass("plus");
		}));
	$(".minus1").livequery("ajaxStop", (function(event){
	  	 $(this).addClass("plus");
	  	 $(this).removeClass("plus1");

	}));
	$("#order-table").livequery("ajaxStop", (function(event){
		$(this).find("tbody tr:even").addClass("even");									   
		$(this).find("tbody tr:odd").addClass("odd");									   		
   }));
	

	$("#searchtext").focus(function(){
	  if($(this).val() == "Search Our Site")
		$(this).val("");        
	});    

        
	$("#appguide_dd").livequery("click", function(event){
		if($(this).children().length < 4){
			$(this).load(siteurl + "nms/loadAppGuides");												   				
		}

   });
	$("#appguide_dd").livequery("change", function(event){
		$("html").css("overflow", "hidden");
		$("#externalframe, #framecloser").show();	
		$("#externalframe").css("top",document.documentElement.scrollTop + "px");		
		$("#framecloser").css("top",document.documentElement.scrollTop + "px");				
		$("#externalframe").attr("src", $(this).val());	
	});
		
	$("#clickclose").click(function(){
		$("html").css("overflow", "auto");					
		$("#framecloser").hide();
		$("#externalframe").attr("src", "");
		$("#externalframe").hide();
	 });
     
     //zebra stuff
     $(".linecard tr:even").addClass("evenrow");
     $(".linecard tr:odd").addClass("oddrow");    
     $(".resultstbl tbody tr:even, #order-table tbody tr:even").addClass("even");
     $(".resultstbl tbody tr:odd, #order-table tbody tr:odd").addClass("odd");        
     $('.sidewindow div ul li:odd').addClass("oddrow");        
     $('.sidewindow div ul li:even').addClass("evenrow");       
     //



	
/*		Products				*/	
	if($('.thickboxlink').length > 0)
	{
		var screenHeight = document.body.clientHeight - 100;	
		var screenWidth = document.body.clientWidth - 100;		
		var urlstring = "width=" + screenWidth + "&height=" + screenHeight;
		$('.thickboxlink').each(function(){					 
			$(this).attr("href", $(this).attr("href") + urlstring);										 
		});
	
	}
		/*
$(".mainsearchhelp").qtip({
   			content: 'You can search by a part number or a part of a part number or you can enter a keyword of a describing the part. You can search by a combination of both.  If you are looking for parts from a specific manufacturer you can select it from the drop down box.  The search is NOT case sensitive.  There is no need to use wildcards',
			   position: {
				  corner: {
					 target: 'center',
					 tooltip: 'topLeft'
				  }
			   },

   			style: { 
			width: 220,
			fontSize:	13,
			padding: 3,
			background: '#009A66',
			color: 'black',
			textAlign: 'left',
				 border: {
				 width: 5,
				 radius: 5,
				 color: '#444'
			},
	      	tip: 'topLeft',

      		name: 'dark' // Inherit the rest of the attributes from the preset dark style
		 	}
			});

			$(".prefixdd").qtip({
   			content: 'Selecting a manufacturer from this list ensures that all the part numbers in the results begin with the manufacturers code',
			   position: {
				  corner: {
					 target: 'center',
					 tooltip: 'topLeft'
				  }
			   },

   			style: { 
			width: 220,
			fontSize:	13,
			padding: 3,
			background: '#009A66',
			color: 'black',
			textAlign: 'left',
				 border: {
				 width: 5,
				 radius: 5,
				 color: '#444'
			},
	      	tip: 'topLeft',

      		name: 'dark' // Inherit the rest of the attributes from the preset dark style
		 	}
			});		
			
		$(".searchhelp").qtip({
   			content: 'Enter a part number or part of a part number and/or a keyword in the description of the item',
			   position: {
				  corner: {
					 target: 'center',
					 tooltip: 'topLeft'
				  }
			   },

   			style: { 
			width: 220,
			fontSize:	13,
			padding: 3,
			background: '#009A66',
			color: 'black',
			textAlign: 'left',
				 border: {
				 width: 5,
				 radius: 5,
				 color: '#444'
			},
	      	tip: 'topLeft',

      		name: 'dark' // Inherit the rest of the attributes from the preset dark style
		 	}
			});				
		
			$('.formlink, .pricelink').click(function(){
				$('#bodyheading').text($(this).text());						  
		  	});

*/
	$(document).click(function(e){
		var idstr = '#' + e.target.id;

		if(e.target.id.indexOf("menusearch") == -1)
		{

	      $('#menusearch').fadeOut(100);		
		}

	});



});    // end document ready


function rotate()
{



	str = siteurl + arr[cnt];
	$('#rotateimage').fadeTo(500, .01);
	setTimeout('change_src()', 500);
	
	if(cnt == arr.length -1)
		cnt = 0;	
	else
		cnt++;
		
		
	window.clearInterval($myinterval);
	$myinterval = window.setInterval('rotate()' ,15000);	

}
function fin()
{
	$('#rotateimage').fadeTo(500, 1);
}
function change_src()
{
	$('#rotateimage').attr("src", str);
	fin();
}

function upd(item_number)
{		
			$('#livelist').load(x + '/' + item_number);	
}
function clearList()
{
			$('#livelist').load(x + '/clear');
}
function getFile()
{
	
}
function swapImage()
{
	if($('.rotatead').attr('src').indexOf("ad1.png") == -1 )
	{
		$('.rotatead').fadeTo(500, .01);
		setTimeout("inOut(1)", 500);
		
	}
	else
	{
		$('.rotatead').fadeTo(500, .01);
		setTimeout("inOut(2)", 500);
	}
}

function inOut(n)
{
	$('.rotatead').attr('src', siteurl + 'images/ad' + n + '.png');
	$('.rotatead').fadeTo(300, 1);
	
}
function update_cart(data){
	$("#your-order").slideDown(300);
	
		$("#order-table").find("tbody").remove();
		$("#order-table").append("<tbody></tbody>")
	
	
	var s = ""
	 $.each(data.items, function(i,item){
		$("#order-table").find("tbody").append("<tr><td>" + i + '</td><td><div class="minus">-</span><td>' + item.quantity + '</td><td><div class="plus">+</span></td></tr>');
	 });			 
}