////////////////
// basic vars //
////////////////
//_dom=document.all?3:(document.getElementById?1:(document.layers?2:0));
var sw = screen.width;
var sh = screen.height;
var sx = screen.availWidth;
var sy = screen.availHeight;
// browser
var IE = (navigator.appName.toLowerCase().indexOf("microsoft") != -1);//(document.all) ? true : false;
var NS  = (navigator.appName.toLowerCase().indexOf("netscape") != -1);
var NS4 = (NS && parseInt(navigator.appVersion.toString())==4);
var NS6 = (NS && parseInt(navigator.appVersion.toString())==5);
// platform
var WIN = (navigator.platform.toLowerCase().indexOf("win") != -1);
var MAC = (navigator.platform.toLowerCase().indexOf("mac") != -1);
var browserVer = parseFloat(IE ? navigator.appVersion.substring(navigator.appVersion.toLowerCase().indexOf("msie") + 4) : navigator.appVersion);
//


////////////////
// blink
function blink(bBnk) {
	viewlayer("blink",bBnk);
	if (bBnk) setTimeout('blink(false)',1400);
	else setTimeout('blink(true)',200);
}

////////////////
// what page //
//////////////
//var myUrl = document.location.href;
//var myPge = '';
//for (i=myUrl.length; i>0; i--) {
//	myChr = myUrl.substring(i-1,i);
//	if (myChr!='/')	{
//		myPge = myChr+myPge;
//	} else {
//		break;
//	}
//}


////////////////
// sound functions
function notSnd() {
	if (document.Mediaplayer.playState==2) {
		document.Mediaplayer.stop();
	} else {
		document.Mediaplayer.play();
	}
}

////////////////
// show image
var cImg = 0;
function showImg(sUrl,sNam,sCom) {
	cImg = new Image(); 
	cImg.src = sUrl;
	setTimeout('checkImg()',100);
}
function checkImg() {
	if (cImg!=0) {
		if (cImg.complete)	{
			cBox = document.getElementById("imgbox");
			cBox.style.backgroundImage = "url("+cImg.src+")";
			cBox.style.width =  cImg.width+"px";
			cBox.style.height = cImg.height+"px";
			cBox.style.marginLeft = -5-cImg.width/2+"px";
			cBox.style.top = (mouseY-cImg.height/2)+"px";
			//
			cHtl = document.getElementById("cimgtl");
			cHtl.style.marginLeft = (-cImg.width/2-19)+"px";
			cHtl.style.top = (-19)+"px";
			cHtl = document.getElementById("cimgtr");
			cHtl.style.marginLeft = (cImg.width/2-16)+"px";
			cHtl.style.top = (-19)+"px";
			cHbr = document.getElementById("cimgbl");
			cHbr.style.marginLeft = (-cImg.width/2-19)+"px";
			cHbr.style.top = (cImg.height-12)+"px";
			cHbr = document.getElementById("cimgbr");
			cHbr.style.marginLeft = (cImg.width/2-16)+"px";
			cHbr.style.top = (cImg.height-12)+"px";
		} else {
			setTimeout('checkImg()',100);
		}
	}
}
function hideImg() {
	cBox = document.getElementById("imgbox");
	cBox.style.width =  "0px";
	cBox.style.height = "0px";
	cBox.style.top = "-100px";
	cHtl = document.getElementById("cimgtl");
	cHtl.style.top = "-100px";
	cHtl = document.getElementById("cimgtr");
	cHtl.style.top = "-100px";
	cHbr = document.getElementById("cimgbl");
	cHbr.style.top = "-100px";
	cHbr = document.getElementById("cimgbr");
	cHbr.style.top = "-100px";
}

////////////////
// switch image functions
function bodybg() {
	sImage = "url(eye/bg/"+ lBgImgs[Math.floor(Math.random()*lBgImgs.length)] +")";
	document.getElementById("body").style.backgroundImage = sImage;
	defaultStatus = sImage;
}
function slidebg(sImage) {
	if (sImage==null) {
		sImage = "url(eye/slides/"+ lBgSlide[Math.floor(Math.random()*lBgSlide.length)] +")";
	}
	document.getElementById("prev").style.backgroundImage = sImage;
	defaultStatus = sImage;
}

// check page
var myCk = getCookie('sjeiti');
function correctPage() {
	if (myCk==null) {
		myCk = "blg";
	}
	showtxt(myCk);
}

// show content text function
function showtxt(id) {
	setCookie("sjeiti", id);
	if (document.getElementById(id)!=null) {
		zeElm = document.getElementById(id);
		zeElm.style.display = "block";
		for (var i=0;i<document.getElementById("content").childNodes.length;i++) {
			myElm = document.getElementById("content").childNodes[i];
			if (myElm.nodeName=="DIV") {
				if (myElm!=zeElm&&myElm.style.display!="none") {
					myElm.style.display = "none";
				}
			}
		}
	}
}



////////////////////////////////////
// moves window relative to sw/sh //
////////////////////////////////////
function moveSizeTo(x,y,w,h) {
	self.moveTo(x*sw/100,y*sh/100)
	self.resizeTo(w*sw/100,h*sh/100)
}



//////////////
// bookmark //
//////////////
var url="http://www.sjeiti.com/"
var title="Sjeiti"
function bookmark() {
	window.external.AddFavorite(url,title);
}



/////////////////////////
// opens popup windows //
/////////////////////////
var popje
function openPopup(nurl, name, x, y, w, h) {
	myW = (w*sw/100) -10
	myH = (h*sh/100) -25
	var popje = window.open ( nurl, name,'width='+myW+',height='+myH+',toolbar=0,status=0,scrollbars=no, resizable=1');
	popje.moveTo(x*sw/100,y*sh/100)
	window.focus();
	popje.focus();
}
function closePop() {
	if (popje && popje.open && !popje.closed) {
		popje.close();
	}
}



////////////////////////
// breaks from frames //
////////////////////////
function breakFrame() {
	if (top.frames.length!=1) {
		if (top.location!='index.php') {
			top.location='index.php';
			//top.location='index.html?'+self.document.location;
		}
	}
}


////////////////////////////
// turns layers on or off //
////////////////////////////
function viewlayer(sId,onoff) {
	if (document.getElementById(sId)!=null) {
		myLyr = document.getElementById(sId);
		if (onoff==1) {
			myLyr.style.visibility = 'visible';
		} else {
			myLyr.style.visibility = 'hidden';
		}
	}
}


/////////////////////////////
// gets the mouse location //
/////////////////////////////
var mouseX = 0;
var mouseY = 0;
function getmouseXY(e) {
	if (IE) {
		mouseX = window.event.clientX + document.documentElement.scrollLeft;
		mouseY = window.event.clientY + document.documentElement.scrollTop;
	} else {
		mouseX = e.pageX;//ev.pageX;
		mouseY = e.pageY;//ev.pageY;
	} 
	if (mouseX < 0) {mouseX = 0}
	if (mouseY < 0) {mouseY = 0}
}

/////////////////////
// mo more errors //
///////////////////
if (1==2) {
	window.onerror = stopErrors;
}
function stopErrors() {
	defaultStatus = "";
	return true;
}

////////////////
// setCookie //
//////////////
// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "s") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

////////////////
// getCookie //
//////////////
// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin==-1) {
		begin = dc.indexOf(prefix);
		if (begin!=0) return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}