	var myinterval;
$(document).ready(function(){ 
	var yz = document.height;					   

    var rt = '/dev/site9/';
    var cnt = 0;	
	
	var pg = document.title;
	var num = 0;
	tmp = Math.ceil(Math.random() * 2);
	if(tmp % 2 == 1)
		var eodiv = 'div:odd';
	else
		var eodiv = 'div:even';
	$(".innerad").find(eodiv).each(function(){	
			//$(this).hide();
	});

	if($('.rotatead').length > 0)
		setInterval('swapImage()', 5000);						   						   

// CART FUNCTIONS

	if($("#carttable").length > 0){
		$("#cart-info").slideDown(500).children().show();		
		$("#cart-menu").show();	
	}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><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 class='" + item.bo +  "'>" + 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();
	 });

	$('.addToCart').livequery('click', function(event){	
		$("#cart-menu").slideDown(1000);								
										
		var code = 		($(this).parent().parent().find(':nth-child(1)').html()).replace(/\"/g, " ").replace("/$/g", "\$");
		var desc = 		($(this).parent().parent().find(':nth-child(3)').html()).replace(/\"/g, " ").replace("/$/g", "\$");		
		var retail = 	($(this).parent().parent().find(':nth-child(4)').html()).replace(/\"/g, " ").replace("/$/g", "\$");
		var jobber = 	($(this).parent().parent().find(':nth-child(5)').html()).replace(/\"/g, " ").replace("/$/g", "\$");	
		$.post(siteurl + "home/aj/addToCart/", {stockCode:  $(this).attr('stockcode'), code: code, desc:desc, jobber:jobber, retail:retail}, 
		function(data){		
			var str = "";	

          	$.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>";
			}); 
		  
		  		$("#added-to-cart").show().children().show();
				$("#cart-added-list").prepend("<li>" + data.quantity +  ": "  +  data.current  + " added to order</li>");
				setTimeout("handle_AddToCart()", 6000);
				$("#cart").html("<table class='zebra' 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");
				$("#itemadded").html(data.current.replace(/_/g, " ") + " added").jFade({
					property: 'background',
					start: '247E57',
					end: '000000',
					steps: 30,
					duration: 30
				}).css('background', 'none');				
			
			}, "json"); 

		restripe();
		});

		var COOKIE_NAME = 'first_visit_cookie1';
		var options = { path: '/', expires: 1000 };
	
		if(!$.cookie(COOKIE_NAME)){
			$.cookie(COOKIE_NAME, 'test', options);
			alert("The Marcor Dealer Portal now allows you to place orders right online!  (Beta Version)\n  \n  To add items to your order use the search field on the left.  From the results click the shopping cart icon on the right of the item you wish to order.  Click the link in the search area on the left for more information.  \n\n We will continually be adding features and improvements");
			
		}

	
	$('#clearList, #clearListLeft').livequery('click', function(event){
		var ans = confirm("Are you sure you want to clear your order?", "Confirm");
		if(ans){
			$('#cart').load(siteurl + "home/aj/clearlist"); 
			$("#cart-info").hide(100).children().hide();
			$("#cart-form").hide(100).children().hide();
	//		$('#cart-pulldown').html(cartImg + "View Order Details");				
			$("#itemadded").html('');
			$("#cart-menu").hide();
			window.location = siteurl;
		}else{ return false; }
	});
	
	$('#cart-info').livequery('click', function(event){	
		$('#submitorder').show(1);												
		$('#cart-form').slideToggle(500, function(){												  
			$('#cart-form:hidden').each(function(){
	 			$('#cart-form').children().hide()												 
				 $('#cart-pulldown').html(cartImg + "View Order Details");				  
			 });
			$('#cart-form:visible').each(function(){
  	 			$('#cart-form').children().show()
				 $('#cart-pulldown').html(cartImg + "Hide Order Details");				  
			 });
		});
		restripe();
	});
	
	$('#cart-info').livequery('mouseover', function(event){	
		$(this).css('backgroundColor', "#1F7754");
		$(this).css('borderColor', "black");
	});
	$('#cart-info').livequery('mouseout', function(event){	
		$(this).css('backgroundColor', "black");
		$(this).css('borderColor', "black");
	});
//  /cart functions





	 /*         HOME              */
	if(thispage.indexOf('home') != -1)
	{
		 $(".showhide").click(function(){
			$(this).prev().css('height', "auto");	
			$(this).text('');
		});
 		 $("#aboutus, #whatwedo, #aboutwt").expander({
		  slicePoint: 250, 
		  widow: 2,
		  expandEffect: 'fadeIn', 
		  userCollapseText: '... Show less'
		});


	}
	if($("#leftlogos").length > 0 && $("#rightlogos").length > 0)
	{
		if(document.body.clientWidth > 1200 )
		{
	//		$("#leftlogos").load(siteurl + "/home/aj/leftlogos");	
	//		$("#rightlogos").load(siteurl + "/home/aj/leftlogos");	
			var	ht = document.body.scrollHeight;
			var n = Math.ceil(Math.random() * 2000);
			$("#leftlogos").css('height' , ht);
			$("#rightlogos").css('height' , ht);
			$("#leftlogos").css('background-position' , "0px " + n + "px");
			ht = ht + n + 2000;
			$("#rightlogos").css('background-position' , "0px " + ht + "px");
			
		//	setInterval('movelogos()', 100);
			
		}else{
			$("#leftlogos").css('display' , "none");
			$("#rightlogos").css('display' , "none");
		}
	}
	/*          WEBORDERS                */
	
	if(document.title.indexOf("WebOrders") != -1){
		$("#salesperson").change(function(){
			$("#sales_dropdown").submit();
		  });
		
	}
	
	
	
	 /*			M SPORT				*/
	 
        $("#searchtext").focus(function(){
          if($(this).val() == "Search Our Site")
            $(this).val("");        
        });    
        $("#searchtext").blur(function(){
            if($(this).val() == "")
              $(this).val("Search Our Site");           
        });    
    
        var ad = 'images/ad' + Math.ceil(Math.random() * 2) + ".jpg";
        $('#mainimg').attr('src', ad);
      
    $('#dealerbutton').hover(function()
    {
      $(this).attr("src", siteurl + "images/round_button_down.png");
		}, function() {
	     $(this).attr("src",siteurl + "images/round_button.png");

    });
   
   $('#sideSubmit').mousedown(function()
   {
		if ($('#search_input_plain').val() == "Enter Search Term")
			   $('#search_input_plain').val('');
   });
    $('#loginbutton').hover(function()
    {
      $(this).attr("src", siteurl + "/images/round_button_login_down.png");
		}, function() {
	     $(this).attr("src", siteurl +  "/images/round_button_login.png");

    });
        
        $(".menuimg").hover(function(){
         var imgname = $(this).attr("src");   
         imgname = imgname.replace(".png", "");
         $(this).attr("src", imgname + "-over.png" );
         },function(){
         var imgname = $(this).attr("src");   
         imgname = imgname.replace("-over", "");
         $(this).attr("src", imgname);
              
        });
    
     
     //zebra stuff
     $(".linecard tr:even").addClass("evenrow");
     $(".linecard tr:odd").addClass("oddrow");    
     $("table.zebra tbody tr:even").addClass("evenrow");
     $("table.zebra tbody tr:odd").addClass("oddrow");    
     $("#contacttbl tr:even").addClass("evenrow");
     $("#contacttbl tr:odd").addClass("oddrow");        
     $('.sidewindow div ul li:odd').addClass("oddrow");        
     $('.sidewindow div ul li:even').addClass("evenrow");       

	 
     //
     
     //focus
     if(window.location.href.indexOf('login') != -1)
     {
          $('#user_input').focus();
     }    
     
     
     //tabs
	  if(window.location.href.indexOf('msport') != -1)
	  {
		
	  } 


	
/*		Products				*/	
	if($('.thickboxlink').length > 0)
	{
	$('.thickboxlink').click(function(){
		$("html").css("overflow", "hidden");
		$("#externalframe, #clickclose, #externalframe-header, #externalframe-body, #framecloser").show();	
		$("#externalframe").css("top",document.documentElement.scrollTop + "px");		
		$("#framecloser").css("top",document.documentElement.scrollTop + "px");				
		$("#externalframe").attr("src", $(this).attr("href"));	
	});
		
	$("#clickclose").click(function(){
		$("html").css("overflow", "auto");					
		$("#framecloser").hide();
		$("#externalframe").attr("src", "");
		$("#externalframe").hide();
	});

	function test23(){
		alert("test");
		var iframeId = "externalframe";
//		var y =   document.getElementById(iframeId).contentWindow.document;

	}
		
	$("#clickclose").click(function(){
		$("#externalframe").attr("src", "");
		$("#externalframe").hide();
		$(this).hide();
	 });
		/*
		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);										 
		});
	*/
	}
/*		Dealer Portal		*/	



	$('#sideSubmit').click(function(){

		if(($('#search_input_plain').val() == "Enter Search Term" || $('#search_input_plain').val() == "" ) && ($('#prefix').val() == "" )  )// &&  $('.search_box').val() == "" )								
		{
			$('#search_input_plain').val("Enter Search Term");
			$('#search_input_plain').addClass('empty');
			return false;
		}
		else
		{
			return true;
		}
	});
	$('#submit').click(function(){

		if(($('#search_input').val() == "Enter Search Term" || $('#search_input').val() == "" ) && ($('#topdd').val() == "" )  )// &&  $('.search_box').val() == "" )								
		{
			$('#search_input').val("Enter Search Term");
			$('#search_input').addClass('empty');
			return false;
		}
		else
		{
			return true;
		}
	});


	if($('.appguidelink').length > 0)
	{
		var screenHeight = document.body.clientHeight - 75;	
		var screenWidth = document.body.clientWidth - 100;		
		var urlstring = "width=" + screenWidth + "&height=" + screenHeight;
		$('.appguidelink').each(function(){					 
			$(this).attr("href", $(this).attr("href") + urlstring);										 
		});
	
	}

	if($(".resetform").length > 0 )
	{
		$(".resetform").click(function(){
			$('.prefix_box').val("");
			$(".search_box").val("Enter Search Term");
			$(".search_box").addClass("empty");
	   });
	}
	


    $('#poplink1, #poplink2, #poplink3').hover(function()
    {
      $(this).addClass('overselect');
      $(this).removeClass('notoverselect');
		}, function() {
	      $(this).removeClass('overselect');
	     $(this).addClass('notoverselect');

    });



	  $("#myresults tbody tr:odd").addClass("odd");
	  $("#myresults tbody tr:even").addClass("even");
     
     $(".dropdown").change(function(){
			alert(this.value);
       window.location.href = this.value;  
	  // jQuery.post('http://www.marcor.ca/dev/site6/index.php/home/dealer/download_price/AFE2009.pdf');
     });
     
	 $('.pricelink, .formlink, .ifrmopen ').click(function(){
		$('#maincontent').html('<iframe id="pdf-frame" name="ifrm"  height="600"></iframe>'); //load('home/dealer/download_price/'  + $(this).attr('id'));				
		$("#bodyheader").text($(this).attr("id"));
	});
	$('.thickboxlink').click(function(){
		$.post("aj/app-guide-click/" + $(this).attr('id') );				   
	});
	 $('.pricelink-result').click(function(){	
										   
		var tmp = window.location.href;										   
		$('#maincontent').html('<strong><a style="text-align:center;" href="' + tmp + '">back to search results</a></strong>' + '<iframe id="pdf-frame" name="ifrm"  height="600"></iframe>'); //load('home/dealer/download_price/'  + $(this).attr('id'));				
	});
	 
	 
     $("#appguides").change(function(){
          var id = '#'  + ($(this).val());
		var y =  $(id).trigger('click');

     });
	 
	  $("#prcguides").change(function(){
          var id = '#'  + ($(this).val());

	 $(id).trigger('click');

     });
	 

     $('select#appguides').each(function(){
          $(this).find('option:odd').addClass('oddrow');     
          $(this).find('option:even').addClass('evenrow');
          $(this).find('option:first').removeClass('evenrow');
     }); 	

     
     
     $('select.dropdown').each(function(){
          $(this).find('option:odd').addClass('oddrow');     
          $(this).find('option:even').addClass('evenrow');
          $(this).find('option:first').removeClass('evenrow');
     }); 		
	 
	$('.imgfloat').livequery('click', function(event){			   
		upd($(this).parent().text());		   
	 }) 	
		$('#search_input, #search_input_plain').each(function(){
		if( $(this).val() == '' || $(this).val() == 'Enter Search Term')
		{
			
			$(this).addClass('empty');
			$(this).val('Enter Search Term');
		
		}							 								 
	});
	
	$('#search_input, #search_input_plain').focus(function()
	{
		if($(this).val() == 'Enter Search Term')
		{
			$(this).removeClass('empty');
			$(this).addClass('full');
			$(this).val('');
		}
	});
	
	$('#search_input, #search_input_plain').blur(function()
	{
		if($(this).val() == '')
		{
			$(this).addClass('empty');
			$(this).val('Enter Search Term');

		}
	});
	
	$('#submit').mousedown(function(){								 
		if($('#search_input').val().indexOf('Enter Search Term') != -1)
		{
			$('#search_input').val('');
		}
	});
	$('#appguides').focus();	
	    $('.imglink').hover(function()
    {
      $(this).attr("src", siteurl + "/home_trans_down.png");
		}, function() {
	     $(this).attr("src", siteurl + "/dev/site6/home_trans.png");

    });
		
	$('#prevad').click(function(){
		if(cnt != 0)
		{
			cnt = cnt - 1;
			str = siteurl + arr[cnt];	
		}
		else if(cnt == 0)
		{
			cnt = arr.length -1;
			str = siteurl + arr[cnt];	
		}

			rotate();
		});
	$('#nextad').click(function(){
		if(cnt != arr.length -1 )
		{
			cnt++;
			str = siteurl + arr[cnt];	
		}
		else if(cnt == arr.length-1)
		{
			cnt = 0;
			str = siteurl + arr[cnt];	
		}
			rotate();
		});	
		$("#prevad, #nextad").hover(function(){
			$(this).addClass('hCursor');						 
		}, function(){
			$(this).removeClass('hCursor');	 
		});
		

	  if(this.title.indexOf('Marcor Automotive Dealer Portal') != -1)
	  {
		imgCounter = 1;
		inOut(6);
		$myinterval = window.setInterval('rotate()' ,15000);

	}
		
$(".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());						  
		  	});


 $('#poplink1').click(function()
    {
      $('#appguidewindow').fadeIn(250);
	});
 
	$('#popmenu').blur(function(){
		  $('.popoutlist').hide();							 							 
	 })
	


	 $('#poplink2').click(function()
    {
		alert("Price guides are no longer available.  Please use the search feature on the left.  Searching for parts shows all the information in the priceguide plus the stock count");
//      $('#prcguidewindow').fadeIn(250);
	});
 
	
	$('#poplink3').click(function()
    {
      $('#frmguidewindow').fadeIn(250);
	});
	
	$(document).click(function(e){
		var idstr = '#' + e.target.id;
		if(e.target.id.indexOf("appguidewindow") == -1 && e.target.id.indexOf("poplink") == -1)
		{
	      $('#appguidewindow').fadeOut(100);	
  	   	  $('#prcguidewindow').fadeOut(100);	
  	   	  $('#frmguidewindow').fadeOut(100);	
		}

	});

});    // end document ready

function movelogos()
{

	var x = $("#leftlogos").css('backgroundPosition').split(' ');
	var y = x[1].replace('px', '');
	
	y = parseInt(y) + 2;
	y = y + "px";
	$("#leftlogos").css('backgroundPosition', "0px " + y );	
	
	
	var x = $("#rightlogos").css('backgroundPosition').split(' ');
	var y = x[1].replace('px', '');
	
	y = parseInt(y) - 2;
	y = y + "px";
	$("#rightlogos").css('backgroundPosition', "0px " + y );	

}




function upd(item_number)
{		
			$('#livelist').load(x + '/' + item_number);	
}
function clearList()
{
			$('#livelist').load(x + '/clear');
}
function moveDown()
{
	$("#framecloser").css("top", 	document.body.scrollTop + 10)	;
}

function restripe(){
			setTimeout(function(){
				$("#carttable").addClass('zebra');
				$("table.zebra tr:even").addClass("evenrow");
				$("table.zebra tr:odd").addClass("oddrow"); 
			}, 500);
			setTimeout(function(){
				$("#carttable").addClass('zebra');
				$("table.zebra tr:even").addClass("evenrow");
				$("table.zebra tr:odd").addClass("oddrow"); 
			}, 150);	
}

function handle_AddToCart(){
	$("#cart-added-list :last-child").fadeOut(500);
	$("#cart-added-list :last-child").slideUp(500);
	setTimeout(function(){$("#cart-added-list :last-child").remove();}, 500);
	setTimeout(function(){
		if($("#cart-added-list").children().length == 0)
		{
			$("#added-to-cart").fadeOut(1000);
			updateZebra();
		}											
	}, 520);

		
}

function updateZebra(){
		 $("table.zebra tr:even").addClass("evenrow");
		 $("table.zebra tr:odd").addClass("oddrow"); 
}

function swapImage()
{

		$('.rotatead').fadeTo(500, .01);
		setTimeout("inOut(imgCounter)", 500);
		imgCounter++;
		if(imgCounter > 6){
			imgCounter = 1;	
		}
}

function inOut(n)
{
	$('.rotatead').attr('src', siteurl + 'images/rotate/' + n + '.jpg');
	$('.rotatead').fadeTo(300, 1);
	
}
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()' ,8000);	

}
function fin()
{
	$('#rotateimage').fadeTo(500, 1);
}
function change_src()
{
	$('#rotateimage').attr("src", str);
	fin();
}