function $(el) {return document.getElementById(el)}

function ShowImageWindow(picname, width, height, title) {
	width += 30
	height += 30    
	var params='toolbar=no,height='+height+',width='+width+',location=no,scrollbars=no,status=no,menubar=no,resizable=yes';
	picwin=window.open("","_blank",params);
	picwin.document.open();
	picwin.document.write('<html><title>Berlingtoun</title>');
	picwin.document.write('<body>');
	picwin.document.write('<table><tr><td align="center" valign="middle"><img style="cursor:hand;cursor:pointer" src="'+picname+'" border="0"/ onclick="window.close();opener.focus()">');
	picwin.document.write('</td></tr></table></body></html>');
	picwin.document.close();
}

function move() {
	var obj = $('containerMain')
	obj.style.background = "url(/imgs/bg.jpg)"
	var pWidth = 30
	var pHeight = 40
	obj.style.backgroundPosition = "0px 0px"
	moving(obj, parseInt(getViewport()[0]/100*pWidth), parseInt(getViewport()[1]/100*pHeight))
	//alert(obj.style.background)
}

function getViewport() {
	if (self.innerWidth)
	{
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}
	return [frameWidth, frameHeight]
}

function moving(obj, dWidth, dHeight) {
	var p1 = (dWidth-parseInt(obj.style.backgroundPosition.match(/(\d+)/)[0]))*0.3
	var p2 = (dHeight-parseInt(obj.style.backgroundPosition.match(/(\d+)/)[1]))*0.3
	if (p1<5) p1=5
	if (p2<5) p2=5
	var w = parseInt(obj.style.backgroundPosition.match(/(\d+)/)[0]) + p1
	var h = parseInt(obj.style.backgroundPosition.match(/(\d+)/)[1]) + p2
	changePos(obj, w, h)
	if (w<dWidth && h<dWidth)
		setTimeout('moving(document.getElementById("'+obj.id+'"), "'+dWidth+'", "'+dHeight+'")', 50)
	else return
}

function changePos(obj, w, h) {
	obj.style.backgroundPosition = w + "px " + h + "px"
}
