// kalkhoff_utilities.js
//this all occurs on page load........this version of kalkhoff_utilities is modifed from the version on Volusion


/**
**		PAGE TITLE
**/
document.title.replace(/greenlight bikes llc/i,"Kalkhoff");

function isIE(){
	return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

// Since prototype is loaded earlier //glr commented out dec 17 for greenlightbikes version, seemed to be breaking the 
// the product compare page
//jQuery.noConflict();

// homepage slideshow
var to1, cur, pause;
pause = false;

function slide_home1() {
	cur=1;
	$("#homeimgmain").fadeOut(200).hide().attr("src","/images/HomePage/slide1.jpg").fadeIn(700);
		$("#latestmodels").fadeIn(2000);
		$("#hometext").hide().css({'left':'500px','top':'55px'}).html('<a href="http://store.kalkhoffusa.com/sahel-comp-ebike-p/ka10sahcomp.htm"><div class="big">Sahel Comp Pedal-Assist E-Bike</div><div class="ctasub">with Brooks leather saddle and grips<br>$3,399 (free shipping, satisfaction guaranteed)</div></a>').fadeIn(2000);
		clearTimeout(to1);
		if(!pause) { to1 = setTimeout('slide_home2()',9000); }
}

function slide_home2() {
	cur=2;
	$("#homeimgmain").fadeOut(200).hide().attr("src","/images/HomePage/slide2.jpg").fadeIn(700);
		$("#latestmodels").fadeIn(2000);
		$("#hometext").hide().css({'left':'35px','top':'150px'}).html('<a href="http://store.kalkhoffusa.com/sahel-pro-disc-ebike-p/ka10sahpro.htm"><div class="big">Sahel Pro<br>Pedal-Assist E-Bike</div><div class="ctasub">with Shimano Disc Brakes<br> $3,449 (free shipping, <br>satisfaction guaranteed)</div></a>').fadeIn(2000);
		clearTimeout(to1);
		if(!pause) { to1 = setTimeout('slide_home3()',9000); }
}

function slide_home3() {
	cur=3;
	$("#homeimgmain").fadeOut(200).hide().attr("src","/images/HomePage/slide3.jpg").fadeIn(700);
		$("#latestmodels").fadeIn(2000);
		$("#hometext").hide().css({'left':'25px','top':'120px'}).html('<a href="http://store.kalkhoffusa.com/pro-connect-sport-9g-ebike-p/ka10pros.htm"><div class="big">Pro Connect Sport Pedal-Assist E-Bike</div><div class="ctasub">with leather grips and LCD backlit<br>controller. $3,899 (free shipping,<br>satisfaction guaranteed)</div></a>').fadeIn(2000);
		clearTimeout(to1);
		if(!pause) { to1 = setTimeout('slide_home4()',9000); }
}

function slide_home4() {
	cur=4;
	$("#homeimgmain").fadeOut(200).hide().attr("src","/images/HomePage/slide4.jpg").fadeIn(700);
		$("#latestmodels").fadeIn(2000);
		$("#hometext").hide().css({'left':'520px','top':'200px'}).html('<a href="http://store.kalkhoffusa.com/pro-connect-sport-dual-drive-ebike-p/ka10prosdd.htm"><div class="big">Pro Connect S Dual Drive<br>Pedal-Assist E-Bike</div><div class="ctasub">with 27 speeds and LCD backlit controller.<br>$3,999 (free shipping, satisfaction guaranteed)</div></a>').fadeIn(2000);
		clearTimeout(to1);
		if(!pause) { to1 = setTimeout('slide_home5()',9000); }
}

function slide_home5() {
	cur=5;
	$("#homeimgmain").fadeOut(200).hide().attr("src","/images/HomePage/slide5a.jpg").fadeIn(700);
		$("#latestmodels").fadeIn(2000);
		$("#hometext").hide().css({'left':'540px','top':'45px'}).html('<a href="http://store.kalkhoffusa.com/nostalgia-p/ka10nostal.htm"><div class="big">Nostalgia<br>Mint or Black</div><div class="ctasub">with Brooks leather saddle and grips<br>$1,100 (free shipping, satisfaction guaranteed)</div></a>').fadeIn(2000);
		clearTimeout(to1);
		if(!pause) { to1 = setTimeout('slide_home1()',9000); }
}


jQuery(document).ready(function($){


	/**
	**		HOME PAGE
	**/
	if ( $("#home_flash").length > 0 ) {
		$("#home_flash").flash( {   
			swf: '/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")
		})
	}
	//end home page
		/**
	**		HOME PAGE NON-FLASH
	**/
	if ( $("#home_flash2").length > 0 ) {
		// ctas under main image
		$(".ctas img:not(:last)").css("margin-right","8px")
		$(".ctas img")
		.mouseover( function() {
			$(this).removeClass("border").addClass("on")
		})
		.mouseout( function() {
			$(this).removeClass("on").addClass("border")
		})
		
		slide_home1();
		// main image
		$(".playback").click(function(){
				clearTimeout(to1);
				m = $(this).attr("rel");
				$("#pause").removeClass("playbackon");
			if (m==0) {
				if (pause) { 
					m=1;
					$("#forward").addClass("playbackon");
					$("#pause").removeClass("playbackon");
				}
				else {
					pause = true;	
					$("#pause").addClass("playbackon");
					$("#forward").removeClass("playbackon");
				}
			}
			if (m==1) {
				pause = false;
				$("#forward").addClass("playbackon");
				if (cur==1) { slide_home2(); } else if (cur==2) { slide_home3(); }	else if (cur==3) { slide_home4(); }	else if (cur==4) { slide_home5(); }	else if (cur==5) { slide_home1(); }	
			}
			if (m==-1) {
				pause = false;
				$("#forward").addClass("playbackon");
				if (cur==1) { slide_home5(); } else if (cur==2) { slide_home1(); }	else if (cur==3) { slide_home2(); }	else if (cur==4) { slide_home3(); }	else if (cur==5) { slide_home4(); }	
			}
		});
		
	}
		/**
	**		GALLERY
	**/
	//currentGalleryItemId = $("#gallery-thumbnails img:first").attr("alt")
	currentGalleryItemId = "init";
	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) {
		
  		$("#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")
	
	//end gallery
	
	/**
	**		HISTORY VIDEO
	**/
	if ( $("#history_flash").length > 0 ) {
		$("#history_flash").flash( {   
			swf: '/video/kalkhoff_history.swf',   
			width: 320,
			height: 300
		});
	}
	
	
});