﻿/* -----------------------------  Image Swap function ----------------------------------------- 
 * assumes that an image is inside of a link for example
 * <a href=""><img src="someimage.gif" /></a>
 * 
 * DOES NOT WORK FOR INPUTS USE swapImagesInput
 */

function swapImages(btnName,imgName,imgType){
	var imgNorm = "/assets/images/" + imgName + "."+imgType;
	var imgOver = "/assets/images/" + imgName + "_over." + imgType; 
	
	
	$(btnName).hover(
		function() { $(this).find('img').attr({src:imgOver});},
		function() { $(this).find('img').attr({src:imgNorm});}
	);
}

/* -----------------------------  Image Swap for Inputs and Img tags ----------------------------------------- */

function swapImagesInput(btnName,imgName,imgType){
	var imgNorm = "/assets/images/" + imgName + "."+imgType;
	var imgOver = "/assets/images/" + imgName + "_over." + imgType;
	
	$(btnName).hover(
		function() { $(this).attr({src:imgOver});},
		function() { $(this).attr({src:imgNorm});}
	);
}


/* -----------------------------  document.ready (i.e. onload) ----------------------------------------- */
$(document).ready(function(){
	$('a.roll').each(function(e) {
		var imgName =  $(this).find('img').attr('src');
		imgName = imgName.replace('/assets/images/','');
		
		var imgType = imgName.substr(imgName.lastIndexOf('.')+1,3);
		imgName = imgName.replace('.'+imgType,'');
		
		swapImages($(this),imgName,imgType);
	});
	
	$('input.roll').each(function(e) {
		var imgName =  $(this).attr('src'); // note, this assumes it is an ImageButton
		imgName = imgName.replace('/assets/images/','');
		
		var imgType = imgName.substr(imgName.lastIndexOf('.')+1,3);
		imgName = imgName.replace('.'+imgType,'');
		
		swapImagesInput($(this),imgName,imgType);
	});
	
	$('img.roll').each(function(e) {
		var imgName =  $(this).attr('src'); // note, this assumes it is an img tag
		imgName = imgName.replace('/assets/images/','');
		
		var imgType = imgName.substr(imgName.lastIndexOf('.')+1,3);
		imgName = imgName.replace('.'+imgType,'');
		
		swapImagesInput($(this),imgName,imgType);
	});
	
	/*** nav dropdown ***/
	$('.mainNav li').hover(
		function() {
			//$('div.dropdownOuter', this).css('display', 'block');
			$('div.dropdownOuter', this).fadeIn('fast');
			$('div.dropdownOuter', this).css('z-index', '100');
			//$('.mainContent').css('z-index', '1');
		},
		function() {
			$('div.dropdownOuter', this).css('display', 'none');
		}
	);
	
	/*** product listing profile lists menu ***/
	
	$('.productThListBtn').click( function() {
		$('.productThListMenu').hide();
		//$(this).parent().find('.productThListMenu').css('display','block');
		$(this).parent().find('.productThListMenu').fadeIn('normal');
	});
	
	$('.productThListMenu').hover( 
		function() { $(this).show(); },
		function() { $('.productThListMenu').hide();}
	);
	
	/*** dealer search input fields ***/
	
	$('.dealerClickInput').focus( function() {
		if ($(this).val()) {
			var inputVal = jQuery.trim($(this).val());
			
			if (inputVal == 'Zip/Postal Code' || inputVal == 'City') {
				$(this).val('');
			}
		} else {
		
		}
	});
	
	$('.dealerInputZip').blur( function() {
		if ($(this).val()) {
			var inputVal = jQuery.trim($(this).val());
			
			if (inputVal == '') {
				$(this).val('Zip/Postal Code');
			}
		} else {
			$(this).val('Zip/Postal Code');
		}
	});
	
	$('.dealerInputCity').blur( function() {
		if ($(this).val()) {
			var inputVal = jQuery.trim($(this).val());
			
			if (inputVal == '') {
				$(this).val('City');
			}
		} else {
			$(this).val('City');
		}
	});
	
});

function swapTabClass(argTabId) {
	obj = document.getElementById(argTabId);
	if (obj.className.indexOf("pdTabSelected") != -1) {
		obj.className = obj.className.replace("pdTabSelected", "pdTabDeSelected");
	} else {
		obj.className = obj.className.replace("pdTabDeSelected", "pdTabSelected");
	}
}

function toggleTab(argTabID, argTabContentID) {
	if (argTabID != currentProdTabID) {
		swapTabClass(currentProdTabID);
		swapTabClass(argTabID);
		hide(currentProdTabContentID);
		show(argTabContentID);
		currentProdTabID = argTabID;
		currentProdTabContentID = argTabContentID;
	}
}

function pdImagesTabShow(argImageID, argTabID) {
	/*
	if (argTabID != currentImageTabID) {
		// switch tabs look
		if (argTabID == "pdImagesTabColors") {
			show("pdImagesTabColorLimg");
			document.getElementById("pdImagesTabImagesInner").className = "pdImagesTabInnerOff";
			document.getElementById("pdImagesTabImages").className = "";
			document.getElementById("pdImagesTabImagesB").className = "";
			document.getElementById("pdImagesTabColorBL").className = "";
			document.getElementById("pdImagesTabColors").className = "";
			document.getElementById("pdImagesTabBM").className = "";
			document.getElementById("pdImagesTabColorsB").className = "";
			document.getElementById("pdImagesTabColorsInner").className = "pdImagesTabInnerOn";
		} else {
			hide("pdImagesTabColorLimg"); 
			document.getElementById("pdImagesTabColorBL").className = "off";
			document.getElementById("pdImagesTabColors").className = "off";
			document.getElementById("pdImagesTabBM").className = "off";
			document.getElementById("pdImagesTabColorsB").className = "off";
			document.getElementById("pdImagesTabColorsInner").className = "pdImagesTabInnerOff";
			document.getElementById("pdImagesTabImages").className = "on";
			document.getElementById("pdImagesTabImagesB").className = "on";
			document.getElementById("pdImagesTabImagesInner").className = "pdImagesTabInnerOn";
		}
		
		currentImageTabID = argTabID;
	}
	*/
	
	// hides the current main image
	$("#pdImageMain" + currentImageID).hide();
	
	// shows the passed main image
	//show("pdImageMain" + argImageID);
	$("#pdImageMain" + argImageID).fadeIn("normal");
	
	// turns off the current thumbnail
	document.getElementById("pdImageThumb" + currentImageID).className = " ";
	
	// turns on the passed thumbnail
	document.getElementById("pdImageThumb" + argImageID).className = "pdSelectedImg";
	
	currentImageID = argImageID;
}

if ($.browser.msie && (parseInt($.browser.version) < 7)) {
	$(document).ready(function(){
		$("div.zoomIcon img").css('display', 'block');
		$("div.zoomIcon img").attr("src","/assets/images/products/zoomIcon.gif");
	});
}