// JavaScript Document
	
function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 200, millisec);
	} else {
		opacity(id, 200, 0, millisec);
	}
}

function blendimage(imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	changeOpac(0, imageid);

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}


function centerImage(imgObj){
		//alert(imgObj.height + " x " + imgObj.width);
		hOffset = ((440 - imgObj.height)/2) + 4;
		imgObj.style.top = hOffset + "px";
		wOffset = ((440 - imgObj.width)/2) + 13;
		imgObj.style.left = wOffset + "px";
}

function switchImg()
{
	
	// Comment out if the slideshow is to be cont.
	if(imgFlag==imgLength-1){ setTimeout('location.href="news.php"',4000);}
	
	imgFG = document.getElementById("M_IMG");
	
	changeOpac(0, "M_IMG");
	
	imgFG.src =  imgArray[ssArray[imgFlag]].src;
	imgFG.width =  imgArray[ssArray[imgFlag]].width;
	imgFG.height =  imgArray[ssArray[imgFlag]].height;
	
	centerImage(imgFG);
	
	imgFlag = (imgFlag==imgLength-1)? 0 : imgFlag + 1;
	
	blendimage('M_IMG', imgFG.src,2000);
	
	setTimeout("switchImg()",6000);

}
	
	function jumpToPage(){
	
	setTimeout('location.href="port.php"',2000);
	}
	
	function changeImg(obj)
	{
		
		//changeOpac(0, "M_IMG");
		
		imgObj = document.getElementById("M_IMG");
		
		imgObj.src = imgArray[obj].src;
		imgObj.width = imgArray[obj].width;
		imgObj.height = imgArray[obj].height;
		centerImage(imgObj);
		//blendimage('M_IMG', imgObj.src ,2000);
		
		
		
	}
	
		function ini(){
			
			tn = document.getElementById("IMG_TN");
			links = tn.getElementsByTagName("a");
			
				for(o=0;o<links.length;o++){
					
						links[o].onclick = function(){
						return changeImg(this.id);}
				}
				
				changeOpac(0, "M_IMG");
				imgFG = document.getElementById("M_IMG");
				centerImage(imgFG);
				//alert(location.pathname);
				( location.pathname==="/slideShow.php" ) ? switchImg() : loadFistImage() ;
	}
	
	function loadFistImage(){
		
		
		/*alert(imgArray[ssArray[0]].src);*/
		imgFI = document.getElementById("M_IMG");
	
	changeOpac(0, "M_IMG");
	
	imgFI.src =  imgArray[ssArray[0]].src;
	imgFI.width =  imgArray[ssArray[0]].width;
	imgFI.height =  imgArray[ssArray[0]].height;
	centerImage(imgFI);
	
	blendimage('M_IMG', imgFI.src,2000);	
	}
	
	window.onload = ini;
