function changeImage(img_name, img_src) {
   document[img_name].src = img_src;
}
////scroll functions begin
///projects slider
function initScrollMovers() {
	var mySpeed = 2;
	var movement = 0;
	var thread;
	var numLoops = 1;

	$('#hold2').mousemove(function(e) {
		$(this).addClass("moving");
		clearTimeout(thread); 
		
		var mouseY = e.pageY - $(this).offset().top;
		movement = Math.cos((-mouseY/$('#hold2').height())*Math.PI)*mySpeed;
		numLoops = 0;
		updateThumbs(mouseY, movement);
	});
	
	$('#hold2').mouseleave(function() {
		$(this).removeClass("moving");
		clearTimeout(thread);
	});
	
	function updateThumbs(mouseY, movement) {		

		var lyrPos = $('#lyr2').position();
		var lyrPosY = lyrPos.top;
		var lyrNewYPos = lyrPosY;
		++numLoops;
		
		lyrNewYPos = lyrNewYPos + movement;

		$('#lyr2').css("top", lyrNewYPos);
		
		if (lyrNewYPos>0) {
			$('#lyr2').css("top", 0);
			$('#hold2').removeClass("moving");
			clearTimeout(thread);
		}
		else if (-lyrNewYPos>($('#lyr2').height()-$('#hold2').height())) {
			lyrNewYPos = -($('#lyr2').height()-$('#hold2').height());
			$('#lyr2').css("top", lyrNewYPos);
			$('#hold2').removeClass("moving");
			clearTimeout(thread);
		}
		else if ( $('#hold2').hasClass("moving") && (numLoops<1000) ){
			thread = setTimeout(function(){updateThumbs(mouseY, movement)}, mySpeed);
		} else {
			$('#hold2').removeClass("moving");
			clearTimeout(thread);
		}

	}
	////function projects scrollup
	var movementUp2 = 2;
	var threadUp2;
	var numLoopsUp2 = 1;
	
	$('#up2').mousemove(function() {

		$(this).addClass("moving");
		clearTimeout(threadUp2); 
		numLoopsUp2 = 0;
		updateUpArrow2(movementUp2);
		

  	});
  	$('#up2').mouseleave(function() {
		$(this).removeClass("moving");
		clearTimeout(threadUp2);

	});
	function updateUpArrow2(movementUp2) {		

		var lyrPos = $('#lyr2').position();
		var lyrPosY = lyrPos.top;
		var lyrNewYPos = lyrPosY;
		++numLoopsUp2;
		
		lyrNewYPos = lyrNewYPos + movementUp2;

		$('#lyr2').css("top", lyrNewYPos);
		
		if (lyrNewYPos>0) {
			$('#lyr2').css("top", 0);
			$('#up2').removeClass("moving");
			clearTimeout(threadUp2);
		}
		else if ( $('#up2').hasClass("moving") && (numLoopsUp2<1000) ){
			threadUp2 = setTimeout(function(){updateUpArrow2(movementUp2)}, mySpeed);
		} else {
			$('#up2').removeClass("moving");
			clearTimeout(threadUp2);
		}
	}
	////function scrolldown
	var movementDown2 = 2;
	var threadDown2;
	var numDownLoops = 1;
	
	$('#down2').mousemove(function() {

		$(this).addClass("moving");
		clearTimeout(threadDown2); 
		numDownLoops = 0;
		updateDownArrow2(movementDown2);

  	});
  	$('#down2').mouseleave(function() {
		$(this).removeClass("moving");
		clearTimeout(threadDown2);
	});
	function updateDownArrow2(movementDown2) {		

		var lyrPos = $('#lyr2').position();
		var lyrPosY = lyrPos.top;
		var lyrNewYPos = lyrPosY;
		++numDownLoops;
		
		lyrNewYPos = lyrNewYPos - movementDown;

		$('#lyr2').css("top", lyrNewYPos);
		
		if (-lyrNewYPos>($('#lyr2').height()-$('#hold2').height())) {
			lyrNewYPos = -($('#lyr2').height()-$('#hold2').height());
			$('#lyr2').css("top", lyrNewYPos);
			$('#down2').removeClass("moving");
			clearTimeout(threadDown2);
		}
		else if ( $('#down2').hasClass("moving") && (numDownLoops<1000) ){
			threadDown2 = setTimeout(function(){updateDownArrow2(movementDown2)}, mySpeed);
		} else {
			$('#down2').removeClass("moving");
			clearTimeout(threadDown2);
		}
	}
////individual project images slider
//////////////////////////////////
//////////////////////////////////
	var movement2 = 0;
	var thread2;
	var numLoops2 = 1;
	
	$('#hold').mousemove(function(e) {
	
		if ($('.content').height() > $('#hold').height()) {
			
			$(this).addClass("moving");
			clearTimeout(thread2); 
		
			var mouseY = e.pageY - $(this).offset().top;
			movement2 = Math.cos((-mouseY/$('#hold').height())*Math.PI)*mySpeed;
			numLoops2 = 0;
			updateThumbs2(mouseY, movement);
		}
		
	});
	
	$('#hold').mouseleave(function() {
		if ($('.content').height() > $('#hold').height()) {
			$(this).removeClass("moving");
			clearTimeout(thread2);
		}
	});
	
	function updateThumbs2(mouseY, movement) {		

		var lyrPos = $('#lyr1').position();
		var lyrPosY = lyrPos.top;
		var lyrNewYPos = lyrPosY;
		++numLoops2;
		
		lyrNewYPos = lyrNewYPos + movement2;

		$('#lyr1').css("top", lyrNewYPos);
		
		if (lyrNewYPos>0) {
			$('#lyr1').css("top", 0);
			$('#hold').removeClass("moving");
			clearTimeout(thread2);
		}
		else if (-lyrNewYPos>($('#lyr1').height()-$('#hold').height())) {
			lyrNewYPos = -($('#lyr1').height()-$('#hold').height());
			$('#lyr1').css("top", lyrNewYPos);
			$('#hold').removeClass("moving");
			clearTimeout(thread2);
		}
		else if ( $('#hold').hasClass("moving") && (numLoops2<1000) ){
			thread2 = setTimeout(function(){updateThumbs2(mouseY, movement2)}, mySpeed);
		} else {
			$('#hold').removeClass("moving");
			clearTimeout(thread2);
		}
	}

	////function scrollup
	var movementUp = 2;
	var threadUp;
	var numLoopsUp = 1;
	
	$('#up').mousemove(function() {

		$(this).addClass("moving");
		clearTimeout(threadUp); 
		numLoopsUp = 0;
		updateUpArrow(movementUp);

  	});
  	$('#up').mouseleave(function() {
		$(this).removeClass("moving");
		clearTimeout(threadUp);

	});
	function updateUpArrow(movementUp) {		

		var lyrPos = $('#lyr1').position();
		var lyrPosY = lyrPos.top;
		var lyrNewYPos = lyrPosY;
		++numLoopsUp;
		
		lyrNewYPos = lyrNewYPos + movementUp;

		$('#lyr1').css("top", lyrNewYPos);
		
		if (lyrNewYPos>0) {
			$('#lyr1').css("top", 0);
			$('#up').removeClass("moving");
			clearTimeout(threadUp);
		}
		else if (-lyrNewYPos>($('#lyr1').height()-$('#hold').height())) {
			lyrNewYPos = -($('#lyr1').height()-$('#hold').height());
			$('#lyr1').css("top", lyrNewYPos);
			$('#up').removeClass("moving");
			clearTimeout(threadUp);
		}
		else if ( $('#up').hasClass("moving") && (numLoopsUp<1000) ){
			threadUp = setTimeout(function(){updateUpArrow(movementUp)}, mySpeed);
		} else {
			$('#up').removeClass("moving");
			clearTimeout(threadUp);
		}
	}
		////function scrolldown
	var movementDown = 2;
	var threadDown;
	var numLoopsDown = 1;
	
	$('#down').mousemove(function() {

		$(this).addClass("moving");
		clearTimeout(threadDown); 
		numLoopsDown = 0;
		updateDownArrow(movementDown);

  	});
  	$('#down').mouseleave(function() {
		$(this).removeClass("moving");
		clearTimeout(threadDown);
	});
	function updateDownArrow(movementDown) {		

		var lyrPos = $('#lyr1').position();
		var lyrPosY = lyrPos.top;
		var lyrNewYPos = lyrPosY;
		++numLoopsDown;
		
		lyrNewYPos = lyrNewYPos - movementDown;

		$('#lyr1').css("top", lyrNewYPos);
		
		if (lyrNewYPos>0) {
			$('#lyr1').css("top", 0);
			$('#down').removeClass("moving");
			clearTimeout(threadDown);
		}
		else if (-lyrNewYPos>($('#lyr1').height()-$('#hold').height())) {
			lyrNewYPos = -($('#lyr1').height()-$('#hold').height());
			$('#lyr1').css("top", lyrNewYPos);
			$('#down').removeClass("moving");
			clearTimeout(threadDown);
		}
		else if ( $('#down').hasClass("moving") && (numLoopsDown<1000) ){
				threadDown = setTimeout(function(){updateDownArrow(movementDown)}, mySpeed);
		} else {
				$('#down').removeClass("moving");
				clearTimeout(threadDown);
		}
	}
}
///scroll functions end

///Panel Scripts start
function initOpenDivs() {
	var productDiv = new Object();

	$(".image_link").each(function(i) {
		var x=i+1;
		
		if ( ( $("#myThumbs_"+x).hasClass("open")) ){
			$("#myThumbs_"+x).animate({ opacity: 1 }, 100);
		}
		
		$("#myThumbs_"+x).click(
			function () {
				if ( $(this).hasClass("open") ){
					//$(this).removeClass("open");
				} else {
					//$("#myLargeImage_"+x).fadeIn('slow');
					$("#myLargeImage_"+x).animate({ opacity: 1, right: '0px' }, 600);
					
					//$(".bigImage.open").fadeOut('slow');
					$(".bigImage.open").animate({ opacity: 0, right: '-600px' }, 600);
					
					$(".image_link").not(document.getElementById('myThumbs_'+x)).removeClass("open");
					$(".bigImage").not(document.getElementById('myLargeImage_'+x)).removeClass("open");
					
					$(this).addClass("open");
					$("#myLargeImage_"+x).addClass("open");
					
					$(this).animate({ opacity: 1 }, 1);
					$(this).addClass("selected");
					
					$(".image_link").not(this).removeClass("open");
					$(".image_link").not(this).animate({ opacity: 0.7 }, 100);

				}
			}
		);
		$("#myThumbs_"+x).hover(
			function() {
				if (!( $(this).hasClass("open")) ){
					$(this).animate({ opacity: 1 }, 100);
					$(this).css({"cursor":"hand"});
				}
			},
			function(){
				if (!( $(this).hasClass("open")) ){
					$(this).animate({ opacity: 0.7 }, 100);
					$(this).css({"cursor":"hand"});
				}
			}
		);
		
	});
	
	$(".bigImage").each(function(i) {
		var x=i+1;
		$("#myLargeImage_"+x).hover(
			function() {
				if (!( $(this).hasClass("up")) ){
					$(".bigTitle", this).animate({ top: "-36px" }, 200);
					//$(this).css({"cursor":"hand"});
					$(this).addClass("up");
				} else {
					$(".bigTitle", this).animate({ top: "0px" }, 200);
					//$(this).css({"cursor":"hand"});
					$(this).removeClass("up");
				}
			},
			function(){
				if (!( $(this).hasClass("up")) ){
					$(".bigTitle", this).animate({ top: "0px" }, 200);
					//$(this).css({"cursor":"hand"});
					$(this).removeClass("up");
				} else {
					$(".bigTitle", this).animate({ top: "-36px" }, 200);
					//$(this).css({"cursor":"hand"});
					$(this).hasClass("up");
				}
			}
		);
	});
}

function initControlPanel() {
	$("#panelSwitch").click(
		function() {
			if ( !$(this).hasClass("open") ){
				$("#catContainer").animate({ width: '880px' }, 1 , function(){
					$("#catMask").animate({ opacity: 0.7 }, 600);
					$("#catThumbs").animate({ left: '0px' }, 600);
				});
				$("#panelEnd").attr("src","images/panel-left-on.png"); 
				$(this).addClass("open");
			} else {
				$("#catMask").animate({ opacity: 0 }, 600);
				$("#catThumbs").animate({ left: '-366px' }, 600, function(){
					$("#catContainer").animate({ width: '20px' }, 1 );
				});
				$("#panelEnd").attr("src","images/panel-right-on.png"); 
				$(this).removeClass("open");
			}
		}

	);
	$('.myProjectThumbs').click(function() {
		var projectID = $(this).attr('id');
		var nextProjectID = $(this).attr('id');
		var projCatID = $(".nextProject").attr('id');
		$(".nextProject").load("next_project.php?pid="+nextProjectID+"&cid="+projCatID);
		$("#project").load("this_project.php?pid="+projectID, function(){
				//initScrollLayer();
				$(document).ready(initScrollMovers);
				$(document).ready(initOpenDivs);
				$(document).ready(initRollOverImages);
				$("#catMask").animate({ opacity: 0 }, 600);
  				$("#catThumbs").animate({ left: '-366px' }, 600, function(){
  				$("#catThumbs").animate({ left: '-366px' }, 600);
				$("#panelEnd").attr("src","images/panel-right-on.png"); 
				$("#panelSwitch").removeClass("open");
				$("#catContainer").animate({ width: '20px' }, 1, function(){
					initNext();
				});
			});
		});	
	});
}

function initToLeftNav() {
	$('.topLeftNav').click(function() {
		var currentProjectID = $(".storeCurrentProjID").attr('id');
		var nextProjectID = $(this).attr('id');
		var projCatID = $(".nextProject").attr('id');
		if ($("#panelSwitch").hasClass("open")) {
			$(".nextProject").load("next_project.php?pid="+nextProjectID+"&cid="+projCatID);
			$("#project").load("this_project.php?pid="+nextProjectID, function(){
				//initScrollLayer();
				$(document).ready(initScrollMovers);
				$(document).ready(initOpenDivs);
				$(document).ready(initRollOverImages);
				$("#catMask").animate({ opacity: 0 }, 600);
				$("#catThumbs").animate({ left: '-366px' }, 600, function(){
					$("#catThumbs").animate({ left: '-366px' }, 600);
					$("#panelEnd").attr("src","images/panel-right-on.png"); 
					$("#catContainer").animate({ width: '20px' }, 1, function(){
						$("#panelSwitch").removeClass("open");
						initNext();
					});
				});
			});
		} else {
			$("#catContainer").animate({ width: '880px' }, 1);
			$("#catMask").animate({ opacity: 0.8 }, 600, function(){
				$(".nextProject").load("next_project.php?pid="+nextProjectID+"&cid="+projCatID);
				$("#project").load("this_project.php?pid="+nextProjectID, function(){
					//initScrollLayer();
					$(document).ready(initScrollMovers);
					$(document).ready(initOpenDivs);
					$(document).ready(initRollOverImages);
					$("#catMask").animate({ opacity: 0 }, 600, function(){
						$("#catContainer").animate({ width: '20px' }, 1, function(){
							initNext();
						});
					});
				});
			});
		}
	});
}

function initNext() {
	$(document).ready(initToLeftNav);
}

function initRollOverImages() {
	var image_cache = new Object();
	
	$(".rollover a img").not("[src*='-on.']").each(function(i) {
		var imgsrc = this.src;
		var dot = this.src.lastIndexOf('.');
		var imgsrc_on = this.src.substr(0, dot) + '-on' + this.src.substr(dot, 4);
		image_cache[this.src] = new Image();
		image_cache[this.src].src = imgsrc_on;

	});
	
	$("img.rollover").not("[src*='-on.']").each(function(i) {
		var imgsrc = this.src;
		var dot = this.src.lastIndexOf('.');
		var imgsrc_on = this.src.substr(0, dot) + '-on' + this.src.substr(dot, 4);
		image_cache[this.src] = new Image();
		image_cache[this.src].src = imgsrc_on;

	});
	
	$.ajaxSettings.cache = false;
	
}

$(document).ready(initOpenDivs);
$(document).ready(initScrollMovers);
$(document).ready(initControlPanel);
$(document).ready(initRollOverImages);
$(document).ready(initToLeftNav);

function changeTDColor(obj, myColor) {
	var myElement = document.getElementById(obj);
	myElement.style.backgroundColor = myColor;
}

