var $j = jQuery.noConflict(); 

$j(document).ready(function(){
	$j("#front-branding p img").unwrap();
	$j("#featured p").remove();
	$j("#product-selector a").click(function(){
		var selected = $j(this).attr("rel");
		$j("#featured div.featured-products").removeClass("active");
		$j("#featured div."+selected).addClass("active");
		
		$j("#product-selector a").removeClass("active");
		$j(this).addClass("active");
		
		return false;
	});
	
	$j("div.product-image-thumbnails a").click( function(){
		var newImgLink = $j(this).find(".thumbnail").attr("rel");
		$j(this).closest(".product-media").find("#image").attr("src",newImgLink);
		return false;
	});
	
	$j("#jsAmountCalculator #your-floor-size").keyup(function(){
		var content = $j("#jsAmountCalculator #package-content").attr("rel");
		var total = $j(this).val()/content;
		if (total > parseInt(total)) {
			total = parseInt(total) + 1;
		}
		else {
			total = parseInt(total);
		} 
		$j("#jsAmountCalculator .totalCalc span.totalPack").html(total);
		$j("#jsAmountCalculator .totalCalc span.totalKvm").html(total*content);
	});
	
	$j("#opc-shipping li.address-as-billing input").focus(function(){ setBillingInformation(); });
	
	$j("#opc-shipping input.required-entry").blur(function(){
		valCheckOut();
	});
	
	
	//FORHANDLER LOGIN
	
	$j("#forhandler-search-box").quicksearch('table#products-all-table tbody tr');

	$j("#forhandler-login-search .filter-text").focus(function(){
		var checkVal = $j(this).attr("rel");
		if ($j(this).val() == checkVal){ $j(this).val(""); }
	});
	$j("#forhandler-login-search .filter-text").blur(function(){
		var checkVal = $j(this).attr("rel");
		if ($j(this).val() == ""){ $j(this).val(checkVal); }
	});	
/*	
	*/
	
	

	
	
	function setBillingInformation(){
		valCheckOut();
		$j("#billing-buttons-container button").trigger('click');
	}
	
	function valCheckOut(){
		$j("#checkout-area input.required-entry").each(function(){
			if ( $j(this).val() == "" ){
				$j(this).addClass("input-error");
			} else {
				$j(this).removeClass("input-error");
			}
		});
		return false;
	}
	
});

