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("about");
		myCanvas = document.getElementById("canvas");
		myNavigation = document.getElementById("navigation");
		if (myDivider) myDivider.style.display = "none";
		if (myCanvas && myNavigation && myAbout){
//			myAbout.style.position = "absolute";
//			myNavigation.style.position = "absolute";
//			myCanvas.style.position = "absolute";
			myCanvas.style.left = myNavigation.scrollWidth+20+"px";
//			myCanvas.style.height = (myCanvas.scrollHeight<280) ? "280px" : myCanvas.scrollHeight+"px";
//			myNavigation.style.top = (myCanvas.scrollHeight-myNavigation.scrollHeight>20) ? myCanvas.scrollHeight-myNavigation.scrollHeight+"px" : "0px";
			myNavigation.style.top = 160+"px";
		}
		initiated = true;
	}
	get_scr_res();
	if (myHome){
//		myHome.style.position = "absolute";
		myHome.style.left = _width/2-130+"px";
		myHome.style.top  = (_height-myHome.scrollHeight)/2-30+"px";// 55 je haluz
	}
	if (myCanvas && myNavigation && myAbout){
/*		if(_width>1000){
			myCanvas.style.marginLeft = (_width-1000)/2+"px";
			myNavigation.style.marginLeft = (_width-1000)/2+"px";
			myAbout.style.marginLeft = (_width-1000)/2+"px";
		}else{
			myCanvas.style.marginLeft = "0px";
			myNavigation.style.marginLeft = "20px";
			myAbout.style.marginLeft = "20px";
		}*/
		topMargin = _height-myNavigation.scrollHeight-22;
	}
	layerSetup(); // start floating
//	alert("dock2");
//	if (document.getElementById("dock")) document.getElementById("dock").style.visibility = "visible";
//	if (ie){
//		if (document.getElementById("navigation")) document.getElementById("navigation").style.visibility = "visible";
//		if (document.getElementById("home")) document.getElementById("home").style.visibility = "visible";
//		if (document.getElementById("canvas")) document.getElementById("canvas").style.visibility = "visible";
//	}
	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();
}
