// Café-Vrac 2.0
// Common scripts

$(document).ready(function(){
	
	// Set the state of current page nav button on page load to show down state
	// The class="current" attribute is set by ColdFusion on the server (see nav include)
	if ($("a[class=current]").children("img").attr("src")) {
		currimgdefaultsrc = $("a[class=current]").children("img").attr("src");	
		currimgsrc = currimgdefaultsrc.replace('.', '_down.');
		$("a[class=current]").children("img").attr("src", currimgsrc);
	}
	
	// Main navigation image rollovers
	$("#nav a").mouseover(function() {
		imgsrc = $(this).children("img").attr("src");
		// Fail if no image found or if user is mousing over the current page button
		if (typeof(imgsrc) != 'undefined' && $(this).attr("class") != "current") {
			// Replace .gif with _over.gif
			imgsrcON = imgsrc.replace('.', '_over.');
			// Now change the src to the 'ON' value
			$(this).children("img").attr("src", imgsrcON);
		}
	});
	
	$("#nav a").mouseout(function(){
	  // trap for 'undefined' errors again
	  if (typeof(imgsrc) != 'undefined') {
		  $(this).children("img").attr("src", imgsrc);
	  }
	});
	
	// Other images rollovers using the "roll" class
	$("a.roll").mouseover(function() {
		imgsrc = $(this).children("img").attr("src");
		// Fail if no image found or if user is mousing over the current page button
		if (typeof(imgsrc) != 'undefined' && $(this).attr("class") != "current") {
			// Replace .gif or .png with _over.gif _over.png
			imgsrcON = imgsrc.replace('.', '_over.');
			// Now change the src to the 'ON' value
			$(this).children("img").attr("src", imgsrcON);
		}
	});
	
	$("a.roll").mouseout(function(){
	  // trap for 'undefined' errors again
	  if (typeof(imgsrc) != 'undefined') {
		  $(this).children("img").attr("src", imgsrc);
	  }
	});	
	
	// Other images rollovers using the "roll" class
	$("input[type=image].roll").mouseover(function() {
		imgsrc = $(this).attr("src");
		// Fail if no image found or if user is mousing over the current page button
		if (typeof(imgsrc) != 'undefined') {
			// Replace .gif or .png with _over.gif _over.png
			imgsrcON = imgsrc.replace('.', '_over.');
			// Now change the src to the 'ON' value
			$(this).attr("src", imgsrcON);
		}
	});
	
	$("input[type=image].roll").mouseout(function(){
	  // trap for 'undefined' errors again
	  if (typeof(imgsrc) != 'undefined') {
		  $(this).attr("src", imgsrc);
	  }
	});
	// input[type=image]
	
	// Category selector rollover code for the last button (different images than the rest)
	$("#leftCol #selector ul li:last a").css("background", "url(/_assets/img/all/categories_last_btn_bgnd.png) no-repeat 50% bottom");
	$("#leftCol #selector ul li:last a.selectedCat").css("background", "url(/_assets/img/all/categories_last_btn_bgnd_down.png) no-repeat 50% bottom");
	$("#leftCol #selector ul li:last a").mouseover(function() {
		$("#leftCol #selector ul li:last a").css("background", "url(/_assets/img/all/categories_last_btn_bgnd_over.png) no-repeat 50% bottom");																													
	});
	$("#leftCol #selector ul li:last a").mouseout(function() {
		if($("#leftCol #selector ul li:last a").attr("class") == "selectedCat") {
			$("#leftCol #selector ul li:last a").css("background", "url(/_assets/img/all/categories_last_btn_bgnd_down.png) no-repeat 50% bottom");
		} else {
			$("#leftCol #selector ul li:last a").css("background", "url(/_assets/img/all/categories_last_btn_bgnd.png) no-repeat 50% bottom");																													
		}
	});
	$("#leftCol #selector ul li:last a").css("padding-bottom", "24px");
	//$("#leftCol #selector ul li:last a").css("height", "50px");
	
	// Format credit card form field 
	//$("input[name=cstCCNumber]").mask("9999 9999 9999 9999");	
	
});
