var menuid = undefined;
var submenuid = undefined;

//go over menu-item
function menuover(obj, id, sel, selsub){
	//change  menu (hide (sub)menu if active)
	menuchange(sel);
	
	//show menu
	document.getElementById('menu-left-' + id).style.backgroundPosition = '0px 0px';
	document.getElementById('menu-item-' + id).style.backgroundPosition = '0px 0px';
	document.getElementById('menu-right-' + id).style.backgroundPosition = '0px 0px';
	
	//show submenu if exists
	objsubitem = document.getElementById('submenus-' + id);
	if(objsubitem != undefined){
		document.getElementById('submenu-left').style.display = 'block';
		objsubitem.style.display = 'block';
		document.getElementById('submenu-right').style.display = 'block';
		submenuid = id;
	}
	menuid = id;
}
//change menu-item
function menuchange(sel){
	//hide background if exists and isn't selected menu-item
	if(menuid != undefined && menuid != sel){
		document.getElementById('menu-left-' + menuid).style.backgroundPosition = '0px 20px';
		document.getElementById('menu-item-' + menuid).style.backgroundPosition = '0px 20px';
		document.getElementById('menu-right-' + menuid).style.backgroundPosition = '0px 20px';
	}
	//hide submenu if exists
	if(submenuid != undefined){
		document.getElementById('submenu-left').style.display = 'none';
		document.getElementById('submenus-' + menuid).style.display = 'none';
		document.getElementById('submenu-right').style.display = 'none';
		submenuid = undefined;
	}
	//if selected menu-item's submenu exists, hide it
	obj = document.getElementById('submenus-' + sel);
	if(obj != undefined){
		document.getElementById('submenu-left').style.display = 'none';
		document.getElementById('submenus-' + sel).style.display = 'none';
		document.getElementById('submenu-right').style.display = 'none';
	}
}
//go out total menu
function menuout(sel){
	//hide background if exists and isn't selected menu-item
	if(menuid != undefined && menuid != sel){
		document.getElementById('menu-left-' + menuid).style.backgroundPosition = '0px 20px';
		document.getElementById('menu-item-' + menuid).style.backgroundPosition = '0px 20px';
		document.getElementById('menu-right-' + menuid).style.backgroundPosition = '0px 20px';
	}
	//hide submenu if exists
	if(submenuid != undefined){
		document.getElementById('submenu-left').style.display = 'none';
		document.getElementById('submenus-' + menuid).style.display = 'none';
		document.getElementById('submenu-right').style.display = 'none';
		submenuid = undefined;
	}
	//show submenu from selected menu-item
	obj = document.getElementById('submenus-' + sel);
	if(obj != undefined){
		document.getElementById('submenu-left').style.display = 'block';
		document.getElementById('submenus-' + sel).style.display = 'block';
		document.getElementById('submenu-right').style.display = 'block';
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function placefooter(){
	objs = document.getElementsByTagName('div');
	total = 0;
	for(var i = 0; i < objs.length; i++){
		objpos = findPos(objs[i]);
		objheight = objs[i].offsetHeight;
		subtotal = objpos[1] + objheight;
		if(subtotal > total){
			total = subtotal;
		}
	}
	document.getElementById('footer').style.top = total + 'px';
}

function showimg(url, width, height){
	objs = document.getElementsByTagName('div');
	
	total_height = 0;
	total_width = 0;

	if(typeof(window.innerWidth) == 'number'){
		total_width = window.innerWidth-20;
		total_height = window.innerHeight;
	}
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
		total_width = document.documentElement.clientWidth;
		total_height = document.documentElement.clientHeight;
	}
	
	for(var i = 0; i < objs.length; i++){
		objpos = findPos(objs[i]);
		objheight = objs[i].offsetHeight;
		subtotal_height = objpos[1] + objheight;
		objwidth = objs[i].offsetWidth;
		subtotal_width = objpos[0] + objwidth;
		if(subtotal_height > total_height){
			total_height = subtotal_height;
		}
		if(subtotal_width > total_width){
			total_width = subtotal_width;
		}
	}
	
	document.getElementById('foto-overlay').style.width = total_width + 'px';
	document.getElementById('foto-overlay').style.height = total_height + 'px';
	document.getElementById('foto-overlay').style.display = 'block';
	document.getElementById('foto-overlay-image').style.marginTop = ((total_height/2) - (height/2)) + 'px';
	document.getElementById('foto-overlay-image').style.marginLeft = ((total_width/2) - (width/2)) + 'px'; 
	document.getElementById('foto-overlay-image').innerHTML = '<img src="'+url+'" width="'+width+'" />';
	document.getElementById('foto-overlay-panel').style.top = ((total_height/2) + (height/2) - 15) + 'px';
	document.getElementById('foto-overlay-panel').style.left = ((total_width/2) + (width/2) - 333) + 'px'; 
	document.getElementById('foto-overlay-panel').style.display = 'block';
	filename = url.split("/");
	filename.reverse(); 
	document.getElementById('foto-overlay-panel').innerHTML = filename[0];
}

function hideimg(){
	document.getElementById('foto-overlay').style.display = 'none';
	document.getElementById('foto-overlay-image').innerHTML = '';
	document.getElementById('foto-overlay-panel').style.display = 'none';
}

function gotourl(url){
	document.location=url;
}

function checkInput(obj, val){
	if(obj.value == val){
		obj.value = '';
		obj.onblur = function() { blurInput(this, val); };
	}
}

function blurInput(obj, val){
	if(obj.value == ''){
		obj.value = val;
	}
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function video_mouseover(obj, itemnumb){
	obj.className = 'special';
	document.getElementById('video-item-image-overlay-'+itemnumb).className = 'video-item-image-overlay special';
	
	obj.onmouseout = function() { video_mouseout(this, itemnumb); };
}

function video_mouseout(obj, itemnumb){
	obj.className = '';
	document.getElementById('video-item-image-overlay-'+itemnumb).className = 'video-item-image-overlay';
}
