
var oInfoSection = '';
var isFirst = true;
var oCartKey = '';

$(document).ready(function() {
	$("input#cal_qty").numeric();
	
	
	/*try{
		$('#welcomemessage').html('Welcome ' + getCookie('dealername'));
	} catch(e){}*/
	
	$('#productinfotab a:last').addClass('last');
	$('#productinfotab a').click(function(){
		if($(this).attr('rel') != "roomviews"){
			if(oInfoSection != $(this).attr('rel')){
				oInfoSection = $(this).attr('rel');
				DoSections();
			}
		}
	});
	
	$("a.enlarge").fancybox({
		'overlayOpacity'	:	0.7,
		'overlayColor'		:	'#352b26'
	});
	
	oInfoSection = $.query.get('Section');
	if(oInfoSection!="Accessory" || oInfoSection == ""){
		oInfoSection = $('#productinfotab a:first').attr('rel');
	} else {
		oInfoSection = 'accessories';
	}
	DoSections();
	
	$('#orders.orders tbody tr').each(function(i){
		$(this).click(function(){
			var url = $('.orders tbody tr:eq('+i+') a:first').attr('href');
			location.href=url;
		});
	});
	
	$('#shipType input[name=shipMethod]').change(function(){
		var value = jQuery('#shipType input[name=shipMethod]:checked').val();
		showShipInfo();
		switch(value){
			case "dealership":
				$('div[rel=fedexinfo]').fadeIn(250);
			break;
			case "cfship":
				$('div[rel=fedexinfo]').fadeOut(250);
			break;
		}
	});
	
	$("#productList li:nth-child(3n)").addClass("last")
	$('#productList li').each(function(i){
		$(this).click(function(){
			location.href = $('#productList li:eq('+i+') a:first').attr('href');
		});
	});
	
	$('.infosection[rel=downloads] a').each(function(){
		var oHTML = $(this).html();
		$(this).html(oHTML.substr(oHTML.lastIndexOf("/") + 1));
	});
	
	/*if($('#hfrubberprices').length > 0){
		$('#calculator').remove();
		
		var rubberinfo = [];
		rubberinfo = $('#hfrubberprices').val().split('|');
		var sizesDropdown = "";
		for(var i=0; i<rubberinfo.length;i++){
			var oExtra = [];
			oExtra = rubberinfo[i].split(',');
			for(var a=0;a<oExtra.length;a++){
				if(a == 1){
					sizesDropdown += "<option value=\""+oExtra[a]+"\">"+oExtra[a]+"</option>";
				}
			}
		}
		
		var	oString = "<ul id=\"calculator\">";
			oString += "	<li class=\"clearfix\">";
			oString += "		<label>Cut</label>";
			oString += "		<select id=\"cut\">";
			oString += "			<option value=\"Interlock\">Interlock</option>";
			oString += "			<option value=\"Square\">Square</option>";
			oString += "		</select>";
			oString += "	</li>";
			oString += "	<li class=\"clearfix\">";
			oString += "		<label>Size</label>";
			oString += "		<select id=\"size\">";
			oString += "			"+sizesDropdown+"";
			oString += "		</select>";
			oString += "	</li>";
			oString += "	<li class=\"clearfix\"><label>Qty.</label><input type=\"text\" id=\"rubb_qty\" /><a href=\"javascript:;\" onclick=\"CartMethods.CalculateRubberCart();\">Calculate</a></li>";
			oString += "	<li class=\"clearfix\"><label>Total</label><input type=\"text\" disabled=\"true\" id=\"rubb_total\" /><a href=\"javascript:;\" onclick=\"CartMethods.AdddRubberToCart();\">Order</a></li>";
			oString += "</ul>";
	
		$('#product div.details').append(oString);
	}*/
	
});
var isRepeat = false;
function showShipInfo(){
	if(!isRepeat){
		setTimeout(function() {
			$('#ajaxloader').fadeIn(250);
			$('#ajaxloader').fadeOut(250,function(){
				$('div[rel=shippinginfo]').fadeIn(250);
				$('.productspurchased').fadeIn(250);
			});
		}, 250);
	}
	isRepeat = true;
}
function DoSections(){
	$('#productinfo .infosection').fadeOut(250);
	setTimeout(function() {
		$('#tabajaxloader').fadeIn(250);
		$('#productinfotab a').removeClass('selected');
		$('#productinfotab a[rel='+oInfoSection+']').addClass('selected');
		
		$('#tabajaxloader').fadeOut(250,function(){
			$('#productinfo .infosection[rel='+oInfoSection+']').fadeIn(250);
		});
	}, 250);
}

jQuery.preloadImages = function() {
    for (var i = 0; i < arguments.length; i++) {
        jQuery("<img>").attr("src", arguments[i]);
    }
}

/***********************	Start Cookie Work		********************/
function getCookie(c_name){
	if (document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1){
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}
function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
/***********************	End Cookie Work		********************/

    
