// JavaScript Document
$(document).ready(function() {
//	$('#image0-slide .splash-text img').attr('src', '/sites/default/files/home/txt-automated.gif');
//	$('#image1-slide .splash-text img').attr('src', '/sites/default/files/home/txt-narrowgroove.gif');
//	$('#image2-slide .splash-text img').attr('src', '/sites/default/files/home/txt-weldingtechnology.gif');
	
	var $imageListItems = $("#splash-thumbs li"); // Array of images
	var $imageHolders = $("#splash-slides li"); // Array of images
	var stopRotate = 'no'; // "no" for rotation, "yes" for rotation to stop
	var flipspeed = 5; // Number of seconds between flips
	var curImage = 0; // Image to start displaying - recommend to keep at 0
	var numImages = $imageHolders.size() -1; // Gets the size of the array of images
	var tempID = "";
	var doFade = "true";

	if ($.browser.msie && $.browser.version < 8) {
		doFade = "false";
	}


	
	if ($imageHolders.length > 1) {
		$(document).ready(function() {
			rotateImages();
	
			$imageListItems.each(
				function(index, domEle) {
					var tempSlide = "";
					if(index == 0) {
	//					$(domEle).addClass("active");
						makeActive(domEle);
					} 
					$(domEle).attr("id", "image" + index);
				}
			);
		
			$('#splash-thumbs a').click(function(){
				tempID = $(this).parent().attr("id");
				stopRotate = 'yes';
				viewSection(tempID);
				return false;
			});
		});
	}
	
	function viewSection(id) {
//		$imageListItems.removeClass("active");
//		$("#"+id).addClass("active");
		makeActive("#"+id);
		$imageHolders.each(function() {
			var $tempThis = $(this);
			if($tempThis.is(":visible")){
				if(doFade == "true") { 
					$(this+" .splashtext").fadeOut();
					$tempThis.fadeOut('slow');
				} else {
					$(this+" .splashtext").hide();
					$tempThis.hide();
				}
			}
		});
	
		var slideID = id+"-slide";
		$('#image0-slide .splash-text').css({opacity: 0, top: 100});
		$('#image1-slide .splash-text').css({opacity: 0, top: 40});
		$('#image2-slide .splash-text').css({opacity: 0, top: 110});
	
		if(doFade == "true") { 
			$("#"+slideID).fadeIn('slow', function () {
				$("#"+slideID+" .splash-text").animate({
					opacity: 1,
					top: '+=20'
//					height: 'toggle'
				});
			});
		} else {
			$("#"+slideID).show();
			$("#"+slideID+" .splash-text").animate({
				opacity: .999,
				top: '+=20'
//					height: 'toggle'
			});
		}

	}
	
	function makeActive(ele) { 
		$imageListItems.animate({
			top: '0'
		});
		$(ele).animate({
			top: '-=13'
		});
	}
	
	function rotateImages() {
		if (stopRotate != 'yes') {
			setTimeout(function() { 
				if (curImage < numImages) {
					curImage++;
				} else {
					curImage = 0;
				}
				if (stopRotate == 'no')
				{
					viewSection("image"+curImage);
				}
				rotateImages();
			}, flipspeed*1000);
		}
	}
});

