var to1;
var cur;
var count = 0;
var stopped = false;

$(document).ready(function(){  
	/* use this block if we are having stacking issues:
	var zIndexNumber = 1000;
	$('ul').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});
	*/
	//if ($.browser.msie && jQuery.browser.version == '7.0') { $('a').removeClass('more');}
	if ($('#slide_home_wrapper').length > 0) { 
		slide_home1();
	}
	if ($('#slide_auto_cont_wrapper').length > 0) { 
		slide_auto_cont1();
	}
	
	
	$('.more').click(function() {
		  return false;
	});
	
	// nav hover
	$("ul.topnav > li").hover(
			function() { $(this).addClass("foobar");},
			function() { $(this).removeClass("foobar"); } ); 

});  





// product page scrollable section ************************************************************************
var cur_pos = 0;
$(document).ready(function(){
	if ($('#scroll_move').length > 0) { 
		scroll_move_length = ($('#scroll_move').children().length-1) * 237;
		pos = $('.imgon').position();
		if (pos.left > 1900) { $('#scroll_move').css('left',-1900);}
		else if (pos.left > 950) { $('#scroll_move').css('left',-950);}
			
		$('#s_left').click(function() {
											 
											 
				$('#scroll_move').stop();
				offset = $('#scroll_move').css('left').substr(0,$('#scroll_move').css('left').length-2);
				if (offset >= 0) { $('#scroll_move').animate({"left": "0px"},500); }
				else {
					$('#scroll_move').animate({"left": "+=950px"},1000);
				}
		});
		$('#s_right').click(function() {
				$('#scroll_move').stop();	
				offset = $('#scroll_move').css('left').substr(0,$('#scroll_move').css('left').length-2);
				if (offset < -scroll_move_length+950) { $('#scroll_move').animate({"left": "0px"},500); }
				else {
					$('#scroll_move').animate({"left": "-=950px"},1000); 
				}
		});
		$('#scroll_move').find('img').hover(function() 
		{
			// on hover
			$(this).addClass('productscrollon');
			var position = $(this).position();
			var w = $(this).width()
			$('#product_scroll_tip').html( $(this).attr('alt') ).css('left',position.left).css('width',w+20).show();
		},function()
		{
			// off hover
			$(this).removeClass('productscrollon');
			//foo = setTimeout(function() { $('#product_scroll_tip').hide().clearQueue(); },500);
			$('#product_scroll_tip').hide().clearQueue();
			//$('#scroll_move').find('img').unbind();
		}
		);														
	}	
	if ($('.supplier_link_wrapper').length > 0) {
		$('.supplier_link_wrapper').hover(
			function() { $(this).addClass('supplier_over'); },
			function() { $(this).removeClass('supplier_over'); }
		);
	}
});

// ********************************************************************************************************

// if we add or subtract number of images, we need to make sure that thumbstyles() param "prev" is calculated correctly.


/* home *************************************** */
function slide_home1() {
	count++;
	if (count==2) { stopped = true; }
	thumbstyles(1);
	$('#slide_home').fadeOut(200).attr("src","/assets/images/slideshow/slide-aerospace.jpg").fadeIn(700);
	$('#flying_words').hide().css('left',560).css('top',200).css('color','#1a2f5c').html("aerospace system <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;solutions").fadeIn(100).animate({"left": "+=100px"},2000);
	clearTimeout(to1);
	if (!stopped) {
		to1 = setTimeout("slide_home2();",10000);
	}
}
function slide_home2() {
	thumbstyles(2);
	$('#slide_home').fadeOut(200).attr("src","/assets/images/slideshow/slide-controls3.jpg").fadeIn(700);
	$('#flying_words').hide(); //.css({'left':'630px','top':'10px','color':'#6d0a0b'}).html("temperature control <br><span class=bigger>&nbsp;&nbsp;&nbsp;systems</span>....").fadeIn(100).animate({"left": "-=100px"},2000);
	clearTimeout(to1);
	if (!stopped) {
		to1 = setTimeout("slide_home3();",10000);
	}
}
function slide_home3() {
	thumbstyles(3);
	$('#slide_home').fadeOut(200).attr("src","/assets/images/slideshow/slide-precision.jpg").fadeIn(700);
	$('#flying_words').hide().css('left',225).css('top',190).css('color','#fff').html("precision manufacturing<br>solutions").fadeIn(100).animate({"left": "-=100px"},2000);
	clearTimeout(to1);
	if (!stopped) {
		to1 = setTimeout("slide_home1();",10000);
	}
}

function thumbstyles(x) {
	$('#flying_words').stop();
	$("#thumb_"+cur).attr("src","/assets/images/slideshow/thumb_"+cur+".png").removeClass("selectedthumb");
	cur = x;
	$("#thumb_"+x).attr("src","/assets/images/slideshow/thumb_"+x+"_on.png").addClass("selectedthumb");
}
function thumbstyles_sub(x,y) {
	$("#thumb_"+cur).attr("src","/assets/images/slideshow/"+y+"/thumb_"+cur+".png").removeClass("selectedthumb");
	cur = x;
	$("#thumb_"+x).attr("src","/assets/images/slideshow/"+y+"/thumb_"+x+"_on.png").addClass("selectedthumb");
}
/* auto_cont *********************************** */
function slide_auto_cont1() {
	thumbstyles_sub(1,'auto_cont');
	$('#slide_auto_cont').fadeOut(200).attr("src","/assets/images/slideshow/auto_cont/slide1.jpg").fadeIn(700);
	clearTimeout(to1);
	to1 = setTimeout("slide_auto_cont2();",10000);
}
function slide_auto_cont2() {
	thumbstyles_sub(2,'auto_cont');
	$('#slide_auto_cont').fadeOut(200).attr("src","/assets/images/slideshow/auto_cont/slide2.jpg").fadeIn(700);
	clearTimeout(to1);
	to1 = setTimeout("slide_auto_cont3();",10000);
}
function slide_auto_cont3() {
	thumbstyles_sub(3,'auto_cont');
	$('#slide_auto_cont').fadeOut(200).attr("src","/assets/images/slideshow/auto_cont/slide3.jpg").fadeIn(700);
	clearTimeout(to1);
	to1 = setTimeout("slide_auto_cont1();",10000);
}
