
var ie   = document.all;
var moz  = document.getElementById;


var counter 		= 0;
var isrunning 		= 0;
var imgwidth 		= 600;
var imgheight 		= 383;

var thmbwidth 		= 300;
var thmbheight 		= 191;

var animsteps		= 15;
var animspeed		= 10;

var caption 		= "";
var thumbfilename 	= "";
var imgfilename 	= "";
var positionid		= "";

var previousid		= "";

var imgplacex		=0;
var imgplacey		=0;


function scaleimage() {
	counter++;
	if (isrunning == 0) {
		counter = 0;
	}
	else {
		var widthrange 		= (imgwidth - thmbwidth);
		var heightrange 	= (imgheight - thmbheight);
		var widthadder 		= (widthrange / animsteps);
		var heightadder		= (heightrange / animsteps);
		var animwidth 		= (thmbwidth + (widthadder * counter));
		var animheight 		= (thmbheight + (heightadder * counter));
		var layer 		= "imglayer";
		var imgName 		= eval("document.images." + positionid);
		var layer2		= "kuva";

		var crossobj2		= document.getElementById? document.getElementById(layer2) : eval("document.all." + layer2);
		crossobj2.style.width	= animwidth + "px";
		crossobj2.style.height	= animheight + "px";

		imgPlace 		= getDim(imgName);
		var crossobj		= document.getElementById? document.getElementById(layer) : eval("document.all." + layer);
		crossobj.style.left	= ((imgPlace.x - animwidth)+thmbwidth) + "px";
		crossobj.style.top	= (imgPlace.y) + "px";

		if (counter >= animsteps) {
			crossobj.style.left	= (((imgPlace.x - animwidth)+thmbwidth)-25) + "px";
			crossobj.style.top	= ((imgPlace.y)-15) + "px";


			var htmlstart = '<table border=0 cellspacing=0 cellpadding=0>';
			htmlstart = htmlstart + '<tr><td width=25 height=15><img src="/img/border/top_l.png" width=25 height=15 class="transparent"></td><td background="/img/border/top.png" class="transparent"></td><td width=25 height=15><img src="/img/border/top_r.png"  width=25 height=15 class="transparent"></td></tr>';
			htmlstart = htmlstart + '<tr><td background="/img/border/left.png" class="transparent"></td><td bgcolor="#ffffff">';
		

			var htmlend = '</td><td background="/img/border/right.png" class="transparent"></td></tr>';
			htmlend = htmlend + '<tr><td width=25 height=32><img src="/img/border/bot_l.png" width=25 height=32 class="transparent"></td><td background="/img/border/bot.png" class="transparent"></td><td width=24 height=32><img src="/img/border/bot_r.png" width=25 height=32 class="transparent"></td></tr>';
			htmlend = htmlend + '</table>';
		
		        document.getElementById('imgplacer').innerHTML = htmlstart + "<img src='" + imgfilename + "' width=" + imgwidth + "height=" + imgheight + "><p>" + "<table border=0 cellspacing=0 cellpadding=0 width='" + imgwidth + "'><tr><td align=left>" + caption + "</td><td align=right nowrap><a href=\"#\" style=\"text-decoration:none; color:#888888\">" + langclose + " <img src='/img/ruksi.gif' width=20 height=20 border=0 align=absmiddle></a></td></tr></table>" + htmlend;
			isrunning 	= 0;
			counter 	= 0;
		}
	}
	
	window.setTimeout("scaleimage();", animspeed);
}


function geetDim(el){
        for (var lx=0,ly=0;el!=null;
                lx+=el.offsetLeft,ly+=el.offsetTop,el=el.offsetParent);
        return {x:lx,y:ly}
}


function getDim(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return {x:curleft,y:curtop};
}

function show_layer(id,thumb_url,thumb_width,thumb_height,img_url,img_width,img_height,capt) {
	positionid 		= id;
	imgwidth 		= img_width;
	imgheight 		= img_height;
	thmbwidth 		= thumb_width;
	thmbheight 		= thumb_height;
	caption 		= capt;
	thumbfilename 		= thumb_url;
	imgfilename 		= img_url;
	isrunning 		= 1;
	counter 		= 0;
	var layer 		= "imglayer";
	var imgName 		= eval("document.images." + positionid);
	imgPlace 		= getDim(imgName);
	var crossobj		= document.getElementById? document.getElementById(layer) : eval("document.all." + layer);
	imgplacex		= imgPlace.x;
	imgplacey		= imgPlace.y;
	crossobj.style.left	= (imgPlace.x ) + "px";
	crossobj.style.top	= (imgPlace.y) + "px";

	document.getElementById('imgplacer').innerHTML = "<img src='" + thumbfilename + "' width=" + thmbwidth + "height=" + thmbheight + " name='kuva' id='kuva'>";

	
	
	if (moz) {
		var crossobj=document.getElementById? document.getElementById(layer) : document.all.layer;	
		crossobj.style.visibility='visible';
	}
	else {
		document.all[layer].style.visibility='visible';
	}
	return false;
}

function hide_layer() {
	var layer = "imglayer";
	if (moz) {
		var crossobj=document.getElementById? document.getElementById(layer) : document.all.layer;
		crossobj.style.visibility='hidden';
	}
	else {
		document.all[layer].style.visibility='hidden';
	}
        document.getElementById('imgplacer').innerHTML = "";
	isrunning = 0;
}

