// kalkhoff_utilities.js

// See bottom of this file for BroswerDetect and gearSKUs

/**
**		PAGE TITLE
**/
document.title.replace(/greenlight bikes llc/i,"Kalkhoff")

/**
***		GEAR SKUS
**/
var gearSKUs = new Array("banb01","banb02","banb03","banb04","banb05", "baor00","baor01","baor03","baor04","baor05","baor06","baor07","baor08","baor09","henutc01","henutc02","henutc03", "loab01", "loab02", "loab03", "loab04", "loab05","loab06","gft","bart00")



// Since prototype is loaded earlier
jQuery.noConflict();

jQuery(function($){

	/**
	**	Default.asp redirect
	**/
	filename = location.href.substring(location.href.lastIndexOf('/')+1)
	if (filename.indexOf("efault.asp") > -1 && filename.indexOf("GiftCert") == -1)  {
		location.href = "/"	
	}
	


      /**
      **	affiliate page color/text change
      **/
      
      
      function fixit() {
      	document.getElementsByTagName("body")[0].innerHTML = fixcode(document.getElementsByTagName("body")[0].innerHTML);
      }
      
      function fixcode(input) {
        input = input.replace("009900", "231F20");
        return input;
      }

      function fixcode4(input) {
        input = input.replace("Generate Banner Ads", "");
        return input;
      }
      function fixit4() {
      	document.getElementsByTagName("body")[0].innerHTML = fixcode4(document.getElementsByTagName("body")[0].innerHTML);
      }

      function fixcode5(input) {
        input = input.replace("Helpful Reminders", "");
        return input;
      }
      function fixit5() {
      	document.getElementsByTagName("body")[0].innerHTML = fixcode5(document.getElementsByTagName("body")[0].innerHTML);
      }

      function fixcode6(input) {
        input = input.replace("Advertising Tools", "");
        return input;
      }
      function fixit6() {
      	document.getElementsByTagName("body")[0].innerHTML = fixcode6(document.getElementsByTagName("body")[0].innerHTML);
      }

     function fixcode7(input) {
        input = input.replace("Place your link anywhere: In e-mails, banner", "");
        return input;
      }
      function fixit7() {
      	document.getElementsByTagName("body")[0].innerHTML = fixcode7(document.getElementsByTagName("body")[0].innerHTML);
      }

     function fixcode8(input) {
        input = input.replace("ads, on your website, etc.", "");
        return input;
      }
      function fixit8() {
      	document.getElementsByTagName("body")[0].innerHTML = fixcode8(document.getElementsByTagName("body")[0].innerHTML);
      }

     function fixcode9(input) {
        input = input.replace("Anyone who visits \"Your Link\" will be tracked,", "");
        return input;
      }
      function fixit9() {
      	document.getElementsByTagName("body")[0].innerHTML = fixcode9(document.getElementsByTagName("body")[0].innerHTML);
      }

     function fixcode10(input) {
        input = input.replace("and you will get credit.", "");
        return input;
      }
      function fixit10() {
      	document.getElementsByTagName("body")[0].innerHTML = fixcode10(document.getElementsByTagName("body")[0].innerHTML);
      }

     function fixcode11(input) {
        input = input.replace("Your Link", "Your Unique Link");
        return input;
      }
      function fixit11() {
      	document.getElementsByTagName("body")[0].innerHTML = fixcode11(document.getElementsByTagName("body")[0].innerHTML);
      }
			
			
      filename = location.href.substring(location.href.lastIndexOf('/')+1);
      if (filename.indexOf("myaccount_affiliate.asp") > -1)  {
        fixit(); 
	fixit();
        fixit4();
        fixit5();
        fixit6();
        fixit7(); 
        fixit8(); 
        fixit9(); 
        fixit10(); 
        fixit11(); 
              
      }	


      /**
      **	new signup exit!
      **/
      function fixcode2(input) {
        input = input.replace("<!-- V-Chrome -->", "<!-- V-Chrome --><input type='submit' value='Exit This Form' />");
        return input;
      }

      function fixcode3(input) {
        input = input.replace('<b><font size="2">Enter a new shipping address...</font></b>', '<b><font size="2">Enter a new shipping address...</font></b><br /><a href="http://store.kalkhoffusa.com/myaccount.asp">Click here to go directly to your account page.</a>');
        return input;
      }

      function fixcodeIE(input) {
        input = input.replace('Enter a new shipping address...', 'Enter a new shipping address...<br /><a href="http://store.kalkhoffusa.com/myaccount.asp">Click here to go directly to your account page.</a>');
        return input;
      }

      function isIE(){
          return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
      }

      function addbutton() {
      if(isIE()){
            document.getElementsByTagName("body")[0].innerHTML = fixcodeIE(document.getElementsByTagName("body")[0].innerHTML);
      } else {
            document.getElementsByTagName("body")[0].innerHTML = fixcode3(document.getElementsByTagName("body")[0].innerHTML);
      }
      	
      }
      if (filename.indexOf("AccountSettings.asp?NewSignup") > -1)  {
        addbutton();
      }	


	
	/**
	**		NAV MENU - OPERA
	**/
	//			"nav" needs to be 1 pixel wider in Opera
	/* 			the code below is in custom.js, since the elements are built too early
	 			for jQuery to see them
	
	if(BrowserDetect.browser == "Opera") {
		document.getElementById("searchbox").getElementsByTagName("img")[0].style.marginLeft = "-1px"
	}
	*/ 
	
	
	/**
	**		LIVE CHAT
	**			swap out the ugly button volusion plants into the code
	**/
	liveChatFirstLoad = true
	$("#VolusionLiveChat img").bind("load", function() {
		if (liveChatFirstLoad) {
			$("#VolusionLiveChat").hide()
			$("#VolusionLiveChat img").attr("src","/v/vspfiles/assets/images/btn_live_chat.gif")
			
			// remove second link, since it's the "free chat by volusion" nonsense
			$("#VolusionLiveChat a:eq(1)").hide()
			liveChatFirstLoad = false
		}
		else {
			$("#VolusionLiveChat").show()
			$("#VolusionLiveChat img").show()
		}
	})


	/**
	**		HOME PAGE
	**/
	if ( $("#home_flash").length > 0 ) {
		$("#home_flash").flash( {   
			swf: '/v/vspfiles/flash/closeups.swf',   
			width: 860,
			height: 387
		});
		$(".ctas img:not(:last)").css("margin-right","8px")
		$(".ctas img")
		.mouseover( function() {
			$(this).removeClass("border").addClass("on")
		})
		.mouseout( function() {
			$(this).removeClass("on").addClass("border")
		})
	}
	
	/**
	**		HISTORY VIDEO
	**/
	if ( $("#history_flash").length > 0 ) {
		$("#history_flash").flash( {   
			swf: '/v/vspfiles/assets/video/kalkhoff_history.swf',   
			width: 320,
			height: 300
		});
	}




	/**
	**		GALLERY
	**/
	currentGalleryItemId = $("#gallery-thumbnails img:first").attr("alt")
	firstLoad = true
	
	// change border colors as user mouses over the gallery thumbnails
	$("#gallery-thumbnails img")
	.mouseover( function() {
		$(this).addClass("on").css("cursor", "pointer")
	})
	.mouseout( function() {
		$(this).removeClass("on")
	})
	// display larger image and/or text in gallery 
	.click(function() {
		galleryItemId = $(this).attr("alt")
		galleryItemHTML = $("#gallery-" + galleryItemId).html()
		galleryTextHTML = $("#gallery-" + galleryItemId + "-caption").html()

		// Don't do the image swap if user clicked on same thumbnail
		if ( currentGalleryItemId != galleryItemId || firstLoad) {
		
			if (firstLoad) {
				$(this).html(galleryItemHTML + galleryTextHTML).fadeIn()
				$(this).find(".gallery-caption").animate({opacity: 1.0}, 4000).fadeIn("slow")
				currentGalleryItemId = galleryItemId
				firstLoad = false
			
			} else {
				$("#gallery").fadeOut("normal", function() {
						$(this).html(galleryItemHTML + galleryTextHTML).fadeIn()
						$(this).find(".gallery-caption").animate({opacity: 1.0}, 4000).fadeIn("slow")
						currentGalleryItemId = galleryItemId
						firstLoad = false
				})
			}
		}
	})
	
	// Load the first large image, based on the ALT in the first thumbnail
	$("#gallery-thumbnails img:first").trigger("click")
	

 
/* autoselect code for bikes*/	
        
    if (!isGear) {
		// see if the color drop down has only 2 elements.  if so, call the change_option function. 
		if ( $("select[name$='_16'] option").length == 2) {
			change_option( $("select[name$='_16']").attr('name'), $("select[name$='_16'] option:last").val());
		}
		if ( $("select[name$='_14'] option").length == 2) {
			change_option( $("select[name$='_14']").attr('name'), $("select[name$='_14'] option:last").val());
		}
		if ( $("select[name$='_15'] option").length == 2) {
			change_option( $("select[name$='_15']").attr('name'), $("select[name$='_15'] option:last").val());
		}
		
		$("select[name$='_14']").change(function() {
  			if ( $("select[name$='_15'] option").length == 2) {
			change_option( $("select[name$='_15']").attr('name'), $("select[name$='_15'] option:last").val());
			}
		});
		$("select[name$='_16']").change(function() {
  			if ( $("select[name$='_14'] option").length == 2) {
			change_option( $("select[name$='_14']").attr('name'), $("select[name$='_14'] option:last").val());
			}
		});
	   // see if it has a sale price; then style it // sharrah // 10.19.2010
	 	if ( $('.colors_productprice').length > 0) {
			if ( $('.colors_productprice').html().substr(0,4) == "Sale") {
				$('.colors_productprice').html('<span id="saleprice">'+$('.colors_productprice').html().substr(12)+'</span>'); // remove the "sale price:" text.
				//$('.colors_text').contents().filter(function() { return this.nodeType == 3; }).wrap('<span class="strike"></span>'); // strike through the original price
				$('.colors_text').contents().filter(function() { return this.nodeType == 3; }).wrap('<span class="strike"><span class="striketext"></span></span>'); // strike through the original price
			}
		}
	}
	
/* insert print button ******** */
/* GLR modified 9/15/2010 to accommodate overlapping  product codes (ka10proc, ka10procon) 
     also made the product code array easier to look at       ******** */

if (!isGear) {
  
/* printlist = 'ka09proc,ka09pros,ka09tasm,ka10agat,ka10procon,ka10proc,ka10tasm,ka10nostal,ka10pros,ka10prosdd,ka10sahcomp,ka10sahpro';
    canprint = printlist.split(','); */

    var canprint = new Array(
      'ka09proc',
      'ka09pros',
      'ka09tasm',
      'ka10agat',
      'ka10procon',
      'ka10proc',
      'ka10tasm',
      'ka10nostal',
      'ka10pros',
      'ka10prosdd',
      'ka10sahcomp',
      'ka10sahpro',
      'ka11agat',
      'ka10test',
      'ka11procon8nex',
      'ka11procon11',
      'ka11prosdlxtr',
      'ka11sahelpro',
      'ka11tastour',
      'dummy'
    );

  d = document.location + ' ';	
  for (i=0;i<canprint.length;i++) {
	  lowers = canprint[i]+'.htm';
	  uppers = (canprint[i]+'').toUpperCase()+'.htm';
    //if (d.indexOf(canprint[i]) > 0 || d.indexOf(uppers) > 0) {
    if (d.indexOf(lowers) > 0 || d.indexOf(uppers) > 0) {
      //showPrintIcon(canprint[i]);
      pos = $("img[class='fader']").position();
      $("body").append('<a href="http://www.kalkhoffusa.com/product_data/specs/'+canprint[i]+'.pdf" class="printbug" id="printbug" target="_blank">print/download spec sheet <img src="http://www.kalkhoffusa.com/images/printr-friendly.gif" border="0" align="absmiddle" /></a>');
      $("a[class='printbug']").css("position","absolute");
      $("a[class='printbug']").css("left",pos.left+15);
      $("a[class='printbug']").css("top",pos.top+460);
    }
  }
}
	
/* make specs & reviews tabs load content without going to new page 6/9/2010, sharrah@cascadewebdev.net */
/* **************************************************************************************************** */

/* Geordie added this bit  to remove the old href to prevent indexing*/
$("a[href^='/ProductDetails.asp']")
   .each(function()
   { 
      this.href = "javascript:void();"
   });

$(document).ready(function(){
	$("#visiblecontent").html($("#sub_features").html());
	$("b:contains('Overview')").attr("Id","btn_overview");
	$("b:contains('Specs')").attr("Id","btn_specs");
	$("b:contains('Reviews')").attr("Id","btn_reviews");
});
// wrap <a> around "overview"i tab
$("#btn_overview").wrap("<a class='productnamecolorSMALL colors_productname' href='' />");
// give an id to the dynamic title
$("b:contains('Features')").attr("id","visibletitle");



/*
new code sept 30, 2010 to move specs and reviews up 
*/
var moveup = "-40px";

//special cases (always special cases...)
if(filename.indexOf("ka09proc")>-1) {moveup = "-25px";}
if(filename.indexOf("ka09tasm")>-1) {moveup = "-25px";}
if(filename.indexOf("ka10proc")>-1) {moveup = "-25px";}


var tpages = new Array("ka10proc","ka10procon","ka10agat","ka09proc");
var testpage = tpages[1];

// set the actions for clicking on each tab
$("#btn_specs").click(function(){
	$("#visiblecontent").html($("#sub_specs").html());
	$("#visibletitle").html("Specifications");
	makeOrange('specs');
if (!isGear) {
        $("#overview_paragraph").hide();
        moveSpecRev(moveup);
}
	return false;
});
$("#btn_overview").click(function(){
	$("#visiblecontent").html($("#sub_features").html());
	$("#visibletitle").html("Features");
	makeOrange('overview');
if (!isGear) {
        $("#overview_paragraph").show();	
        moveSpecRev("0px");
}
	return false;
});
$("#btn_reviews").click(function(){
	$("#visiblecontent").html($("#sub_reviews").html());
	$("#visibletitle").html("Reviews");
	makeOrange('reviews');
if (!isGear) {
       $("#overview_paragraph").hide();
       moveSpecRev(moveup);
}
	return false;
});

function makeOrange(x) {
	$("#btn_specs").removeClass("prod_overview_orange");
	$("#btn_overview").removeClass("prod_overview_orange");
	$("#btn_reviews").removeClass("prod_overview_orange");
	$("#btn_"+x).addClass("prod_overview_orange");
}
makeOrange('overview');

/*
* function moveSpecRev
* moves content of lower table up/down after overview paragraph is hidden/shown
*/
function moveSpecRev(topnum){  
	cdelements = $('.colors_descriptionbox');
	cdelements.each(function(intIndex) { 
	if(intIndex==1){
		/*alert("movePara : move this table up");*/
		$(cdelements[intIndex]).css("position","relative");
		$(cdelements[intIndex]).css("top",topnum);
	}
	});
}


/*
helmet thumbnails
attempt  to  resize tiny thumbnails on henutco1 page
glr oct 1, 2010
*/
if(filename.indexOf("HENUTC01.htm")>-1 || filename.indexOf("henutc01.htm")>-1) {
	$('img[src$=.jpg]').each(function() {
  	var srce = this.src;
  	if(srce.indexOf("options")>-1){
   	   this.style.height = '30px';
  	}
	});
}





/* **************************************************************************************************** */
/* **************************************************************************************************** */
		

	
	/**
	**		SEARCH RESULTS
	**/
	$("#content_area").hide()
	if ($("input[name=Search]").length > 0 ) {

		// remove narrowing-search options
		$("#MainForm").prev().hide()
		$("#MainForm table:eq(0)").hide()
		$("#content_area table:eq(0)").hide()
		$("#content_area table:eq(1)").hide()
		
		searchHdHTML = $("#content_area table:eq(0) table:eq(0) td:eq(0) font:eq(0)").text()
		
		$("#content_area").prepend('<div class="search-hd">'+searchHdHTML+'</div>')
		
      $("#content_area").append('<div id="searchcontrol"></div>')

		
		// hide "add to cart" buttons
		$("img[src*=addtocart]").parent().hide()

	}
	$("#content_area").show()


	
	
	/**
	**		PRODUCT PAGES
	**/
	
	
	//		See if the product is a bike or a gear item
	//
	//		For the list of gear SKUs, see the array gearSKUs, defined
	//		at the bottom of this file
	var isGear = false
	if ($(".colors_pricebox:eq(0)").length > 0 ) {
	
	//		The product SKU is in the URL, usually in one of these forms:
	//			http://www.kalkhoffusa.com/ProductDetails.asp?ProductCode=HENUTC01
	//			http://www.kalkhoffusa.com/Kalkhoff-ProConnect-p/ka09pros.htm
		
		var here = location.href.toLowerCase()
		for (i=0; i<gearSKUs.length; i++) {
			if (here.indexOf(gearSKUs[i]) > -1) {
				isGear = true
				break
			}
		}
	}
	
	// CROSS-SELLING
	// 		Style and position the cross-selling display
	//
	if ($("table.colors_lines_light").length > 0 && $(".colors_pricebox:eq(0)").length > 0 ) {
		
		// Get product names & links
		crossSellTitles = []
		crossSellLinks = []
		$.each( $("table.colors_lines_light table:first table:first td a"), function() {
			title = ($(this).text()).replace(/^\s*|\s*$/g,'');		// strip out whitespace
			if (title.length > 0) {
				crossSellTitles.push($(this).text())
				crossSellLinks.push($(this).attr("href"))
			}
		})
		
		
		// Get product prices
		crossSellPrices = []
		$.each($("table.colors_lines_light table:first table:first tr:eq(1) td table font.colors_productprice"), function(){
			crossSellPrices.push($(this).text())
		})
		
		// Get code for "Add" checkbox
		crossSellInputs = []
		$.each ($("table.colors_lines_light table:first table:first tr:eq(1) td table input"), function() {
			crossSellInputName = $(this).attr("name")
			crossSellInputValue = $(this).attr("value")
			crossSellInputs.push('<input type="checkbox" name="' + crossSellInputName + '" value="' + crossSellInputValue + '">')
		})
		
		// Get product image sources
		crossSellImgSrcs = []
		$.each( $("table.colors_lines_light table:first table:first img"), function() {
			if ($(this).attr("src").indexOf("/photos/") > -1){
				crossSellImgSrcs.push($(this).attr("src"))
			}
		})
		
		
		crossSellHTML = 		'<div id="cross-sell-container">'
		crossSellHTML += 		'	<div id="cross-sell">'
		crossSellHTML +=		'		<div id="cross-sell-left">You may also like:</div>'
		for (i=0; i<2; i++){
			crossSellHTML +=	'		<div class="cross-sell-item">'
			crossSellHTML +=	'			<a href="'+crossSellLinks[i]+'"><img src="' + crossSellImgSrcs[i] + '" border="0"></a>'
			crossSellHTML +=	'			<div class="cross-sell-item-text">'
			crossSellHTML +=	'				<div class="cross-sell-item-name"><a href="'+crossSellLinks[i]+'">' + crossSellTitles[i] + '</a></div>'
			crossSellHTML +=	'				<div class="cross-sell-item-price">' + crossSellPrices[i] + '</div>'
			crossSellHTML +=	'				' + crossSellInputs[i] + ' Add'
			crossSellHTML +=	'			</div>'
			crossSellHTML +=	'		</div>'
		}
		crossSellHTML +=		'	</div>'
		crossSellHTML +=		'</div>'

		
		// Display new cross-sell items
		$("table.colors_lines_light").after(crossSellHTML)
		
		// Hide default cross-sell items
		$("table.colors_lines_light").hide()	
		
		
		// Positioning Cross-sell Items
		//		Add extra space for larger product images
		//
		var p = $("#cross-sell").position()
		var neededExtraHeight = 0
		
		// 		Mac Firefox
		if(BrowserDetect.browser == "Firefox" && BrowserDetect.OS == "Mac" ){
			newLeft = p.left-10;
			neededExtraHeight = 150;
		}
		
		// 		Mac Safari
		if(BrowserDetect.browser == "Safari" && BrowserDetect.OS == "Mac" ){
			newLeft = p.left-10;
			neededExtraHeight = 250;
		}
		
		// 		Mac Chrome
		if(BrowserDetect.browser == "Chrome" && BrowserDetect.OS == "Mac" ){
			newLeft = p.left-10;
			neededExtraHeight = 250;
		}
		
		// 		Windows Firefox 3.0 
		if(BrowserDetect.browser == "Firefox" && BrowserDetect.OS != "Mac"  && BrowserDetect.version >= 3 && BrowserDetect.version < 3.5){
			newLeft = p.left-10;
			neededExtraHeight = 100;
		}
		
		// 		Windows Firefox 3.5
		if(BrowserDetect.browser == "Firefox" && BrowserDetect.version >= 3.5 && BrowserDetect.OS != "Mac" ){
			newLeft = p.left-10;
			neededExtraHeight = 100;
		}
		
		// 		Windows Chrome
		if(BrowserDetect.browser == "Chrome" && BrowserDetect.OS != "Mac" ){
			newLeft = p.left-10;
			neededExtraHeight = 360;
		}
		
		// 		Windows Opera
		if(BrowserDetect.browser == "Opera" && BrowserDetect.OS != "Mac" ){
			newLeft = p.left-10;
			neededExtraHeight = 100;
		}
		
		// 		Windows Internet Explorer 7
		if(BrowserDetect.browser == "Explorer" && BrowserDetect.OS != "Mac"  && BrowserDetect.version >= 7 && BrowserDetect.version < 8){
			newLeft = p.left
			neededExtraHeight = 80;
		}
		
		// 		Windows Internet Explorer 8
		if(BrowserDetect.browser == "Explorer" && BrowserDetect.OS != "Mac"  && BrowserDetect.version >= 8){
			newLeft = p.left - 10
			neededExtraHeight = 60;
		}
		
		
		$("#cross-sell-container").css("left",newLeft + "px")
		
		// Increase height of content area to accommodate the cross-sell layout
		conentAreaHeight = $("#content_area").height() + neededExtraHeight
		$("#content_area").height(conentAreaHeight + "px")
		
		// END CROSS-SELLING CODE
		
	}
		
		
	
	//		Gear-specific code
	//
	if (isGear) {
	
		// If there are style thumbnails, move those above the "Our Price" text
		$(".colors_productprice:first").parent().parent().parent().parent().parent().before( $("img[id^=optionimg]").parent().parent().html() )
		
		// Move price down from the thumbnails a bit
		$(".colors_productprice:first").parent().parent().parent().parent().parent().css("margin-top","0px")
		
		// Hide the <br> inserted after the price
		$(".colors_productprice:first").parent().parent().parent().parent().parent().next().hide()
		
		// remove original thumnails
		$("table.colors_pricebox:eq(1) img[id^=optionimg]").parent().parent().parent().hide()
		
		//		Remove unwanted Volusion default design element
		$("img[src*=Line_Group_Features]").hide()

/* autoselect code */	

/* might need to be redone.....			
                 //		If option dropdowns (color, Size, Style, etc) only have one option,
		//		remove the "First, Choose [thing]" option
		selects = $("form[name=MainForm] select")
		//alert(selects.length)
		$.each (selects, function () {
			if ($(this).find("option:first").val() == "0"){
				$(this).find("option:first").remove() 
			}
		});

*/
		//		Swap out "create your bike" image with "create your gear" image
		$("img[src*=Options_Text_Choose]").attr("src","/v/vspfiles/templates/102/images/Headings/hd_Options_Text_Choose_gear.gif").css("padding-bottom","10px")
		
		//		Restyle dropdown heading (probably "Styles")
		//		This involves removing a lot of code Volusion crams in there by default
		//		Note that swatch images must be uploaded for the proper elements to be hidden
		dropdownHd = $("font[class=colors_productname] i b").html();
		$("font[class=colors_productname]").parent().parent().next().next().find("td:first").html(dropdownHd + ":")
		$("font[class=colors_productname]").parent().parent().next().hide()
		$("font[class=colors_productname]").parent().parent().hide()
		
		// 	Remove line break about main product image
		$("form[name=MainForm] td:first br:first").hide()
		


		// 		If there are no dropdowns (Size, Style, etc), then Volusion uses different layout code
		//		that screws up our current layout.
		//		So we have to recode
		if ($("form[name=MainForm] select").length == 0) {
			
			 $(".colors_pricebox").clone(true).insertAfter(".colors_pricebox");
			 
			 // hides cart
			 $(".colors_pricebox:eq(0) table:eq(0) table:eq(0) td:eq(2)").hide()
			 
			 // hides price
			 $(".colors_pricebox:eq(1) table:eq(0) table:eq(0) td:eq(0)").hide()
			 
			 // remove cloned input fields
			 $("input[name=e]:first").remove()
			 $("input[name=ReplaceCartID]:first").remove()
			 $("input[name=ReturnTo]:first").remove()
			 
			// move Add to Cart and Wishlist buttons down (otherwise, they're directly under the price) 
			//
			// Mac Firefox
			if(BrowserDetect.browser == "Firefox" && BrowserDetect.OS == "Mac" ){ $(".colors_pricebox:eq(1)").css("margin-top","140px") }
			
			// Mac Safari
			if(BrowserDetect.browser == "Safari" && BrowserDetect.OS == "Mac" )	{ $(".colors_pricebox:eq(1)").css("margin-top","240px") }
			 
			// Mac Chrome
			if(BrowserDetect.browser == "Chrome" && BrowserDetect.OS == "Mac" )	{ $(".colors_pricebox:eq(1)").css("margin-top","140px") }
			
			// IE
			if(BrowserDetect.browser == "Explorer")								{ $(".colors_pricebox:eq(1)").css("top","100px")  }
			
			// Windows Firefox
			if(BrowserDetect.browser == "Firefox" && BrowserDetect.OS != "Mac" ){ $(".colors_pricebox:eq(1)").css("top","100px") }
			
			// Windows Chrome
			if(BrowserDetect.browser == "Chrome" && BrowserDetect.OS != "Mac" )	{ $(".colors_pricebox:eq(1)").css("top","100px") }

			
			// position "Add to wish list" button
			 $("input[name=btnaddtowishlist]").css("position","relative").css("left","-63px").css("top","-5px")

                             /*  $("input[name=btnaddtowishlist]").css("position","relative").css("left","-140px").css("top","-20px")   */
		

               } 
 

	} //end if(isGear)
	
	
	// 		increase right margin for description
	$(".colors_descriptionbox table:eq(0) td:eq(0)").css("padding-right", "100px")
	
	
	// Mac Firefox
	//
	if(BrowserDetect.browser == "Firefox" && BrowserDetect.OS == "Mac" ){
		if (isGear) {

			if ($("form[name=MainForm] select").length == 0) {
				$(".colors_descriptionbox:first").prev().css("margin-top","60px")	// 		move tabs down
			} else {
				$(".colors_descriptionbox:first").prev().css("margin-top","40px")	// 		move tabs down
			}

			// move text down 
			 $(".colors_pricebox:eq(0)").css("margin-top","20px")
		} else {
			$(".colors_descriptionbox:first").prev().css("margin-top","30px")	// 		move tabs down
		}
		$("img[src*=Options_Text_Choose]")
			.parent().parent().parent()
			.css("position","absolute")
			.css("top","250px")
	}
	
	// Mac Chrome
	//
	if(BrowserDetect.browser == "Chrome" && BrowserDetect.OS == "Mac" ){
		if ($("form[name=MainForm] select").length == 0) {
			// 		move tabs down 
			$(".colors_descriptionbox:first").prev().css("margin-top","50px")
		} else {
			// 		move tabs down 
			$(".colors_descriptionbox:first").prev().css("margin-top","15px")
		}	
		if (isGear) {
			
			// 	move text down 
			 $(".colors_pricebox:eq(0)").css("margin-top","40px")
			 
			 $("img[src*=Options_Text_Choose]")
			.parent().parent().parent()
			.css("position","absolute")
			.css("top","100px")
		} else {
			
			$("img[src*=Options_Text_Choose]")
			.parent().parent().parent()
			.css("position","absolute")
			.css("top","30px")
		}
		
	}
	
	// Mac Safari
	//
	if(BrowserDetect.browser == "Safari"  && BrowserDetect.OS == "Mac"  && isGear) {
		if ($("form[name=MainForm] select").length == 0) {
			$(".colors_descriptionbox:first").prev().css("margin-top","0px")		// move tabs down
		}
		else {
			$(".colors_descriptionbox:first").prev().css("margin-top","20px")		// move tabs down
			$(".colors_pricebox:eq(0)").css("margin-top","40px")					// move price down 
			$(".colors_pricebox:eq(1)").css("margin-top","40px")					// move "create gear" down
		}	
		
								
	}
	
	
	
	// Mac Opera
	//
	if(BrowserDetect.browser == "Opera"  && BrowserDetect.OS == "Mac" ) {
		$(".colors_descriptionbox:first").prev().css("margin-top","10px")			// move tabs down
	}
	
	// Windows Opera
	//
	if(BrowserDetect.browser == "Opera"  && BrowserDetect.OS != "Mac") {
		// position "our price" up a bit
		$(".colorsshell").next().hide()
		
		
		if (isGear) {
			if ($("img[id^=optionimg]").length > 0) {
				$(".colors_pricebox:eq(1)").css("margin-top","40px")					// move "create your gear" down
			} else {
				$(".colors_pricebox:eq(1)").css("margin-top","120px")					// move "create your gear" down
			}
			if ($("form[name=MainForm] select").length == 0) {
				$(".colors_descriptionbox:first").prev().css("margin-top","50px")	// move tabs down
			} else {
				$(".colors_descriptionbox:first").prev().css("margin-top","10px")	// move tabs down
			}
			
		} else {
			$(".colors_pricebox:eq(1)").css("margin-top","30px")				// move "create your bike" down
		}
	}
	
	// IE
	//
	if(BrowserDetect.browser == "Explorer") {
		// hide the <br> above the "enlarge" and "share" images
		$("img[src*=btn_emailafriend]")
			.parent().prev().prev().hide()
			
		// IE 8
		if (BrowserDetect.version >= 8) {
			if (isGear){
				$(".colors_pricebox:eq(0)").css("margin-top","0px")			// move prices
				if ($("form[name=MainForm] select").length == 0) {
					$(".colors_pricebox:eq(1)").css("margin-top","85px")
					$(".colors_descriptionbox:first").prev().css("margin-top","50px")		// move tabs down for baskets
				} else {
					$(".colors_pricebox:eq(1)").css("margin-top","30px")	// move "create your gear"
				}
			} else {
		
				$(".colors_pricebox:eq(0)").css("margin-top","-5px")
				$(".colors_pricebox:eq(1)").css("margin-top","30px")
			}
		} else {
			if (isGear){
				$(".colors_pricebox:eq(1)").css("background","transparent")
				$(".colors_pricebox:eq(0)").css("margin-top","0px")				// move prices
				$(".colors_pricebox:eq(1)").css("margin-top","30px")			// move "create your gear" down
			} else {
				$(".colors_pricebox:eq(1) table:eq(0)").css("margin-top","10px")
			}
		}
			
		// move tabs down
		if (isGear) { 
			if ($("form[name=MainForm] select").length == 0) {
				$(".colors_descriptionbox:first").prev().css("margin-top","50px")		// move tabs down for baskets
			} else {
				$(".colors_descriptionbox:first").prev().css("margin-top","55px")		// move tabs down for all other gear
			}
		} else {
			$(".colors_descriptionbox:first").prev().css("margin-top","20px")
		}		
		// position "our price" up a bit
		$(".colorsshell").next().hide()
		
		
		// IE 7 only
		if (BrowserDetect.version >= 7 && BrowserDetect.version < 8 && $(".colors_descriptionbox").length > 0) {
			if (isGear) {
				$(".colors_pricebox:eq(1)").css("margin-top","60px")	// move "create your gear"
				$(".colors_descriptionbox:first").prev().css("margin-top","20px")
				if ($("form[name=MainForm] select").length == 0) {
					$(".colors_descriptionbox:first").prev().css("margin-top","50px")		// move tabs down for baskets
				}
			}
			// move nav menu over
			$("#content").css("margin-left","0px").css("width","900px")
			$("#content_area").css("padding","0").width(900)

		}
		
		// IE 8
		if (BrowserDetect.version >= 8 && $(".colors_descriptionbox").length > 0 && isGear) {
			if (isGear) {
				$(".colors_pricebox:eq(1)").css("margin-top","70px")	// move "create your gear"
				if ($("form[name=MainForm] select").length == 0) {
					$(".colors_descriptionbox:first").prev().css("margin-top","50px")		// move tabs down
				} else {
					$(".colors_descriptionbox:first").prev().css("margin-top","20px")		// move tabs down
				}
			} else {
				$(".colors_descriptionbox:first").prev().css("margin-top","10px")		// move tabs down
			}
		}

		
	}
	
	// Windows Chrome
	
	if(BrowserDetect.browser == "Chrome" && BrowserDetect.OS != "Mac" ){
		$(".colors_descriptionbox:first").prev().css("margin-top","15px")				// 	move tabs down 
		if (isGear) {
			 $(".colors_pricebox:eq(0)").css("margin-top","5px")						// 	move price down 
			 $(".colors_pricebox:eq(1)").css("margin-top","30px")						// 	move "create your gear" down 

			if ($("img[id^=optionimg]").length > 0) {
				$("img[src*=Options_Text_Choose]")
					.parent().parent().parent()
					.css("position","absolute")
					.css("top","0px")
			} else {
				$("img[src*=Options_Text_Choose]")
					.parent().parent().parent()
					.css("position","absolute")
					.css("top","100px")
			}
			
			if ($("form[name=MainForm] select").length == 0) {
				$(".colors_descriptionbox:first").prev().css("margin-top","50px")		// move tabs down for baskets
			}
		} else {
			
			$("img[src*=Options_Text_Choose]")
				.parent().parent().parent()
				.css("position","absolute")
				.css("top","30px")
		}
	}
	
	// Windows FF 
	if(BrowserDetect.browser == "Firefox" && BrowserDetect.OS != "Mac" ){
		if (isGear) {
			$(".colors_pricebox:eq(0)").css("background","transparent")
			$(".colors_pricebox:eq(0) table:eq(0)").css("margin-top","5px")
			
			// two rows of style images pushes the layout down
			if ($("img[id^=optionimg]").length > 10) {
				$(".colors_pricebox:eq(1)").css("margin-top","30px")
			}
			else {
				$(".colors_pricebox:eq(1)").css("margin-top","60px")
			}
			
		} else {
			$(".colors_pricebox:eq(0)").css("margin-top","-5px")
		}
		
		// Windows FF 2, 3, NOT 3.5
		if (BrowserDetect.version < 3.5) {
			if (isGear) {
				if ($("form[name=MainForm] select").length == 0) { 
					$(".colors_descriptionbox:first").prev().css("margin-top","45px")
				} else {
					$(".colors_descriptionbox:first").prev().css("margin-top","10px")
				}
			} else {
				$(".colors_descriptionbox:first").prev().css("margin-top","45px")
			}
		}	
	}
	
	
	// Windows FF 3.5+
	if(BrowserDetect.browser == "Firefox" && BrowserDetect.version >= 3.5 && BrowserDetect.OS != "Mac" ){
		// move tabs down
		if (isGear) {
			if ($("img[id^=optionimg]").length > 0) {
				$(".colors_descriptionbox:first").prev().css("margin-top","20px")
			} else {
				$(".colors_descriptionbox:first").prev().css("margin-top","50px")
			}
		} else {
			$(".colors_descriptionbox:first").prev().css("margin-top","20px")
		}		
	}
	
	
	
	// Form validation for Color, Size, Frame, and Style dropdowns
	// All are required
	
	// Make sure jquery.validate thinks all the dropdowns are required.
	$(".colors_pricebox:eq(1) select").addClass("required")
	
 

  /* autoselect code */

  /* might need to recode...*/

	// If the first option is something like "First, choose size", then
	// change the first option values to blank
	$.each($(".colors_pricebox:eq(1) select"), function() { 
		if ($(this).find("option:first").val() == 0) {
			$(this).find("option:first").val('')
		}	
	})
	

	// turn off default error message
	$.validator.messages.required = "";

	$("form[name=MainForm]").validate({
		errorClass: "errorMsg",
		invalidHandler: function(form, validator) 
		{
      		var errors = validator.numberOfInvalids();
	        if (errors) {
				 alert('Please select all product options.')
	        } 
		} 
	
	});
	

	


  //replaced by this temporarily


      
      function getUrlVars() {
      	var map = {};
      	var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
      		map[key] = value;
      	});
      	return map;
      }
      

      
    /**
	**		PRODUCT PAGES - COLOR SWATCH ROLLOVER -GLR modified Aug 5 2010 for multiple color rollovers
	**/
	jQuery.fn.colorSwatchPopup = function (colorName, e) {
		if ($("#color-swatch-popup").length > 0) {
			
                        //$("#color-swatch-popup").fadeIn()
                        $("#color-swatch-popup").remove()
		} 
                //else {
			// create the popup
			$(this).parent().parent().parent().parent().parent().append('<div id="color-swatch-popup">' + colorName + '</div>')
			$("#color-swatch-popup").fadeIn()
			
			// position popup
			if(BrowserDetect.browser == "Firefox" && BrowserDetect.OS != "Mac" ){
				position = $(this).position()
				$("#color-swatch-popup").css("top",position.top+35 + "px").css("left", position.left-55 + "px")
			}
			else {
				$("#color-swatch-popup").css("top","80px").css("left", "-52px")
			}
		//}
	}
	$("img[src*=black_silver.gif]")
		.mouseover(function(e) 	{	$(this).colorSwatchPopup("Carbon/Brownish Grey Metallic",e)	})
		.mouseout(function() 	{	$("#color-swatch-popup").fadeOut()	})
	$("img[src*=carbon_salt.gif]")
		.mouseover(function(e) 	{	$(this).colorSwatchPopup("Carbon/Salt",e)	})
		.mouseout(function() 	{	$("#color-swatch-popup").fadeOut()	})
	$("img[src*=white.gif]")
		.mouseover(function(e) 	{	$(this).colorSwatchPopup("Sterling Silver",e)	})
		.mouseout(function() 	{	$("#color-swatch-popup").fadeOut()	})
	$("img[src*=black_silver2.gif]")
		.mouseover(function(e) 	{	$(this).colorSwatchPopup("Titanogrey/Nepal Silver Matte",e)	})
		.mouseout(function() 	{	$("#color-swatch-popup").fadeOut()})
	$("img[src*=s_ps1.gif]")
		.mouseover(function(e) 	{	$(this).colorSwatchPopup("Silver/Palmero Silver Matte",e)	})
		.mouseout(function() 	{	$("#color-swatch-popup").fadeOut()	})
	$("img[src*=magic_black.gif]")
		.mouseover(function(e) 	{	$(this).colorSwatchPopup("Magic Black",e)	})
		.mouseout(function() 	{	$("#color-swatch-popup").fadeOut()	})
   $("img[src*=mint.gif]")
		.mouseover(function(e) 	{	$(this).colorSwatchPopup("Mint",e)	})
		.mouseout(function() 	{	$("#color-swatch-popup").fadeOut()	})	

	$("img[src*=whit.gif]")
		.mouseover(function(e) 	{	$(this).colorSwatchPopup("Snow White Matte",e)	})
		.mouseout(function() 	{	$("#color-swatch-popup").fadeOut()	})	

	$("img[src*=canon-grey.gif]")
		.mouseover(function(e) 	{  $(this).colorSwatchPopup("Canon Grey Matte",e)  })
		.mouseout(function() 	{	$("#color-swatch-popup").fadeOut()	})

	$("img[src*=smsilvermatte.gif]")
		.mouseover(function(e) 	{	$(this).colorSwatchPopup("Smoked Silver Matte",e)	})
		.mouseout(function() 	{	$("#color-swatch-popup").fadeOut()	})

	$("img[src*=malachgreen.gif]")
		.mouseover(function(e) 	{	$(this).colorSwatchPopup("Malachite Green",e)	})
		.mouseout(function() 	{	$("#color-swatch-popup").fadeOut()	})

	$("img[src*=dologrey-sm-silv.gif]")
		.mouseover(function(e) 	{	$(this).colorSwatchPopup("Dolomite Grey/Smoke Silver Matte",e)	})
		.mouseout(function() 	{	$("#color-swatch-popup").fadeOut()	})

	$("img[src*=havana-brown2.gif]")
		.mouseover(function(e) 	{  $(this).colorSwatchPopup("Havana Brown",e)  })
		.mouseout(function() 	{	$("#color-swatch-popup").fadeOut()	})
        
        $("img[src*=ind_brown.gif]")
		.mouseover(function(e) 	{  $(this).colorSwatchPopup("India Brown",e)  })
		.mouseout(function() 	{	$("#color-swatch-popup").fadeOut()	})

        $("img[src*=white_zermatt.gif]")
		.mouseover(function(e) 	{  $(this).colorSwatchPopup("Zermatt Silver matte",e)  })
		.mouseout(function() 	{	$("#color-swatch-popup").fadeOut()	})

        $("img[src*=harbor_blue.gif]")
		.mouseover(function(e) 	{  $(this).colorSwatchPopup("Harbor Blue",e)  })
		.mouseout(function() 	{	$("#color-swatch-popup").fadeOut()	})



		
		
	/*
	swatch changing for bikes
	hide Volusion generated swatches
	add color switching events to bike swatches
	glr oct 26, 2010
	*/
	if(filename.indexOf("ka10procon.htm")>-1 || location.href.indexOf("KA10PROCON")>-1) {
		//first, hide the generated swatch code
		$('#options_table').find('tr:lt(1)').hide();
		
		//add event to mouseover for our swatches
		$("img[src*=canon-grey.gif]").mouseover(function() 	{  change_option('SELECT___KA10PROCON___16',142)  });
		$("img[src*=whit.gif]").mouseover(function() 	{  change_option('SELECT___KA10PROCON___16',113)  });
	}
	if(filename.indexOf("ka10nostal.htm")>-1 || location.href.indexOf("KA10NOSTAL")>-1) {
		//first, hide the generated swatch code
		$('#options_table').find('tr:lt(1)').hide();
		
		//add event to mouseover for our swatches
		$("img[src*=mint.gif]").mouseover(function() 	{  change_option('SELECT___KA10NOSTAL___16',143)  });
		$("img[src*=magic_black.gif]").mouseover(function() 	{  change_option('SELECT___KA10NOSTAL___16',80)  });
	}

	if(filename.indexOf("ka10pros.htm")>-1 || location.href.indexOf("KA10PROS")>-1) {
		//first, hide the generated swatch code
		$('#options_table').find('tr:eq(1)').hide();
		
		//add event to mouseover for our swatches
		$("img[src*=DT-solo.gif]").mouseover(function() 	{  change_option('SELECT___KA10PROS___14',68)  });
		$("img[src*=TR-solo.gif]").mouseover(function() 	{  change_option('SELECT___KA10PROS___14',82)  });
	}

        if(filename.indexOf("ka10sahcomp.htm")>-1 || location.href.indexOf("KA10SAHCOMP")>-1) {
		//first, hide the generated swatch code
		$('#options_table').find('tr:eq(1)').hide();
		
		//add event to mouseover for our swatches
		$("img[src*=DT-solo.gif]").mouseover(function() 	{  
		   change_option('SELECT___KA10SAHCOMP___14',68);
		   //$('#printbug').attr('href', 'http://www.kalkhoffusa.com/product_data/specs/ka10sahcomp-d.pdf');
		});
		$("img[src*=WA-solo.gif]").mouseover(function() 	{  
		   change_option('SELECT___KA10SAHCOMP___14',69);
                   //$('#printbug').attr('href', 'http://www.kalkhoffusa.com/product_data/specs/ka10sahcomp.pdf');
		});
	}


	if(filename.indexOf("ka10procnew.htm")>-1 || location.href.indexOf("KA10PROCNEW")>-1) {
		//first, hide the generated swatch code
                $('#options_table').find('tr:eq(0)').hide();
                $('#options_table').find('tr:eq(2)').hide(); 
		
		//add event to mouseover for our swatches
		$("img[src*=canon-grey.gif]").mouseover(function() 	{
                   change_option('SELECT___KA10PROCNEW___16',142);
                   //change_option('SELECT___KA10PROCNEW___14',68);
                });

		$("img[src*=whit.gif]").mouseover(function() 	{  
                     change_option('SELECT___KA10PROCNEW___16',113);  
                });

		//add event to mouseover for our swatches
		$("img[src*=DT-solo.gif]").mouseover(function() 	{  
		   change_option('SELECT___KA10PROCNEW___14',68);
		});
		$("img[src*=WA-solo.gif]").mouseover(function() 	{  
                   change_option('SELECT___KA10PROCNEW___16',113);    		   
                   change_option('SELECT___KA10PROCNEW___14',69);
		});
	   }
	
	
/* Leaving in place temporarily in case there are modifications needed, 
   check bug  #173, if closed, then this can be deleted.
   
	if(filename.indexOf("KA10PROCON_2TONE")>-1) {
		//first, hide the generated swatch code
		$('#options_table').find('tr:lt(1)').hide();
		
		//add event to mouseover for our swatches
		$("img[src*=canon-grey.gif]").mouseover(function() 	{  change_option('SELECT___KA10PROCON_2TONE___16',142)  });
		$("img[src*=whit.gif]").mouseover(function() 	{  change_option('SELECT___KA10PROCON_2TONE___16',113)  });
	}
*/
	/**
	**		PRODUCT PAGES - DUPLICATE ADD TO CARTS
	**/ 
	//			Specifically, when adding locks, two are added to the cart instead of just one
	//			This appears to be a problem with there being two <input name="ProductCode"> fields
	if ($("input[name=ProductCode]").length > 1) {
		$("input[name=ProductCode]:first").remove()
	}
      
    /**
	**		PRODUCT PAGES - FITTING GUIDE
	**/
	//	create a "fitting guide" link under the dropdowns, but above the purchase buttons

	
	if ($(".colors_pricebox:eq(1) select").length > 0 ) {
	
		//	Create fitting guide link for non-gear items
		if (!isGear) {
			$(".colors_pricebox:eq(1) select:last")
				.after('<div id="fitting-guide-link"><a href="" >fitting guide</a></div><img src="/v/vspfiles/assets/images/fitting_guide.png" id="fitting-guide-popup">')
		}
	}
	
	//		alternate line item colorsi
	//		Note this also affects the "features" lists in the product description section (which is handy)
             $(".colors_descriptionbox li:even").css("background","#f4f4f5");


	$("#fitting-guide-link").click( function(e) {
		e.preventDefault();
		$("#fitting-guide-popup").fadeIn()
		
		if(BrowserDetect.browser == "Firefox" && BrowserDetect.OS != "Mac" ){
			$("#fitting-guide-popup").css("top",e.pageY-100 + "px").css("left", e.pageX-450 + "px")
		}
		else {
			$("#fitting-guide-popup").css("top","0px").css("left", "-200px")
		}
	})
	
	$("#fitting-guide-popup").click( function() {
		$(this).fadeOut()
	
	})
	
	

	/**
	**		PRODUCT OVERVIEW PAGES
	**/
	// change border colors as user mouses over the gallery thumbnails
		
	$(".bike-item img")
	.mouseover( function() {
		$(this).addClass("on").parent().next().addClass("linkon")
	})
	.mouseout( function() {
		$(this).removeClass("on").parent().next().removeClass("linkon")
	})
	$(".bike-item a")
	.mouseover( function() {
		$(this).prev().find("img").trigger("mouseover")
	})
	.mouseout( function() {
		$(this).prev().find("img").trigger("mouseout")
	})
		
	
	/**
	**		YELLOW ALERTS
	**			Hide them on product pages.
	**/
	if ($(".colors_pricebox:eq(1) select").length > 0 ) {
		if ($("img[src*=error_alert]").length > 0) {
			$("img[src*=error_alert]").parent().parent().parent().parent().parent().parent().parent().hide()
			alertMs = $("img[src*=error_alert]").parent().next().find("li b").html()
			newAlertHTML = '<div class="error">' + alertMs + '</div>'
			bigTable = $("img[src*=error_alert]").parent().parent().parent().parent().parent().parent().parent()
			
			/* $(newAlertHTML).insertBefore(bigTable) */
						$("img[src*=error_alert]").parent().parent().parent().parent().parent().parent().parent().parent().prev().remove();
						$("img[src*=error_alert]").parent().parent().parent().parent().parent().parent().parent().parent().next().remove();
                        alert('We are sorry, this product is not \ncurrently available with those options. ');
		}
	}
	
	
	/**
	**		WHITE BACKGROUND PAGES
	**/
	$("img[src*=images/headings]")
		.css("margin-top","20px")
		.css("margin-left", "20px")
		
	
	/**
	**		WISH LIST
	**/
	// remove "add to cart" button
	$("form[action*=ShoppingCart.asp]").find("img[src*=addtocart]").parent().hide()


	/**
	**		TUNE-UP CREDIT
	**/
	if ($("#tuneUpForm").length > 0) {
		$("#tuneUpForm").validate()
	}
	
	/**
	**		TUNE-UP CREDIT - THANK YOU
	**/
	if (filename.indexOf("emailform.asp") > -1)  {
		// Don't replace anything if there's an error
		pageHTML = $("#content_area").html()
		if (pageHTML.indexOf("ERROR") < 0) {
		
			newHTML = '<div style="margin-top: 20px; margin-left: 20px;">'
			newHTML += '<img src="/v/vspfiles/assets/images/headers/thank_you.gif" alt="Thank you" >'
			newHTML += '<p>We will credit your card as soon as we verify your tune-up!</p>'
			newHTML += '</div>'
			
			$("#content_area").html(newHTML)
		}
	}
	
	
	/**
	***		ONE-PAGE CHECKOUT
	**/
	$("#font_checkout_cart a").each(function(i) {
		linkText = $(this).html()
		$(this).html('<span style="color:#bb5427">' + linkText + "</span>") 
	})
	$("#table_checkout_cart1 td:eq(0)").removeClass("colors_background_main").css("background","#fff")
	
	// autopopulate with billing address, if it exists
	$("select[name=My_Saved_Billing] option:eq(1)").attr("selected","selected")
	$("select[name=My_Saved_Billing]").change()


	// if we are on this page, then auto-select credit card as payment type:
	if ( $("select[name='PaymentMethodType']").length > 0) {
		$("select[name='PaymentMethodType'] option[value='Credit Card']").attr('selected', 'selected');
		Choose_PaymentMethodType(1);	
	}
	

	// Move Coupon code section
	here = location.href
	if (here.indexOf("one-page-checkout.asp") < 0) {
		//alert("i")
		// tweak for IE7
		if (BrowserDetect.browser == "Explorer" && BrowserDetect.version >= 7 && BrowserDetect.version < 8)  {
			$("img[src*=coupon]").parent().parent().parent().parent().css("margin","0px 0 0 120px")
		} else {
			$("img[src*=coupon]").parent().parent().parent().parent().css("margin","-40px 0 0 120px")
		}
	} 
	//	Remove dotted line around Coupn Code form
	$("img[src*=coupon]").hide()
	$("td[background*=coupon]").hide()
	
	/**
	***		FACEBOOK ICON
	**/
	$(".facebook").hover( 
		function() {	this.src = this.src.replace("_off","_on")	},
		function() {	this.src = this.src.replace("_on","_off")	})
	
	
	
	/**
	***		CHECK OUT
	**/	
	//			Move "apply" button down a bit
	$("input[name=btnApply]").css("position","relative").css("top","5px")
	
	//			Remove super-light text of "Shipping to [][][]"
	if (location.href.indexOf("one-page-checkout.asp") > -1 ){
		$("font[color=#cccccc]").hide()
	}
	
	// restyle Cart Item popup pages
	//		page title: Help_CartItemDetails.asp
	if(location.href.indexOf("shoppingcart.asp") > -1 || location.href.indexOf("ShoppingCart.asp") > -1){

		var clicktext = ""
		// Alter the "View List" link so we can change its default behavior
		if ($("a[href*=void]").length > 0) 
		{
			clicktext = $("a[href*=void]").attr("onclick")
			var temp = $('<div>');
			var linkHTML = temp.html($("a[href*=void]").clone()).html();
			
			temp.html('<a id="bike_details" href="">[+] View list of options I selected</a>')
			$("a[href*=void]").after(temp)
			temp.prev().hide()
		}
		
		clicktext = clicktext + ""
		popupURL = clicktext.split("\"")[1]
		
		$("#bike_details").click(function(e) {
			e.preventDefault()
			
			// open a blank popup window
			popWin = window.open("", "popWin", "height=400,width=400,toolbar=0,location=0,status=0")
			
			// Use AJAX to get the raw HTML
			$.ajax({
				url: popupURL,
			  	cache: true,
			  	success: function(html){

			    	// remove all instances of class="colors_background_main" from the HTML
			    	var intIndexOfMatch = html.indexOf( 'class="colors_background_main"' );
			    	while (intIndexOfMatch != -1)
			    	{
						html = html.replace( 'class="colors_background_main"', "" )
						intIndexOfMatch = html.indexOf( 'class="colors_background_main"' );
					}
					
					// write the altered HTML to the popup window
					popWin.document.write(html)
			  	}
			});
		
		})

	}
	
	
	/**
	**	change our price on gift cert
	**/

	
	var giftc = false;
	if (filename.indexOf("GFT") != -1 || filename.indexOf("gft") != -1)  {
		giftc = true;
	}
	allhtml = document.getElementsByTagName("body")[0].innerHTML;
	if (allhtml.indexOf("gift certificate") != -1)  {
		giftc = true;
	}
	
	if(giftc){
		function swp(input) {
			input = input.replace("Our Price:", "You can buy a gift certificate for any amount.");
			return input;
		}
		function swpOurPrice() {
			document.getElementsByTagName("body")[0].innerHTML = swp(document.getElementsByTagName("body")[0].innerHTML);
		}
		swpOurPrice();
	}


	
 
}); 

/**
**		BROWSER DETECTION
**/

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
