
imageSize=100 // size larger image is shown at in %
isCentered=0 // set to 1 only if centering in browser window

isThumbs=1 // 0 = no 1 = yes, if you are not showing thumbnails set to zero


autoRun=1 // 0 = no 1 = yes
autoRunTime = 3 // seconds

var preload=[]
for(var i=0;i<imageArr.length;i++){
	preload[i]=new Image()
	preload[i].src=imageArr[i];
	preload[i].alt=metinArr[i];
}

function initIG8(){
	opac=0
	aniTimer=""
	running=0
	fadeStep=2
	stepNum=50
	lastNum=null
	faderTimer=""
	autoCount=0
	autoTimer=""

	if(isThumbs==1){
		g8Thumbs=document.getElementsByName("ig8tn")
		for(var i=0;i<g8Thumbs.length;i++){
			g8Thumbs[i].i=i;
			g8Thumbs[i].onclick=function(){clearTimeout(autoTimer);nextG8Pic(this.i);}
			g8Thumbs[i].onmousedown=function(){this.className="g8mousedown";}
			g8Thumbs[i].onmouseup=function(){this.className="g8mouseup";}
			g8Thumbs[i].className="g8mouseup"; 
		}
	}
	g8Box=document.getElementById("g8box")
	g8Text=document.getElementById("g8text")
	g8Img=document.getElementById("g8img")
	if(g8Box.parentNode.nodeName=="TD"){
		moz=document.getElementById&&!document.all
		tdCell=g8Box.parentNode
		tdLeftPos = tdCell.offsetLeft
		tdTopPos = tdCell.offsetTop
		parentEl = tdCell.offsetParent
		while (parentEl != null){
			if(parentEl.tagName == "TD"){
				if(!moz){
					tdLeftPos += parentEl.clientLeft;
					tdTopPos += parentEl.clientTop;
				}else{
					if(parentEl.tagName == "TABLE"){
						nParBorder = parseInt(parentEl.border);
						if(nParBorder > 0){
							nLeftPos += nParBorder;
						}
					}
				}
			}
			tdLeftPos += parentEl.offsetLeft;
			tdTopPos += parentEl.offsetTop;
			parentEl = parentEl.offsetParent;
		}
		tdCenterX=g8Box.parentNode.offsetWidth/2;
		tdCenterY=g8Box.parentNode.offsetHeight/2;
	}else{
		tdCenterX=0;
		tdCenterY=0;
	}

	border=0;
	if(document.defaultView && document.defaultView.getComputedStyle){
		border=parseInt(document.defaultView.getComputedStyle(g8Box, '').getPropertyValue("border-left-width"));
	}
	documentBody=(document.compatMode=="CSS1Compat"?document.documentElement:document.body);
	if(isCentered==0){
		defaultLeft=tdLeftPos+tdCenterX-border;
		defaultTop=tdTopPos+tdCenterY-border;
	}else{
		defaultLeft=documentBody.clientWidth/2;
		defaultTop=documentBody.clientHeight/2;
	}
	g8Box.style.left=parseInt(defaultLeft)+"px";
	g8Box.style.top=parseInt(defaultTop)+"px";

	if(autoRun==1){
		autoRunner();
	}
}

function nextG8Pic(num){
	if(lastNum==num||running==1){return}
	closing=false;
	running=1;
	autoCount=num;
	
	currentLeft=g8Box.offsetLeft;
	currentTop=g8Box.offsetTop;
	currentWidth=g8Box.offsetWidth-(border*2);
	currentHeight=g8Box.offsetHeight-(border*2);

	if(num==-1){
		newWidth=wStep;
		newHeight=hStep;
		wDirection="in";
		hDirection="in";
		closing=true;
	}else{
		nextPicWidth=preload[num].width; // images full width
		nextPicHeight=preload[num].height; // images full height
		newWidth=nextPicWidth/100*imageSize; // images displayed width
		newHeight=nextPicHeight/100*imageSize; // images displayed height
	}

	if(newWidth>currentWidth ){
		wStep=(newWidth-currentWidth)/stepNum;
	}else{
		if((newWidth ) < currentWidth){ wStep=(currentWidth-newWidth)/stepNum;} else wStep = 0;
	}
	if(newHeight>currentHeight){
		hStep=(newHeight-currentHeight)/stepNum;
	}else{
		if((newHeight)<currentHeight){ hStep=(currentHeight-newHeight)/stepNum;} else hStep = 0;
	}
	g8Box.style.visibility="visible";
	g8Text.style.visibility="visible";
	wDone=false;
	hDone=false;
	lastNum=num;
	fading="out";
	if(resimAlt[num]){
		g8Img.alt=resimAlt[num]; 
		g8Text.innerHTML = metinArr[num];
	}else{
		g8Img.alt=''; 
		g8Text.innerHTML = '';
	}

	if(((hStep <0.1)&&(hStep >(0-0.1))) && ((wStep <0.1)&&(wStep >(0-0.1))) ){
		fading="out";
		opac = 100;
		faderTimer=setTimeout("fadeG8Pic()",5);
		setTimeout("fadeInG8(" + num + ")",1000);
		return
	}

	fadeG8Pic();
	animateG8(num);
}

function fadeInG8(num){
	g8Img.src=preload[num].src; 
	faderTimer=setTimeout("fadeG8Pic()",5);
	fading="in";
	fadeG8Pic();
}


function animateG8(num){
	if(parseInt(newWidth)>parseInt(currentWidth)){
		currentWidth+=wStep;
		currentLeft-=wStep/2;
		wDirection="out";
	}else{
		if(parseInt(newWidth)<parseInt(currentWidth)){
			currentWidth-=wStep;
			currentLeft+=wStep/2;
			wDirection="in";
		}else
			wDone=true;
	}
	if(parseInt(newHeight) > parseInt(currentHeight)){
		currentHeight+=hStep;
		currentTop-=hStep/2;
		hDirection="out";
	}else{
		if(parseInt(newHeight) < parseInt(currentHeight)){
			currentHeight-=hStep;
			currentTop+=hStep/2;
			hDirection="in";
		}else
			hDone=true;
	}
	
	//alert(wStep + '\n' + hStep)
	
	if(aniTimer)clearTimeout(aniTimer);
	aniTimer=setTimeout("animateG8("+num+")",10);
	if(wDirection=="out"&&parseInt(currentWidth)>=parseInt(newWidth-wStep/2)){wDone=true;}
	if(wDirection=="in"&&parseInt(currentWidth)<=parseInt(newWidth+wStep/2)){wDone=true;}
	if(hDirection=="out"&&parseInt(currentHeight)>=parseInt(newHeight-hStep/2)){hDone=true;}
	if(hDirection=="in"&&parseInt(currentHeight)<=parseInt(newHeight+hStep/2)){hDone=true;}
	if(wDone&&hDone){
		clearTimeout(aniTimer);
		if(closing){
			g8Box.style.visibility="hidden";
			g8Text.style.visibility="hidden";
			currentWidth=1;
			currentHeight=1;
			currentLeft=defaultLeft;
			currentTop=defaultTop;
			running=0;
		}else{
			fading="in";
			fadeG8Pic();
			if(num!=-1){g8Img.src=preload[num].src;}
			currentWidth=newWidth;
			currentHeight=newHeight;
			currentLeft=defaultLeft-(newWidth/2);
			currentTop=defaultTop-(newHeight/2);
		}
	}
	g8Box.style.left=parseInt(currentLeft)+"px";
	g8Box.style.top=parseInt(currentTop)+"px";
	g8Box.style.width=parseInt(currentWidth)+"px";
	g8Box.style.height=parseInt(currentHeight)+"px";
}

function fadeG8Pic(){
	clearTimeout(faderTimer);
	faderTimer=setTimeout("fadeG8Pic()",5);
	if(fading=="out"){
		opac-= fadeStep;
		if(opac<5){
			opac=5;
			clearTimeout(faderTimer);
		}
	}else{
		opac+= fadeStep;
		if(opac>100){
			clearTimeout(faderTimer);
			opac=100;
			running=0;
		}
	}
	if(g8Img.filters){g8Img.filters.alpha.Opacity=opac;}else{g8Img.style.opacity=(opac/100)-0.001;}
}

function autoRunner(){
	nextG8Pic(autoCount);
	if(autoCount<imageArr.length-1){autoCount++;}else{autoCount=0;}
	autoTimer=setTimeout("autoRunner()",autoRunTime*1000);
}
