/* menu */
kMenu=function() {
	var container=null;
	var ulMenu=null;
	var home=null;
	var pointer=null;
	var easeStep=0;
	var easeFrom=0;
	var easeTo=0;
	var timer=null;

	this.setContainer=function(id) {
		container=document.getElementById(id);
		}
	this.init=function() {
		ulMenu=container.getElementsByTagName('UL')[0];
		hideRealAncestors();
		hideChilds(ulMenu);
		mouseHandlers(ulMenu);
		for(var i=0;ulMenu.childNodes[i];i++) {
			elm=ulMenu.childNodes[i];
			if(elm.tagName=='LI'&&(elm.className=='sel'||elm.className=='ancestor')) home=elm;
			}
		pointer=document.createElement('IMG');
		pointer.src=TEMPLATEDIR+'img/mpointer.png';
		pointer.id='menupointer';
		pointer.style.left='0px';
		container.appendChild(pointer);
		if(home) pointer.style.left=home.offsetLeft+(home.offsetWidth-pointer.width)/2+'px';
		kAddEvent(window,"onload",function() { if(home) pointer.style.left=home.offsetLeft+(home.offsetWidth-pointer.width)/2+'px'; });
		}
	function goHere() {
		if(timer) clearInterval(timer);
		moveTo(this.offsetLeft+(this.offsetWidth-pointer.width)/2);
		}
	function goHome() {
		if(timer) clearInterval(timer);
		if(home) moveTo(home.offsetLeft+(home.offsetWidth-pointer.width)/2);
		}
	function moveTo(to) {
		easeStep=0;
		easeFrom=parseInt(pointer.style.left);
		easeTo=to;
		timer=setInterval(moveNextStep,20);
		}
	function moveNextStep() {
		var newpos=easeFrom+easeInOut(easeTo-easeFrom,10,easeStep,5);
		pointer.style.left=newpos+'px';
		easeStep++;
		if(easeStep>10) {
			clearInterval(timer);
			easeStep=0;
			}
		}
	function mouseHandlers(elm) {
		for(var i=0;elm.getElementsByTagName('LI')[i];i++) {
			elm.getElementsByTagName('LI')[i].getElementsByTagName('A')[0].onmouseover=showChilds;
			elm.getElementsByTagName('LI')[i].getElementsByTagName('A')[0].onmouseout=mouseOutHandler;
			if(elm.getElementsByTagName('LI')[i].getElementsByTagName('UL').length>0) {
				mouseHandlers(elm.getElementsByTagName('LI')[i].getElementsByTagName('UL')[0]);
				}
			elm.getElementsByTagName('LI')[i].onmouseover=goHere;
			elm.getElementsByTagName('LI')[i].onmouseout=goHome;
			}
		}
	function mouseOutHandler() {
		elm=this.parentNode;
		ancestorOff(elm);
		setTimeout(function() { hideChilds(ulMenu); },100);
		}
	function hideChilds(elm) {
		if(elm!=ulMenu&&elm.parentNode.getElementsByTagName('A')[0].className.indexOf('ancestmp')==-1) elm.style.display="none";
		for(var i=0;elm.getElementsByTagName('UL')[i];i++) {
			hideChilds(elm.getElementsByTagName('UL')[i]);
			}
		//if(!mouseIsOver()) showRealAncestors();
		}
	function showChilds() {
		elm=this.parentNode;
		for(var i=0;elm.childNodes[i];i++) {
			if(elm.childNodes[i].tagName.toLowerCase()=='ul') elm.childNodes[i].style.display="block";
			}
		ancestorOn(elm);
		if(!searchForRealAncestors(this)) hideRealAncestors();
		else showRealAncestors();
		}
	function searchForRealAncestors(elm) {
		if(elm.className.indexOf('ancestor')>-1) return true;
		for(;elm.parentNode!=container;elm=elm.parentNode) {
			if(elm.className.indexOf('ancestor')>-1) {
				return true;
				}
			}
		return false
		}
	function ancestorOn(elm) {
		if(elm.tagName.toLowerCase()=='li') {
			elm.getElementsByTagName('A')[0].setAttribute('classBkup',elm.getElementsByTagName('A')[0].className);
			if(elm.getElementsByTagName('A')[0].className.indexOf('ancestmp')==-1) elm.getElementsByTagName('A')[0].className+=" ancestmp";
			}
		if(elm.parentNode!=container) ancestorOn(elm.parentNode);
		}
	function ancestorOff(elm) {
		elm.childNodes[0].className=elm.childNodes[0].getAttribute('classBkup');
		if(elm.parentNode!=container) ancestorOff(elm.parentNode);
		}
	function mouseIsOver() {
		for(var i=0;ulMenu.getElementsByTagName('A')[i];i++) {
			if(ulMenu.getElementsByTagName('A')[i].className.indexOf('ancestmp')!=-1) return true;
			}
		return false;
		}
	function showRealAncestors() {
		for(var i=0;ulMenu.getElementsByTagName('A')[i];i++) {
			if(ulMenu.getElementsByTagName('A')[i].className.indexOf('ancestor')!=-1||ulMenu.getElementsByTagName('A')[i].className.indexOf('sel')!=-1) {
				ulMenu.getElementsByTagName('A')[i].parentNode.parentNode.style.display="block";
				}
			}
		}
	function hideRealAncestors() {
		for(var i=0;ulMenu.getElementsByTagName('A')[i];i++) {
			if(ulMenu.getElementsByTagName('A')[i].parentNode.parentNode!=ulMenu&&(ulMenu.getElementsByTagName('A')[i].className.indexOf('ancestor')!=-1||ulMenu.getElementsByTagName('A')[i].className.indexOf('sel')!=-1)) {
				ulMenu.getElementsByTagName('A')[i].parentNode.parentNode.style.display="none";
				}
			}
		}
	}
function menuInit(id) {
	var kMainMenu=new kMenu;
	kMainMenu.setContainer(id);
	kMainMenu.init();
	}

function removePlaceholder(inp) {
	if(!inp.getAttribute("placeholder")) inp.setAttribute("placeholder",inp.value);
	if(inp.value==inp.getAttribute("placeholder")) {
		inp.value="";
		inp.style.color="#000";
		}
	}
function setPlaceholder(inp) {
	if(inp.value=="") {
		inp.value=inp.getAttribute("placeholder");
		inp.style.color="#aaa";
		}
	}

function easeInOut(value,totalSteps,actualStep,pwr) { 
	totalSteps=Math.max(totalSteps,actualStep,1);
	var p1=Math.ceil(totalSteps/2);
	var p2=totalSteps-p1;
	var p1a=Math.min(actualStep,p1);
	var p2a=actualStep-p1a;
	var step=Math.pow(((1/p1)*p1a),pwr)*(value/2);
	if(p2a>0) step+=value/2-(Math.pow(((1/p2)*(p2-p2a)),pwr)*(value/2));
	return Math.ceil(step);
	}
	
kVideoModule=function(obj) {
	var container=obj;
	var thumbs=container.getElementsByTagName('DIV')[1];
	var phg=container.getElementsByTagName('DIV')[2];
	var timer=null;
	var stepTot=30;
	var step=0;
	var action='';
	var loaderTimer=null;
	var loader=document.createElement('DIV');
	loader.className='loader';
	loader.style.display='none';
	phg.appendChild(loader);
	var onmouseoverHandler=function() {
		action='open';
		timer=setTimeout(changeHeight,20)
		}
	var onmouseoutHandler=function() {
		action='close';
		timer=setTimeout(changeHeight,20)
		}
	var changeHeight=function() {
		if(action=='close'&&step>0) {
			setTimeout(changeHeight,20);
			step--;
			}
		else if(action=='open'&&step<stepTot) {
			setTimeout(changeHeight,20);
			step++;
			}
		centerPhotogallery();
		container.style.height=(150+easeInOut(150,stepTot,step,5))+'px';
		}
	var centerPhotogallery=function() {
		phg.style.top=-(150-container.offsetHeight/2)+'px';
		}
	var showPhoto=function() {
		phg.getElementsByTagName('IMG')[0].style.visibility='hidden';
		loader.style.display='block';
		phg.getElementsByTagName('IMG')[0].src=this.src.replace("/t_","/");
		phg.getElementsByTagName('IMG')[0].onload=function() {
			phg.getElementsByTagName('IMG')[0].style.visibility='visible';
			clearInterval(loaderTimer);
			loader.style.display='none';
			};
		}
	centerPhotogallery();
	for(var i=0;thumbs.getElementsByTagName('IMG')[i];i++) {
		if(thumbs.getElementsByTagName('IMG')[i].parentNode.tagName!="A") thumbs.getElementsByTagName('IMG')[i].onclick=showPhoto;
		}
	container.onmouseover=onmouseoverHandler;
	container.onmouseout=onmouseoutHandler;
	}
function initVideoModules() {
	for(var c=0;document.getElementById('videoModules').childNodes[c];c++) {
		if(document.getElementById('videoModules').childNodes[c].nodeType==1) {
			var i=arVideoModules.length;
			arVideoModules[i]=new kVideoModule(document.getElementById('videoModules').childNodes[c]);
			}
		}
	}
var arVideoModules=Array();

function displayVideo(dir,w,h,prev) {
	w=parseInt(w);
	if(w>kWindow.clientWidth()-20) {
		h=h*(kWindow.clientWidth()-20)/w;
		w=kWindow.clientWidth()-20;
		}
	if(h>kWindow.clientHeight()-80) {
		w=w*(kWindow.clientHeight()-80)/h;
		h=kWindow.clientHeight()-80;
		}
	kOpenIPopUp(TEMPLATEDIR+'inc/loadVideo.php','&dir='+escape(dir)+'&w='+parseInt(w)+'px&h='+parseInt(h)+'px&prev='+parseInt(prev),w+'px',h+'px');
	}

function kOpenIPopUp(url,vars,w,h) {
	var msg=document.createElement('DIV');
	msg.id='iPopUpWindow';
	msg.style.position='absolute';
	msg.style.width=w;
	msg.style.height=h;
	msg.style.zIndex='100';
	document.body.appendChild(msg);
	msg.style.top=((kWindow.clientHeight()-msg.offsetHeight)/2+kWindow.scrollTop())+'px';
	msg.style.left=(kWindow.clientWidth()-msg.offsetWidth)/2+'px';
	var bkg=document.createElement('DIV');
	bkg.id='iframeWindowBkg';
	bkg.style.height=kWindow.pageHeight()+'px';
	bkg.onclick=kCloseIPopUp;
	document.body.appendChild(bkg);
	var ajax=new kAjax;
	ajax.onSuccess(function(html) { document.getElementById('iPopUpWindow').innerHTML=html; });
	ajax.onFail(function(html) { document.getElementById('iPopUpWindow').innerHTML='Error loading :\\'; });
	ajax.send("post",url,vars);
	}
function kCloseIPopUp() {
	if(document.getElementById('iPopUpWindow')) {
		var msg=document.getElementById('iPopUpWindow');
		msg.parentNode.removeChild(msg);
		}
	if(document.getElementById('iframeWindowBkg')) {
		var bkg=document.getElementById('iframeWindowBkg');
		bkg.parentNode.removeChild(bkg);
		};
	}

