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 = 170+"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 mainMode;
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;
}

/************************* jquery ***************************************/
var img = new Image();
var pause = new Image(); pause.src = "img/pause.gif";
var play = new Image(); play.src = "img/play.gif";
var curIndex = 1;
var myWrap = null;

$(document).ready(function(){
	myWrap = $("#main DIV");
	canvasCoords[0] = findPosX($("#canvas")[0]);
	canvasCoords[1] = document.getElementById("canvas").scrollWidth;
	//	wTitle, wCount, wTotal, wPrev, wNext
	$("#wTotal").html(homePics.length);
	$("#wPrev").click(function(){
		$("#pp")[0].src = play.src;
		clearTimeout(window.playTimer);
		curIndex = (curIndex==1) ? homePics.length : curIndex-1;
		updateImage();
		return false;
	});
	$("#wNext").click(function(){
		$("#pp")[0].src = play.src;
		clearTimeout(window.playTimer);
		curIndex = (curIndex==homePics.length) ? 1 : curIndex+1;
		updateImage();
		return false;
	});
	$("#mImage").click(function(){
		$("#wNext").click();
	});
	for(i=0;i<homePics.length;i++){ // start loading in the background;
		newImg = new Image();
		newImg.src = homePics[i][1];
		homePics[i][1] = newImg;
	}
	function updateImage(){
		$("#wCount").html(curIndex);
		img = $("#mImage:first");
		$("#main").addClass("loading");
		$(img).fadeOut(250, function(){
			$(img).attr('width', homePics[curIndex-1][2]);
			$(img).attr('height', homePics[curIndex-1][3]);
			myWrap.css({width:homePics[curIndex-1][2]+"px"});
			myWrap.css({height:homePics[curIndex-1][3]+"px",border:"5px solid #FFFFFF"});
//			alert(typeof(homePics[curIndex-1][1])=="string");
			if(typeof(homePics[curIndex-1][1])=="string"){
				$(img).attr('src', homePics[curIndex-1][1]);
				$(img).load(function(){ // image loading
				    $("#main").removeClass("loading");
					$("#wTitle").html(homePics[curIndex-1][0]);
					$(img).fadeIn(500);
					newImg = new Image();
					newImg.src = $(img).attr('src');
					homePics[curIndex-1][1] = newImg;
//					alert()
//					clearTimeout(window.playTimer);
//					window.playTimer = setTimeout("playHP()", 4000);
				})
			}else{
//				$(img).attr("");
				$(img).attr('src', homePics[curIndex-1][1].src);
				$(img).load(function(){ // image loading
				    $("#main").removeClass("loading");
					$("#wTitle").html(homePics[curIndex-1][0]);
					$(img).fadeIn(500);
//					alert(window.playTimer);
//					clearTimeout(window.playTimer);
//					window.playTimer = setTimeout("playHP()", 4000);
				})
			}
			if(homePics[curIndex-1][3]>452){
				myMarginLeft = (690-parseInt(homePics[curIndex-1][2]))/2;
				coords[0] = window.findPosX(document.getElementById("main"))+myMarginLeft;
				coords[1] = window.findPosY(document.getElementById("main"));
				coords[2] = coords[0]+parseInt(homePics[curIndex-1][2])+5;
				coords[3] = coords[1]+parseInt(homePics[curIndex-1][3])+20;
//				alert(myMarginLeft)
				$("#main DIV").css({margin:"0px auto 0px "+(myMarginLeft-10)+"px"})
				$("#pods").css({opacity:"0.3"});
				window.checkForMouse = true;
			} else{
				$("#main DIV").css({margin:"0px auto 0px auto"})
				$("#pods").css({opacity:"1"});
				window.checkForMouse = false;
			}
		})
	}
	window.playHP = function(){
		curIndex = (curIndex==homePics.length) ? 1 : curIndex+1;
		updateImage();
//		clearTimeout(window.playTimer);
		window.playTimer = setTimeout("playHP()", 5000);
	}
	window.playTimer = setTimeout("playHP()", 5000);
	$(".pp").click(function(){
		ppBtn = $("#pp")[0];
		if(ppBtn.src.indexOf("pause")==-1){
			clearTimeout(window.playTimer);
			playHP();
			ppBtn.src = pause.src;
		} else{
			clearTimeout(window.playTimer);
			ppBtn.src = play.src;
		}
		return false;
	});
});

var checkForMouse = false;
var curX = 0;
var curY = 0;
var canvasCoords = new Array(0,0) // x, width
var coords = new Array(0,0,0,0);
function checkMouse(e){
//	alert(checkForMouse)
	if(checkForMouse){
		curX = ie ? (event.x + document.body.scrollLeft) : e.pageX;
		curY = ie ? (event.y + document.body.scrollTop) : e.pageY;
		if(
			(
				((curX<coords[0] && curX>canvasCoords[0] || curX>coords[2] && curX<canvasCoords[0]+canvasCoords[1]) 
					&& curY>coords[1]+472)
					||  
				(curX>canvasCoords[0] && curX<canvasCoords[0]+canvasCoords[1] && curY>coords[3])
			)
			 && myWrap.css("height")!="452px"
		){
		
//			document.getElementById("navigation").innerHTML += myWrap.css("height")+"<br>";
			myWrap.css({height:"452px",border:"5px solid #a3d517"});
			coords[3] = coords[1]+452+20;
			$("#pods").css({opacity:"1"});
		} else if(!(curY>coords[3] || (curX>coords[2] && curY>coords[1]+472 && curX<canvasCoords[0]+canvasCoords[1]) || (curX<coords[0] && curY>coords[1]+472) && curX>canvasCoords[0]) && myWrap.css("height")!=coords[1]+parseInt(homePics[curIndex-1][3])+"px") {
//			document.getElementById("navigation").innerHTML += myWrap.css("height")+"<br>";
			myWrap.css({height:homePics[curIndex-1][3]+"px",border:"5px solid #FFFFFF"});
			coords[3] = coords[1]+parseInt(homePics[curIndex-1][3])+20;
			$("#pods").css({opacity:"0.3"});
		}
	}
}
window.onmousemove = checkMouse;