jQuery(document).ready(function($){

			var current_active;

		  $('#mainNav li a').each(function(){

			  	if($('#breadcrumbs').is('div'))

				{

					var bread_html = $('#breadcrumbs').html();

					var current = $(this).html();
					

					bread_html = bread_html.toLowerCase();

					current = current.toLowerCase();

					bread_html =bread_html.split(' ').join('');

					bread_html =bread_html.split("\n").join('');

					bread_html =bread_html.split("\n\r").join('');

					current =  current.split(' ').join('');

					var firstclosure = bread_html.indexOf('>',0);

					var limit = firstclosure + 7;

					//console.log(limit);
					//console.log(bread_html.indexOf('aboutus',limit));
					//console.log(bread_html.indexOf('aboutus'));
					
					
					if(bread_html.indexOf('aboutus',limit)>0){
						current_active = 'aboutus';
						//console.log('was here');
						
					}
					
					
					if(bread_html.indexOf(current,limit)>0)

					{

						current_active = current;

					}
					
					//console.log(bread_html.indexOf('aboutus'));
					//console.log(current);
					//console.log(firstclosure);
					//console.log(limit);

				}

				else

				{

					current_active = 'home';

				}

			  });
				
			  if(!current_active)
			  {		
					current_active = 'home';

			  }	
			if(current_active=='home')
			{
				var location = window.location.href;
				if(location.indexOf('about',0)>0)
				{
					current_active = 'aboutus';
				}
				if(location.indexOf('.html',0)>0)
				{
					current_active = 'orderonline';
				}
			}
			  $('#mainNav li a').each(function(){

				  	var current = $(this).html();

					current = current.toLowerCase();

					current =  current.split(' ').join('');

					if(current == current_active)

					{

						$(this).addClass('active');

					}

			  });

			if($('#leftNav1').is('ul'))

			{

				$('#leftNav1 li a').each(function(){

					var bread_html = $('#breadcrumbs').html();

					var current = $(this).html();

					bread_html = bread_html.toLowerCase();

					current = current.toLowerCase();

					bread_html =bread_html.split(' ').join('');

					bread_html =bread_html.split("\n").join('');

					bread_html =bread_html.split("\n\r").join('');

					current =  current.split(' ').join('');

					var firstclosure = bread_html.indexOf('>',0);

					var limit = firstclosure + 7;

					if(bread_html.indexOf(current,limit)>0)

					{

						$(this).addClass('active');

						$(this).parent().siblings('li').children('a').removeClass('active');

					}

				});

			}

			

		  $('#canadaprovinces').cycle({

				fx: 'fade'
			});

		$('#tab_2').click(function(){

				if(!$(this).hasClass('active'))

				{

					var arr = $('#tab_2 span img').attr('src');

					$('.tabs li img').attr('src',arr);

					arr=arr.substr(0,(arr.length-5));

					arr = arr + '1.png';

					var arr= $('#tab_2 span img').attr('src',arr);

				}

				$('.tabs li').removeClass('active');

				$(this).addClass('active');

				$('#compressionSprings').hide();

				$('#extensionSprings').show();

			})

		$('#tab_1').click(function(){

				if(!$(this).hasClass('active'))

				{

					var arr = $('#tab_1 span img').attr('src');

					$('.tabs li img').attr('src',arr);

					arr=arr.substr(0,(arr.length-5));

					arr = arr + '1.png';

					var arr= $('#tab_1 span img').attr('src',arr);

				}

				$('.tabs li').removeClass('active');

				$(this).addClass('active');

				$('#extensionSprings').hide();

				$('#compressionSprings').show();

			})

		$('#tb_1').click(function(){

				if(!$(this).hasClass('active'))

				{

					var arr = $('#tb_1 span img').attr('src');

					$('.tabs li img').attr('src',arr);

					arr=arr.substr(0,(arr.length-5));

					arr = arr + '1.png';

					var arr= $('#tb_1 span img').attr('src',arr);

				}
				$('.tabs li').removeClass('active');

				$(this).addClass('active');

				$('#blueModule form').hide();

				$('#compressionSprings').show();

			});

		$('#tb_2').click(function(){
			if(!$(this).hasClass('active'))

				{

					var arr = $('#tb_2 span img').attr('src');

					$('.tabs li img').attr('src',arr);

					arr=arr.substr(0,(arr.length-5));

					arr = arr + '1.png';

					var arr= $('#tb_2 span img').attr('src',arr);

				}

			$('.tabs li').removeClass('active');

			$(this).addClass('active');

			$('#blueModule form').hide();

			$('#extensionSpringsSearch').show();

		});

		$('#tb_3').click(function(){
			if(!$(this).hasClass('active'))

				{

					var arr = $('#tb_3 span img').attr('src');

					$('.tabs li img').attr('src',arr);

					arr=arr.substr(0,(arr.length-5));

					arr = arr + '1.png';

					var arr= $('#tb_3 span img').attr('src',arr);

				}

			$('.tabs li').removeClass('active');

			$(this).addClass('active');

			$('#blueModule form').hide();

			$('#searchByPartNo').show();

		});

		$('#draw1').click(function(){

			$('#drawing').show();

			$('#selectrfq option:first').attr('selected','selected');

			$('#selectrfq').val('compression');

			$('#showselect').hide();

			$('#compressionshow').hide();	

			$('#torsionshow').hide();

			$('#extensionshow').hide();	

		});

		$('#draw2').click(function(){

			$('#drawing').hide();

			$('#showselect').show();

			$('#compressionshow').show();	

			$('#torsionshow').hide();

			$('#extensionshow').hide();	

		});

		$('#selectrfq').change(function(){

				$('#compressionshow').hide();	

				$('#torsionshow').hide();

				$('#extensionshow').hide();	

				var val = $(this).val();

				$('#'+val+'show').show();

			});

		$('.update-cart').click(function(){

				$('#updateC').submit();

				return false;

			});

		$('#opc-review .inactiveSlide').addClass('last');

		$('.step-title').click(function() {

			  change_title();

		});
		$('.add_to_compare').live('change',function(){

				$('.add_to_compare').attr('disabled','true');
				if($(this).is(':checked'))

				{

					var html = $.ajax({

						  url: $(this).val(),

						  async: true,
						  
						  success: function(){
							  		$('.add_to_compare').removeAttr('disabled');
							  }

						 }).responseText;

					$('.messages').remove();

					$('.category-products').prepend('<ul class="messages"><li class="success-msg">Product added to compare</li></ul>');		

					$('.messages').fadeOut(2000).delay(2000);	

				}

				else

				{

					var url_ = $(this).val();

					url_ = url_.replace('add','remove');

					var html = $.ajax({

						  url: url_,

						  async: true,
						  
						  success: function(){
							  		$('.add_to_compare').removeAttr('disabled');
							  }

						 }).responseText;

					$('.messages').remove();

					$('.category-products').prepend('<ul class="messages"><li class="success-msg">Product removed from compare</li></ul>');		

					$('.messages').fadeOut(2000).delay(2000);	

				}

			});

			$('.btn_grey2').click(function(){

				var k=0;

				var info;
				if($('.add_to_compare').is('input:checkbox')){

					$('.prodTable .add_to_compare').each(function(){

							if($(this).is(':checked'))

							{

								k=k+1;

								info = $(this).siblings('a').html();						

							}

						});

						if(k==0)

						{

							alert('Please select a product to request information using the checkbox');

						}

						if(k>1)

						{

							alert('Please select only one product to request information about');

						}

						if(k==1)

						{

							window.open($('#hpc_url').val()+"contact-us/?id="+info,'_self');

						}

						return false;
				}

				});

			if($('#go_compression').val()==1)

			{

			  $('.useRefreshLightBox').remove();
			 $('.category-products').remove();
			 $('.tableBtns').remove();
			  $('#blueModule .submit').attr('disabled','true');
			  $('.output').html('<img id="loader" style="margin-left:264px;" src="'+$('#url').val()+'/media/ajax-loader.gif"/>');		  

				window.scrollTo(0, 400);

				 $.ajax({

				type: "POST",

				url: $('#url').val() + "process_search.php",

				data: 'will_go_in='+$('#will_go_in').val()+'&alloy='+$('#alloy').val()+'&wire_diameter='+$('#wire_diameter').val()+'&rate='+$('#rate').val()+'&free_lenght='+$('#free_lenght').val()+'&cat=compression',

				success: function(data) {

				  $('.useRefreshLightBox').remove();
				  $('.output').html(data);
				  $('#prodTable_o').tablesorter();
				  $('#blueModule .submit').removeAttr('disabled');
				}

				});

			}

			if($('#go_extension').val()==1)

			{

			  $('.tabs li').removeClass('active');

				$('#tb_2').addClass('active');

				$('#blueModule form').hide();

				$('#extensionSpringsSearch').show();

			  $('.useRefreshLightBox').remove();
			$('.category-products').remove();
			$('.tableBtns').remove();
		     $('.submit').attr('disabled','true');
			  $('.output').html('<img id="loader" style="margin-left:264px;" src="'+$('#url').val()+'/media/ajax-loader.gif"/>');

			  window.scrollTo(0, 400);

			  $.ajax({

				type: "POST",

				url: $('#url').val() + "process_search.php",

				data: 'alloy='+$('#alloy_ex').val()+'&outside_diameter='+$('#outside_diameter_ex').val()+'&coil_lenght='+$('#coil_lenght').val()+'&rate='+$('#rate_ex').val()+'&cat=extension',

				success: function(data) {

				  $('.output').html(data);
				  $('#prodTable_o').tablesorter();
				$('#blueModule .submit').removeAttr('disabled');
				}

			  });

			}

			if($('#search_by_part').val()==1)

			{
				
				if(!$(this).hasClass('active'))

				{

					var arr = $('#tb_3 span img').attr('src');

					$('.tabs li img').attr('src',arr);

					arr=arr.substr(0,(arr.length-5));

					arr = arr + '1.png';

					var arr= $('#tb_3 span img').attr('src',arr);
					
					$('#searchpart').siblings('li').children('a').removeClass('active');
					$('#searchpart').children('a').addClass('active');

				}
				$('.tabs li').removeClass('active');

				$('#tb_3').addClass('active');

				$('#blueModule form').hide();

				$('#searchByPartNo').show();

			}

			if($('#url').is('input'))

			{
		
		$('#compressionSprings').submit(function(){

			  $('.useRefreshLightBox').remove();
			 $('.category-products').remove();
			 $('.tableBtns').remove();
	         $('#blueModule .submit').attr('disabled','true');
			  $('.output').html('<img id="loader" style="margin-left:264px;" src="'+$('#url').val()+'/media/ajax-loader.gif"/>');

			  window.scrollTo(0, 400);

			  $.ajax({

				type: "POST",

				url: $('#url').val() + "process_search.php",

				data: 'will_go_in='+$('#will_go_in').val()+'&alloy='+$('#alloy').val()+'&wire_diameter='+$('#wire_diameter').val()+'&rate='+$('#rate').val()+'&free_lenght='+$('#free_lenght').val()+'&cat=compression',

				success: function(data) {

				  $('.useRefreshLightBox').remove();
				  $('.output').html(data);
				  $('#prodTable_o').tablesorter();
				$('#blueModule .submit').removeAttr('disabled');
				}

			  });

			  return false;

		})

			}
		$('#extensionSpringsSearch').submit(function(){

			  $('.useRefreshLightBox').remove();
			  $('.category-products').remove();
			 $('.tableBtns').remove();
			    $('#blueModule .submit').attr('disabled','true');
			  $('.output').html('<img id="loader" style="margin-left:264px;" src="'+$('#url').val()+'/media/ajax-loader.gif"/>');

			  window.scrollTo(0, 400);

			  $.ajax({

				type: "POST",

				url: $('#url').val() + "process_search.php",

				data: 'alloy='+$('#alloy_ex').val()+'&outside_diameter='+$('#outside_diameter_ex').val()+'&coil_lenght='+$('#coil_lenght').val()+'&rate='+$('#rate_ex').val()+'&cat=extension',

				success: function(data) {

				  $('.output').html(data);
					$('#prodTable_o').tablesorter();
					$('#blueModule .submit').removeAttr('disabled');
				}

			  });

			  return false;

		})
		$('#prodOrder .greyHolder input[name="qty"]').change(function(){
			
			
				var qty =parseInt($(this).val());
				var disc=new Array(); 
				var i;
				var newPri;
				var pricePerInch = $('#price_per_inch').val();
				var inchLength;
				
				$('#prodOrder .greyHolder label').each(function(){
					if($(this).html() == 'Coil Length(Inches):'){
						inchLength = $(this).next().val();
					}
				})
				
				
				for(i=1;i<=27;i++)
				{
					if($('#disc_'+i).is('input'))
					{
						disc[i]=parseInt($('#disc_'+i).val());
					}
				}
				if(qty>=disc[2])
				{
					
				for(i=2;i<disc.length;i++)
				{
					if((qty>=disc[i])&&(qty<disc[(i+1)]))
					{
						var price_utilizer = i;
					}
				}
					if(isNaN(price_utilizer))
					{
						price_utilizer=disc.length-1;
					}
					var pr = parseFloat($('#price_qty' + price_utilizer).val());
					var pri=new Number(pr*qty);
					
					if(!isNaN(pri))
					{	
										
						if(!isNaN(inchLength))
						{
							newPri = parseFloat(pri + ( pricePerInch * inchLength * qty ) ) ;
						}
						else
						{
							newPri = parseFloat(pri) ;
						}
						$('.price1').html('Price:&nbsp;$'+ newPri.toFixed(2));
						$('.unit_price').html('Unit Price:&nbsp;$'+ (newPri/qty).toFixed(2));
					}
					else
					{
						$('.price1').html('Price: $0.00');
						$('.unit_price').html('Unit Price: $0.00');
					}
				}
				else
				{
					
					var pr = parseFloat($('#price_qty1').val());
					var pri;
					pri = pr*qty;
					if(!isNaN(pri))
					{
						
						if(!isNaN(inchLength))
						{
							
							newPri = parseFloat(pri + ( pricePerInch * inchLength * qty ) ) ;
						}
						else
						{
							newPri = parseFloat(pri) ;
						}
						$('.price1').html('Price:&nbsp;$'+ newPri.toFixed(2));
						$('.unit_price').html('Unit Price:&nbsp;$'+ (newPri/qty).toFixed(2));
					}
					else
					{
						$('.price1').html('Price: $0.00');
						$('.unit_price').html('Unit Price: $0.00');
					}
				}
			});
			$('#searchByPartNo').submit(function(){
				$('.useRefreshLightBox').remove();
			 $('.category-products').remove();
			 $('.tableBtns').remove();
			 			    $('#blueModule .submit').attr('disabled','true');
				$('.output').html('<img id="loader" style="margin-left:264px;" src="'+$('#url').val()+'/media/ajax-loader.gif"/>');
				$('.output').load($('#hpc_url').val()+'catalogsearch/result/index/?limit=100&q='+$('#q').val()+' #results_container',function(){
						$('tr.greyBg').remove();
						var nr_tr = $('tr').length;
						if($('#prodTable_o').is('table'))
						{
							if(nr_tr<100)
							{
								$('.output').prepend('<div class="category-products"><a class="btn_grey3" style="margin-left:20px;margin-bottom:15px;" href="'+$('#hpc_url').val()+'product-compare/">Compare</a><div class="checkoutMethod"><div class="head"><div class="col1"><span>Springs</span></div><div class="clear"></div></div></div>');				
							}
							else
							{
								$('.output').prepend('<div class="category-products"><a class="btn_grey3" style="margin-left:20px;margin-bottom:15px;" href="'+$('#hpc_url').val()+'product-compare/">Compare</a><div class="checkoutMethod"><div class="head"><div class="col1"><span>Springs<br/>First 100 results displayed!<br/> Please narrow your search.</span></div><div class="clear"></div></div></div>');				
							}
						}
						else
						{
							$('.output').prepend('<p class="note-msg">There are no products matching the selection.</p>');
						}
						$('.output').append('</div>')
						var nr_tr = $('tr').length;
						$('#prodTable_o a').attr('href',"javascript:void(0)");
						$('#prodTable_o').tablesorter();
						$('#blueModule .submit').removeAttr('disabled');
					});
					

				return false;
				});
			$('#open_discount').click(function(){
				var height = document.body.clientHeight;
				$('body').prepend('<div class="overlay" style="height:'+height+'px;"></div><div class="discount_show">&nbsp;</div>');
				$('.discount_show').html('<div class="close"><a href="#" id="close_discount">Close</a></div>'+$('.discount_hide').html());
				//$('.discount_show').css({'top': window.scrollY+50});
				//$('.discount_show').prepend('<div class="close"><a href="#" id="close_discount">Close</a></div>')
			});
			$('#close_discount').live('click',function(){
					$('.discount_show').remove();
					$('.overlay').remove();
					return false;
				});
			$('.visual #compressionSprings').submit(function(){
				if(($('#will_go_in').val()=='_')&&($('#wire_diameter').val()=='_')&&($('#rate').val()=='_')&&($('#free_lenght').val()=='_')&&($('#alloy').val()=='_'))
				{
					window.location.href="compression-springs.html";return false;
				}
				
			});
			$('.visual #extensionSprings').submit(function(){
				if(($('#outside_diameter_ex').val()=='_')&&($('#coil_lenght').val()=='')&&($('#rate_ex').val()=='_')&&($('#alloy_ex').val()=='_'))
				{
					window.location.href="extension-springs.html";return false;
				}
				
			});
			$('.greyHolder input:last').change(function(){
					if($(this).attr('name')!='qty')
					{
						var val_l = $(this).val();
						val_l = parseInt(val_l);
						if(val_l>0)
						{
							$('#length_ex .col2').html(val_l);
							$('#length_ex').show();
							var new_rate;
							new_rate = parseFloat($('#rate_ex_bs').val()/val_l);
							$('#rate_ex').html(new_rate.toFixed(4));
							var new_max_defl;
							new_max_defl = parseFloat($('#max_deflex_bs').val()*val_l);
							$('#max_deflex').html(new_max_defl.toFixed(4));
						}
						else
						{
							$('#rate_ex').html($('#rate_ex_bs').val());
							$('#max_deflex').html($('#max_deflex_bs').val());
						}
						var pinch =$('#price_per_inch').val();
						$('.discount_price .price').each(function(){
							if(val_l>0)
							{
								var val = $(this).siblings('.discount_base').val();
								val = parseFloat(val);
								val = val + pinch * val_l;
								$(this).html('$'+val.toFixed(2));
							}
							else
							{
								var val = $(this).siblings('.discount_base').val();
								val = parseFloat(val);
								$(this).html('$'+val.toFixed(2))
							}
						});
						$('.prices_updater').each(function(){
							if(val_l>0)
							{
								var updt_id = $(this).attr('id');
								var val = $('#'+updt_id+'_bs').val();
								val = parseFloat(val);
								val = val + pinch * val_l;								
								$(this).val(val.toFixed(2));
								if(parseInt($('#prodOrder .greyHolder input[name="qty"]').val())>0)
								{
									$('#prodOrder .greyHolder input[name="qty"]').change();
								}
							}	
							else
							{
								var updt_id = $(this).attr('id');
								var val = $('#'+updt_id+'_bs').val();
								val = parseFloat(val);
								$(this).val(val.toFixed(2));
								if(parseInt($('#prodOrder .greyHolder input[name="qty"]').val())>0)
								{
									$('#prodOrder .greyHolder input[name="qty"]').change();
								}
							}
						});
							
					}
			});
	});
	

	function change_title(){

			jQuery('.h1wIco h1').html(jQuery('.active .stepName').html());
			
			var pageTracker = _gat._getTracker("UA-9022973-1"); 
				_gaq.push(['_setAccount', 'UA-9022973-1']);
				
			
			if(jQuery('.active .stepName').html() == 'Billing Information')
			{
				_gaq.push(['_trackPageview','/checkout/billing']);
			}
			if(jQuery('.active .stepName').html() == 'Shipping Information')
			{
				_gaq.push(['_trackPageview','/checkout/shipping']);
			}
			if(jQuery('.active .stepName').html() == 'Shipping Method')
			{
				_gaq.push(['_trackPageview','/checkout/shipping/method']);
			}
			if(jQuery('.active .stepName').html() == 'Payment Information')
			{
				_gaq.push(['_trackPageview','/checkout/payment/']);
			}
			if(jQuery('.active .stepName').html() == 'Order Review')
			{
			 	_gaq.push(['_trackPageview','/checkout/review/']);
			}
		}

function getSearchData(id){

  $('ajax_setter').setValue(id);



  if(id == 'rate'){

    $('rate').replace('<select name="rate" id="rate" onchange="getSearchData(\'free_lenght\')"><option value="_">SELECT OPTION</option></select>');

    $('free_lenght').replace('<select name="free_lenght" id="free_lenght" onchange="getSearchData(\'wire_diameter\')"><option value="_">SELECT OPTION</option></select>');

    $('wire_diameter').replace('<select name="wire_dimeter" id="wire_diameter" onchange="getSearchData(\'alloy\')"><option value="_">SELECT OPTION</option></select>');

    $('alloy').replace('<select name="alloy" id="alloy"><option value="_">SELECT OPTION</option></select>');

  }

  else if(id == 'free_lenght'){

    $('free_lenght').replace('<select name="free_lenght" id="free_lenght" onchange="getSearchData(\'wire_diameter\')"><option value="_">SELECT OPTION</option></select>');

    $('wire_diameter').replace('<select name="wire_dimeter" id="wire_diameter" onchange="getSearchData(\'alloy\')"><option value="_">SELECT OPTION</option></select>');

    $('alloy').replace('<select name="alloy" id="alloy"><option value="_">SELECT OPTION</option></select>');

  }

  else if(id == 'wire_diameter'){

    $('wire_diameter').replace('<select name="wire_dimeter" id="wire_diameter" onchange="getSearchData(\'alloy\')"><option value="_">SELECT OPTION</option></select>');

    $('alloy').replace('<select name="alloy" id="alloy"><option value="_">SELECT OPTION</option></select>');

  }

  else if(id == 'alloy'){

    $('alloy').replace('<select name="alloy" id="alloy"><option value="_">SELECT OPTION</option></select>');

  }

  

  var value = $('will_go_in').getValue() + ',' + $('rate').getValue() + ',' + $('free_lenght').getValue() + ',' + $('wire_diameter').getValue() + ',' +$('alloy').getValue(); 

  new Ajax.Request('/custom/getSearchData.php?id=' + id + '&value=' + value, {

	method: 'get',

	onSuccess: function(transport) {

	  $($('ajax_setter').getValue()).replace(transport.responseText);

	}

  });

}
