//----------------------------------------------------------------------------------------
// Preload events
// This function allows to load multiple functions at once when page loads
//----------------------------------------------------------------------------------------


	function addEvent(object, eventType, functionToCall){
	if(object.addEventListener){
		//will run on Mozilla based browsers
		object.addEventListener(eventType, functionToCall, false);
		return true;
	}else if(object.attachEvent){
		//will run on IE
		var x = object.attachEvent("on"+eventType, functionToCall);
		return x;
	}else{
		//the browser doesnt support either method
		return false;
	}
	}



//----------------------------------------------------------------------------------------
// VERY IMPORTANT - SETUP THE INITAL STATE TO SOME IDs WHEN PAGE IS LOADED
//----------------------------------------------------------------------------------------

	function setup() {
	
	// Make sure browser understands DOM
	
	if(!document.getElementsByTagName){ return false; }
	if(!document.getElementById){ return false; }
	
	// Get current page from the URL
	
	var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
		
	// An array representing each menu option
	
	var menuItems = new Array('red','green','purple','orange','darkblue','blue');
	
	//Initial setup for the main navigation
	//Required in order to apply DOM Animation
	
	for(x=0; x < menuItems.length; x++) {
	
			//We set the background position to x=0 y=1
			
			document.getElementById(menuItems[x]).style.backgroundPosition = "0px 1px";
			
			//Get id in which are red, green, purple, etc... Array variable menuItems
			
			var myObject = document.getElementById(menuItems[x]);
			
			// Call the addEvent Function which is the equivalent of onload
			
			addEvent(myObject, 'mouseover', showMenu);
			addEvent(myObject, 'mouseout', hideMenu);
			
	} // End main menu initial setup
	
	// Little loop that sets as selected the jump menu for the current page
	// May remove this option
	
		var slect=document.getElementById('jump');
			for(i=0; i<slect.options.length; i++) {
				if(slect.options[i].value == sPage){
					slect.options[i].selected = true; 
				}
			}
	// End select 
	
	// Thumbnail
	// Sets default to 0 and invisible
	
	if(document.getElementById("fixedbox")) {
	var thumbnail = document.getElementById("previewThumb");
	document.getElementById("thumbnail").style.width = "0px";
	document.getElementById("thumbnail").style.height = "0px";
	//document.getElementById("thumbnail").style.visibility = "hidden;";
	
	//Call the function shwo/hideThumnail
	
	addEvent(thumbnail, 'mouseover', showThumbnail);
	addEvent(thumbnail, 'mouseout', hideThumbnail);
	}
	
	if(document.getElementById("adPage")) {
	var thumbnail2 = document.getElementById("previewPage");
	document.getElementById("adPage").style.width = "0px";
	document.getElementById("adPage").style.height = "0px";
	
	//Call the function shwo/hideThumnail
	
	addEvent(thumbnail2, 'mouseover', showThumbnail);
	addEvent(thumbnail2, 'mouseout', hideThumbnail);
	}
	
	
	} // End Function
	
	
	
	
//----------------------------------------------------------------------------------------
// Main Menu MouseOver and MouseOut Functions
//----------------------------------------------------------------------------------------

	// Mouse over the main menu
	
	function showMenu(obj) {
	if(obj.target){
		var menuName = obj.target.id;
	}else{
		var menuName = obj.srcElement.id;
	}
		moveElement(menuName, -30);
	}
	
	// Mouse out main menu
	
	function hideMenu(obj) {
	if(obj.target){
		var menuName = obj.target.id;
	}else{
		var menuName = obj.srcElement.id;
	}
		moveElement(menuName, 2);
	}
	
	
	

//----------------------------------------------------------------------------------------
// Main menu color (background) animation
//----------------------------------------------------------------------------------------
	
	function moveElement(elementId, backgroundPos) {
		//Set speed
		var interval = 10;
		//Get element ID
		var elem = document.getElementById(elementId);
		
		//Clear SetTimeOut
		if (elem.movement) {
			clearTimeout(elem.movement);
		}
		
		//Get current position of the background
		var currentPosition = elem.style.backgroundPosition;
		
		//We split x and y position value gathered from currentPosition variable
		var temp = new Array();
		var temp = currentPosition.split(' ');
		
		//We convert y value into an integrer 
		var intPosition = parseInt(temp[1]);
		
	
		//Conditions
		if (intPosition == backgroundPos) {
			return true;
		}
	
		if (intPosition < backgroundPos){ 
			intPosition = intPosition + 2;
		}
	
		if (intPosition > backgroundPos){ 
			intPosition = intPosition - 2;
		}
		
		elem.style.backgroundPosition = "0px " + intPosition + "px";
		
		var repeat = "moveElement('"+elementId+"',"+backgroundPos+")";
		elem.movement = setTimeout(repeat,interval);
	}
	
	
	

//----------------------------------------------------------------------------------------
// Thumbnail call to Animation
//----------------------------------------------------------------------------------------

function showThumbnail(obj){
	if(obj.target){
		var menuName = obj.target.id;
	}else{
		var menuName = obj.srcElement.id;
	}
	
	if(menuName == "previewThumb") {
		animThumbnail("thumbnail", 180, 180);
	} else {
		animThumbnail("adPage", 180, 180);
	}
}
	
/*	
	if(obj.target){
		if((obj.target.id == "previewThumb")){
			animThumbnail("thumbnail", 180, 180);
		} else {
			animThumbnail("adPage", 180, 180);
		}
	} 
}*/

function hideThumbnail(obj){
if(obj.target){
		var menuName = obj.target.id;
	}else{
		var menuName = obj.srcElement.id;
	}
	
	if(menuName == "previewThumb") {
		animThumbnail("thumbnail", 0, 0);
	} else {
		animThumbnail("adPage", 0, 0);
	}
}	
	
	/*if((obj.target.id == "previewThumb")){
		animThumbnail("thumbnail", 0, 0);
	} else {
		animThumbnail("adPage", 0, 0);
	}
}*/


//----------------------------------------------------------------------------------------
// Thumbnail Animation
//----------------------------------------------------------------------------------------

function animThumbnail(elementId, elemWidth, elemHeight) {
	
	//Set speed
		var interval = 20;
		//Get element ID
		var elem = document.getElementById(elementId);
		//elem.style.visibility = "visible";
		
		//Clear SetTimeOut
		if (elem.movement) {
			clearTimeout(elem.movement);
		}
		
		//Get current width - integrer
		var widthPosition = parseInt(elem.style.width);
		
		//Get current height - integrer
		var heightPosition = parseInt(elem.style.height);
		
	
		//Conditions
		if ((widthPosition == elemWidth) && (heightPosition == elemHeight)) {
			return true;
		}
	
		if ((widthPosition < elemWidth) && (heightPosition < elemHeight)) { 
			widthPosition = widthPosition + 6;
			heightPosition = heightPosition + 6;
			
			elem.style.width = widthPosition + "px";
			elem.style.height = heightPosition + "px";
		}
	
		if ((widthPosition > elemWidth) && (heightPosition > elemHeight)) { 
			widthPosition = widthPosition - 6;
			heightPosition = heightPosition - 6;
			
			elem.style.width = widthPosition + "px";
			elem.style.height = heightPosition + "px";
		}
		
		var repeat = "animThumbnail('"+elementId+"',"+elemWidth+","+elemHeight+")";
		elem.movement = setTimeout(repeat,interval);

}

