﻿function switchImg(obj,par){
	if(document.getElementById(obj))
		obj=document.getElementById(obj);
	imgName=obj.src;
	imgName=imgName.split("/");
	imgName=imgName[(imgName.length)-1];
	imgPath=obj.src.split(imgName);
	imgPath=imgPath[0];
	imgName=imgName.split(".");
	imgSuffix=imgName[1];
	imgName=imgName[0];
	if(par==1)
		imgName=imgName+"_over."+imgSuffix;
	else{
		imgName=imgName.split("_");
		imgName=imgName[0]+"."+imgSuffix;
	}
	obj.src=imgPath+imgName;
}

function findPosition(obj){
	x=0; y=0; w=0; h=0; var el,temp;
	if(typeof(obj)=="string")
		obj=getE(obj);
	if(obj.offsetParent){
		temp=obj;
		while(temp.offsetParent){
			temp=temp.offsetParent; 
			x+=temp.offsetLeft;
			y+=temp.offsetTop;
		}
	}
	x+=obj.offsetLeft;
	y+=obj.offsetTop;
	w=obj.offsetWidth;
	h=obj.offsetHeight;
	return [x,y,w,h];
}

function extLinks(){ 
	if(!document.getElementsByTagName)
		return; 
	var anchors=document.getElementsByTagName("a"); 
	for(var i=0;i<anchors.length;i++)				
		if(anchors[i].getAttribute("href")&&anchors[i].getAttribute("rel")) 
			anchors[i].target=anchors[i].getAttribute("rel");
}

function bookmark(title,url){
	if(window.sidebar)
		window.sidebar.addPanel(title,url,"");
	else if(window.opera && window.print){
		el=document.createElement('a');
		el.setAttribute('href',url);
		el.setAttribute('title',title);
		el.setAttribute('rel','sidebar');
		el.click();
	}
	else if(document.all)
		window.external.AddFavorite(url,title);
}

function getE(obj){
	return document.getElementById(obj);	
}

function getEe(e){
	return e?e.target:window.event.srcElement;
}

function showE(obj,par){
	if(typeof(obj)=="string")
		obj=getE(obj);
	if(par==1)
		obj.style.display=obj.style.display=="block"?"none":"block";
	else
		obj.style.display="block";	
}

function hideE(obj){
	if(typeof(obj)=="string")
		obj=getE(obj);
	obj.style.display="none";	
}

function isDigit(e){
	e=e||event;
	iCode=(e.keyCode||e.charCode);
	return((iCode>=48&&iCode<=57)||(iCode>=37&&iCode<=40)||iCode==8||iCode==46);
}

function sendMessage(str1,str2,str3){
	tmp="ma" +"ilto:";
	tmp+=str3+"&#";
	tmp+="64;";
	tmp+=str2;
	window.location=tmp+"."+str1;
	return false;
}

function getScrollHeight(){
	h=window.pageYOffset||document.body.scrollTop||document.documentElement.scrollTop;
	return h?h:0;
}

/*  */
var speed=30;
var loop,timer;

function makeObj(obj,nest){
    this.el=getE(obj);
  	this.css=getE(obj).style;
	this.scrollHeight=this.el.offsetHeight;
	this.clipHeight=this.el.offsetHeight;
	this.scrollWidth=this.el.offsetWidth;
	this.clipWidth=this.el.offsetWidth;
	this.down=goDown;
	this.up=goUp;
	this.left=goLeft;
	this.right=goRight;
	this.moveIt=moveIt;
	this.x=0;
	this.y=0;
    this.obj=obj+"Object"
    eval(this.obj+"=this");
    return this;
}

var px=window.opera?"":"px";

function moveIt(x,y){
	this.x=x;
	this.y=y;
	this.css.left=this.x+px;
	this.css.top=this.y+px;
}

function goDown(move){
	if(this.y>-this.scrollHeight+oContV.clipHeight){
		this.moveIt(0,this.y-move);
		if(loop)
			setTimeout(this.obj+".down("+move+")",speed);
	}
}

function goUp(move){
	if(this.y<0){
		this.moveIt(0,this.y-move);
		if(loop)
			setTimeout(this.obj+".up("+move+")",speed);
	}
}

function goRight(move){
	if(this.x>-this.scrollWidth+oCont.clipWidth){
		this.moveIt(this.x-move,0);
		if(loop)
			setTimeout(this.obj+".right("+move+")",speed);
	}
}

function goLeft(move){
	if(this.x<0){
		this.moveIt(this.x-move,0);
		if(loop)
			setTimeout(this.obj+".left("+move+")",speed);
	}
}

function scroll(speed,dir){
	if(scrolltextLoaded){
		loop=true;
		if(dir=="h"){
			if(speed>0)
				oScroll.right(speed);
			else 
				oScroll.left(speed);
		}
		else{
			if(speed>0)
				oScrollV.down(speed);
			else 
				oScrollV.up(speed);
		}
	}
}

function noScroll(){
	loop=false;
	if(timer)
		clearTimeout(timer);
}

function onWheel(){
	if(event.wheelDelta>=120){
		scroll(-18,"v");
		noScroll();
	}
	else if(event.wheelDelta<=-120){
		scroll(18,"v");
		noScroll();
	}
}

var scrolltextLoaded=false;
function scrolltextInit(){
	oCont=new makeObj("gallery_scroll");
	oScroll=new makeObj("gallery_scroll_content","gallery_scroll");
	
	oContV=new makeObj("content_box");
	oScrollV=new makeObj("content","content_box");
	
	if(oScrollV.scrollHeight>310){
		showE("arrow_up");	
		showE("arrow_down");
	}
	
	scrolltextLoaded=true;
}

document.onmousewheel=function(){if(getE("arrow_up"))onWheel();}

var wm=null;

onload=function(){
	menu_onload();
	extLinks();
	if(wm)webmin_init();
	if(getE("wm_search")){
		getE("wm_search").onfocus=function(){
			if(this.value==this.title)
				this.value='';
		}
		getE("wm_search").onblur=function(){
			if(this.value=='')
				this.value=this.title;
		}
	}		
	scrolltextInit();
};
