document.write('<link href="css/js.css" rel="stylesheet" type="text/css" media="all" />');
var ie = document.all ?	true:false;
var ie7 = navigator.userAgent.indexOf('MSIE 7')!=-1;
var	nn4	= document.layers ?	true:false;
var _width, _height;
var initiated = false;

function get_scr_res(){
	_width = (nn4) ? window.innerWidth + 4 : document.body.offsetWidth;
	_height = (nn4) ? window.innerHeight + 4 : document.body.offsetHeight;
}

function pageInit() {
	if (!initiated){
		myHome = document.getElementById("home");
		myDivider = document.getElementById("divider");
		myAbout = document.getElementById("logo");
		myCanvas = document.getElementById("canvas");
		myNavigation = document.getElementById("navigation");
		if (myDivider) myDivider.style.display = "none";
		if (myCanvas && myNavigation && myAbout){
			myCanvas.style.left = myNavigation.scrollWidth+20+"px";
			myNavigation.style.top = 90+"px";
		}
		initiated = true;
	}
	get_scr_res();
	if (myHome){
		myHome.style.left = _width/2-130+"px";
		myHome.style.top  = (_height-myHome.scrollHeight)/2-30+"px";// 55 je haluz
	}
	if (myCanvas && myNavigation && myAbout){
		topMargin = _height-myNavigation.scrollHeight-22;
	}
	layerSetup(); // start floating
	if (document.getElementById("hpPod1")) hpSetup(); // start floating
	if (window.pageSpecificInit) pageSpecificInit();
}

window.onload = pageInit;
window.onresize = pageInit;

/************************* float engine ***************************************/
window.onerror = null;
var floaterHeight = 0;
var topMargin = 200;
var leftMargin = 80;
var slideTime = 1200;
var slideTime2 = 1200;
var mainMode;
var alignMode;
var currentXaligned;

function layerObject(id) {
	this.obj = document.getElementById(id).style;
	return this.obj;
}
function layerSetup() {
	floatLyr = new layerObject("navigation");
	mainMode = window.setInterval("main()", 10);
}
function main() {
	if (ie7){
		this.currentY = parseInt(document.getElementById('navigation').style.pixelTop);
		this.scrollTop = document.documentElement.scrollTop;
	} else if (ie){
		this.currentY = parseInt(document.getElementById('navigation').style.pixelTop);
		this.scrollTop = document.body.scrollTop;
	} else{
		this.currentY = parseInt(document.getElementById('navigation').style.top);
		this.scrollTop = window.scrollY;
	}
	mainTrigger();
}
function mainTrigger() {
	var newTargetY = (_height > floaterHeight) ? (this.scrollTop + this.topMargin) : (this.topMargin);
	if (newTargetY>myCanvas.scrollHeight-myNavigation.scrollHeight) newTargetY = myCanvas.scrollHeight-myNavigation.scrollHeight;
	if ( this.currentY != newTargetY ) {
		if ( newTargetY != this.targetY ) {
			this.targetY = newTargetY;
			floatStart();
		}
		animator();
	}
}
function floatStart() {
	var now = new Date();
	this.A = this.targetY - this.currentY;
	this.B = Math.PI / ( 2 * this.slideTime );
	this.C = now.getTime();
	if (Math.abs(this.A) > this._height) {
		this.D = this.A > 0 ? this.targetY - this._height : this.targetY + this._height;
		this.A = this.A > 0 ? this._height : -this._height;
	}
	else {
		this.D = this.currentY;
   }
}
function animator() {
	var now = new Date();
	var newY = this.A * Math.sin( this.B * ( now.getTime() - this.C ) ) + this.D;
	newY = Math.round(newY)
	if (( this.A > 0 && newY > this.currentY ) || ( this.A < 0 && newY < this.currentY )) {
		document.getElementById('navigation').style.top = newY + "px";
	}
}
function openPopup(pageId, myWidth, myHeight){
	myWidth = myWidth+20; var _width = 0; var centered_width = 0; _width = screen.availWidth;
	myHeight = myHeight+20; var _height = 0; var centered_height = 0; _height = screen.availHeight;
	if (_width>myWidth) centered_width = (_width-myWidth)/2;
	if (_height>myHeight) centered_height = (_height-myHeight)/2;
	viewer = window.open("/blog/popup.php?id="+pageId,"viewer","top="+centered_height+",left="+centered_width+",status=yes,scrollbars=yes,menubar=no,resizable=yes,width="+myWidth+",height="+myHeight);
	viewer.focus();
}
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;
}
/************************* hp pod engine ***************************************/
var myPod = null;
var myImg = null;
var myLbl = null;
var myOldImgUrl = null;
var curX = 0;
var curY = 0;
var coords = new Array(0,0,0,0);
var preCached = new Array(new Image(),new Image(),new Image(),new Image(),new Image(),new Image());
function checkMouse(e){
	if(myPod){
		curX = ie ? (event.x + document.body.scrollLeft) : e.pageX;
		curY = ie ? (event.y + document.body.scrollTop) : e.pageY;
		if(curX<coords[0] || curX>coords[2] || curY<coords[1] || curY>coords[3]){
			myPod.style.border = "2px solid #52453D";
			myLbl.style.visibility = "hidden";
			myImg.src = preCached[myPod.id.substring(5)].src;
			myPod = null;
		}
	}
}
function hpSetup(){
	preCached[0].src = "img/empty.gif";
	for(i=1;i<6;i++){
		myImg = document.getElementById("hpPod"+i).childNodes[0];
		preCached[i].src = myImg.src;

		document.getElementById("hpPod"+i).onmouseover = function(){
			if(myPod!=null){
				myPod.style.border = "2px solid #52453D";
				myLbl.style.visibility = "hidden";
				myImg.src = preCached[myPod.id.substring(5)].src;
			}
			myPod = this;
			myImg = this.childNodes[0];
			myLbl = document.getElementById("hpLbl"+myPod.id.substring(5));
			myPod.style.border = "2px solid #FFFFFF";
			myImg.style.border = "1px solid #52453D";
			myLbl.style.visibility = "visible";

			myImg.src = preCached[0].src;
			coords[0] = findPosX(myPod);
			coords[1] = findPosY(myPod);
			coords[2] = coords[0]+myPod.scrollWidth;
			coords[3] = coords[1]+myPod.scrollHeight+myLbl.scrollHeight;
		};
	}
	window.onmousemove = checkMouse;
}
