var xPos = xTarget = 0;
var mouseX,mouseY = 0;

var myLoop;
var imgBox;
var redGlas1, redGlas2;
var lines;
var clientsOn=false;
var projectsOn=false;


clientImg = new Image();
clientImg.src = "material/mood/allClients.jpg";
projectImg = new Image ();
projectImg.src = "material/mood/allProjects.jpg";





// -----------------------------
// ON MOUSEMOVE
// -----------------------------

onMouseMove= function () {
	mouseMove(event);
} // end MOUSEMOVE



// -----------------------------
// ON LOAD
// -----------------------------

onload = function () {
	imgBox = document.getElementById("imgWrapper");
	redGlas1 = document.getElementById("redGlas1");
	redGlas2 = document.getElementById("redGlas2");
	lines = document.getElementById("lines");
	content = document.getElementById("content");
	//alert (content);
	mouseInit();
	
}  // end ONLOAD




// -----------------------------
// PLACE IMG
// -----------------------------
// um erneute animation beim neuladen der seite zu vermeiden

function placeImg (aMultipl) {
	imgBox = document.getElementById("imgWrapper");
	xPos = (-400*parseInt(aMultipl))+"px";
	imgBox.style.left= xPos;
	//alert (xPos);
}




// -----------------------------
// INSERT BLOG
// -----------------------------

function insertBlog () {
	//alert ("insertBlog()"); 
	
	//content.innerHTML = "<?php include (http://amg-hamburg.de/news/newsblog.html); ?>";
	//content.innerHTML = "<?php echo 'test'; ?>";
	//content.style.border = "2px solid blue";
	content.style.visibility="hidden";
} // end INSTERT




// -----------------------------
// MOVE
// -----------------------------

function move (aMultipl) {
	if (myLoop) {
		clearInterval(myLoop);
	}
	myLoop = window.setInterval ("loop()", 50);
	xTarget = -400*aMultipl;
} // end MOVE



// -----------------------------
// LOOP
// -----------------------------

function loop () {
	//window.console.log(xPos);
	myXPos = imgBox.offsetLeft;
	myXPos = xTarget*0.2 + myXPos*0.8;
	var dist = xTarget - myXPos;
	
	if (Math.abs(dist)<5) {
		myXPos=xTarget;
		imgBox.style.left=myXPos+"px";
		clearInterval(myLoop);
	}
	imgBox.style.left=myXPos+"px";
} // end LOOP



// -----------------------------
// MOVE RED GLAS
// -----------------------------


function moveGlasLayers () {
	//window.console.log (parseInt(50-redGlasWidth/2)+"px");

	if (mouseX<1000) {
		var xPos = mouseX;	
	} else {
		var xPos = 1000;	
	}
	
	
	var redGlasWidth = parseInt(((xPos/300)*100)-50);
	
	// aktiver bereich ist links oben
	if (mouseY<400 && mouseX < 850) {
		redGlas1.style.width = redGlasWidth+"px";
		redGlas1.style.left = parseInt(50-redGlasWidth/2)+"px";
		
		redGlas2.style.width = redGlasWidth*2+"px";
		redGlas2.style.left = parseInt(600-redGlasWidth/2)+"px";
		
		lines.style.left=parseInt((xPos-300)*2)+"px";
		lines.style.width=parseInt(((xPos/300)*100)-50)+"px";
	}
	
} // end MOVE RED GLAS



function changeImg (aId) {
	//alert (aId);
	if (aId==0) {
		document.images["moodImg"].src = projectImg.src;
		placeImg(0);
	} else if (aId==1) {
		document.images["moodImg"].src = clientImg.src;
		placeImg(0);
	}
}

// -----------------------------
// SHOW HIDE MOODBOX
// -----------------------------

function moodShow (aOn) {
	//alert (aOn);
	if (aOn==true) {
		document.images["moodImg"].src="material/mood/allMoods.jpg";
	} else {
		if (clientsOn==true) {
			document.images["moodImg"].src = clientImg.src;
			placeImg(0);
		} else if (projectsOn==true) {
			document.images["moodImg"].src = projectImg.src;
			placeImg(0);
		} else {
			document.images["moodImg"].src="material/mood/allMoods.jpg";
		}

	}
	
} // end SHOW HIDE CLIENT BOX


// -----------------------------
// SHOW HIDE CLIENTBOX
// -----------------------------

function clientShow (aOn) {
	//alert (aOn);
	if (aOn==true) {
		//document.images["moodImg"].src = clientImg.src;
		clientsOn=true;
	} else {
		document.images["moodImg"].src="material/mood/allMoods.jpg";

	}
	
} // end SHOW HIDE CLIENT BOX



// -----------------------------
// SHOW HIDE PROJECTBOX
// -----------------------------

function projectShow (aOn) {
	//alert (aOn);
	if (aOn==true) {
		//document.images["moodImg"].src = projectImg.src;
		projectsOn=true;
	} else {
		document.images["moodImg"].src="material/mood/allMoods.jpg";

	}
	
} // end SHOW HIDE CLIENT BOX




// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * MOUSE STUFF * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *




function mouseMove(event) {
	/* Ueberwachung der Mausbewegungen */

	if (document.all) {
		/* MSIE, Konqueror, Opera : */
		mouseX=event.clientX;
		mouseY=event.clientY;
    	if (document.body.scrollLeft) {
			mouseX+=document.body.scrollLeft;
		}
    	if (document.body.scrollTop) {
			mouseY+=document.body.scrollTop;
		}
  	} else {
  		/* Netscape, Mozilla : */
    	mouseX=event.pageX;
    	mouseY=event.pageY;
	}
	
	
	moveGlasLayers();
} // end mouseMove





/* Initialisierung der Mausueberwachung */
function mouseInit() {
	/* MSIE, Konqueror, Opera : */
	if (document.all) {
    	window.onmousemove=mouseMove;
	} else {
		/* Netscape6, Mozilla : */
    	if (typeof(document.addEventListener)=="function")
      	document.addEventListener("mousemove",mouseMove,true);
  }
} // end MOUSE INIT



