// JavaScript Document
var navMenuList = new Array('home','ofirmie','produkty','aktual','kontakt');
for(i=0;i<navMenuList.length;i++){
	eval("var " + navMenuList[i] + "_over = new Image;");
	eval(navMenuList[i] + "_over.src = 'images/nav/box_" + navMenuList[i] + "_over.jpg';");
	eval("var " + navMenuList[i] + "_off = new Image;");
	eval(navMenuList[i] + "_off.src = 'images/nav/box_" + navMenuList[i] + ".jpg';");
}
function showMenu(menuname){
	document.getElementById(menuname).style.display="block";
}
function hideMenu(menuname){
	document.getElementById(menuname).style.display="none";
}
function rollover(linkname){
	eval("document.images."+linkname+".src = "+linkname+"_over.src");
	return true;
}
function rollout(linkname){
	eval("document.images."+linkname+".src = "+linkname+"_off.src");
	return true;
}
function dropdownrollover(linkname){
	document.getElementById(linkname).style.backgroundColor="#e7eaf2";
}
function dropdownrollout(linkname){
	document.getElementById(linkname).style.background="none";
}
function navrollover(linkname){
	document.getElementById(linkname).style.backgroundColor="#a2b2c2";
}
function navrollout(linkname){
	document.getElementById(linkname).style.backgroundColor="#6f7f90";
}

var picList1 = ['track1.jpg','track2.jpg','fasttrain1.jpg','fasttrain2.jpg','roundtable1.jpg','roundtable2.jpg','blue_chip.jpg','blue_infoboard.jpg','track1_fade.gif','track2_fade.gif','fasttrain1_fade.gif','fasttrain2_fade.gif','roundtable1_fade.gif','roundtable2_fade.gif','blue_chip_fade.gif','blue_infoboard_fade.gif'];
var picList2 = ['blueglobe.gif','swirl.jpg','bigscreen1.jpg','bigscreen2.jpg','bridge1.jpg','bridge2.jpg','tunel1.jpg','tunel2.jpg','blueglobe_fade.gif','swirl_fade.jpg','bigscreen1_fade.jpg','bigscreen2_fade.jpg','bridge1_fade.jpg','bridge2_fade.jpg','tunel1_fade','tunel2_fade'];
var picList3 = ['nodes.jpg','touchscreen1.jpg','touchscreen2.jpg','chipboard1.jpg','chipboard2.jpg','codewall.jpg','datacenter1.jpg','datacenter2.jpg','nodes_fade.jpg','touchscreen1_fade.jpg','touchscreen2_fade.jpg','chipboard1_fade.jpg','chipboard2_fade.jpg','codewall_fade.jpg','datacenter1_fade.jpg','datacenter2_fade.jpg'];
var picBoxes1 = ["picbox3","picbox4","picbox8","picbox11","picbox12","picbox16"];
var picBoxes2 = ["picbox2","picbox5","picbox6","picbox10","picbox13","picbox14"];
var picBoxes3 = ["picbox2","picbox3","picbox6","picbox10","picbox11","picbox14"];
var animations = [];
var animationCount = 0;
var picboxes = [];
var startFrom = 0;
var startTo = 30;
var currPageNum = 1;

for(n=0;n<16;n++){
	eval("var picList1" + n + " = new Image;");
	eval("picList1" + n + ".src = 'images/pics/" + picList1[n] + "';");
	eval("var picList2" + n + " = new Image;");
	eval("picList2" + n + ".src = 'images/pics/" + picList2[n] + "';");
	eval("var picList3" + n + " = new Image;");
	eval("picList3" + n + ".src = 'images/pics/" + picList3[n] + "';");
}

function nextAnimation() {
	if (animations[animationCount]) {
	// writeDebug('starting animation '+animationCount);
		animations[animationCount].start();
		animationCount++;
	}else{ //clean up animations array
		animations.length=0;
		animationCount=0;
	}
}


var pageNum = 1;

function boxesOut(){
	startFrom = 0;
	startTo = 30;
	if(pageNum=="3"){ picboxes = picBoxes3; }
	else if(pageNum=="2"){ picboxes = picBoxes2; }
	else{ picboxes = picBoxes1; }
	animations.push(new Animation({
		from: startFrom,
		to: startTo,
		ontween: function(value){
			oBox=document.getElementById(picboxes[0]);
			slideOut(oBox,value);
			oBox=document.getElementById(picboxes[3]);
			slideOut(oBox,value);
		},
		oncomplete: nextAnimation
	}));
	animations.push(new Animation({
		from: startFrom,
		to: startTo,
		ontween: function(value){
			oBox=document.getElementById(picboxes[1]);
			slideOut(oBox,value);
			oBox=document.getElementById(picboxes[4]);
			slideOut(oBox,value);
		},
		oncomplete: nextAnimation
	}));
	animations.push(new Animation({
		from: startFrom,
		to: startTo,
		ontween: function(value){
			oBox=document.getElementById(picboxes[2]);
			slideOut(oBox,value);
			oBox=document.getElementById(picboxes[5]);
			slideOut(oBox,value);
		},
		//oncomplete: setPositions
	}));
	nextAnimation();
	var newPageRef = "newPage()";
	var newPageTimer = setTimeout(newPageRef,6000);
}

function slideOut(o,value) {
	if(value>0){
		o.style.left = '-'+value+'px';
	}else{
		o.style.left = value+'px';
	}
	o.style.top = value+'px';
}

function newPage(){
	if(pageNum=="3"){ picboxes = picBoxes3; }
	else if(pageNum=="2"){ picboxes = picBoxes2; }
	else{ picboxes = picBoxes1; }
	startFrom = 30;
	startTo = 0;
	animations.push(new Animation({
		from: startFrom,
		to: startTo,
		ontween: function(value){
			oBox=document.getElementById(picboxes[0]);
			slideOut(oBox,value);
			oBox=document.getElementById(picboxes[1]);
			slideOut(oBox,value);
			oBox=document.getElementById(picboxes[2]);
			slideOut(oBox,value);
			oBox=document.getElementById(picboxes[3]);
			slideOut(oBox,value);
			oBox=document.getElementById(picboxes[4]);
			slideOut(oBox,value);
			oBox=document.getElementById(picboxes[5]);
			slideOut(oBox,value);
		},
	}));
	nextAnimation();
	var newPageCall = "openNewPage()";
	var myTimer = setTimeout(newPageCall,800);
}

function resetPositions(){
	if(pageNum=="3"){ picboxes = picBoxes3; }
	else if(pageNum=="2"){ picboxes = picBoxes2; }
	else{ picboxes = picBoxes1; }
	for(n=0;n<6;n++){
		document.getElementById(picboxes[n]).style.left="0px";
		document.getElementById(picboxes[n]).style.top="0px";
	}
}

function setPositions(){
	if(pageNum=="3"){ picboxes = picBoxes3; }
	else if(pageNum=="2"){ picboxes = picBoxes2; }
	else{ picboxes = picBoxes1; }
	for(n=0;n<6;n++){
		document.getElementById(picboxes[n]).style.left="-30px";
		document.getElementById(picboxes[n]).style.top="30px";
	}
}

function openNewPage(){
	//resetPositions();
	var picList = [];
	pageNum = pageNum + 1;
	if(pageNum > 3){ pageNum = 1; }
	if(pageNum==3){ picList = picList3; }
	else if(pageNum==2){ picList = picList2; }
	else{ picList = picList1; }
	for(i=1;i<=3;i++){
		thisContentBox = "mainpagecontent"+i;
		if(i==pageNum){
			document.getElementById(thisContentBox).style.display="block";
		}else{
			document.getElementById(thisContentBox).style.display="none";
		}
	}
	for(j=0;j<16;j++){
		imageNum = j+1;
		imageName = "pic"+imageNum;
		imagePath = "images/pics/"+picList[j];
		document[imageName].src = imagePath;
	}
	//var myTestTimer = setTimeout('boxesOut()',400);
	boxesOut();
}





/////////// GET WINDOW INFO //////////////
var winHeight = 0;
var winWidth = 0;
var docWidth = 0;
var docOffset = 0;
var contentTop = 0;
var docHeight = 0;
function setDivHeights(page){
	if (window.innerWidth) { //if browser supports window.innerWidth
		winHeight = window.innerHeight;
		docWidth = document.body.clientWidth;
		docOffset = window.pageYOffset;
		if(docWidth <= 0){ docWidth = window.outerWidth; }
	}else if (document.all) { //else if browser supports document.all (IE 4+)
		winHeight = document.body.clientHeight;
		docWidth = document.body.clientWidth;
		docOffset = document.body.scrollTop;
	}
	docHeight = Math.max(Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),Math.max(document.body.clientHeight, document.documentElement.clientHeight));
	//alert("docHeight: "+docHeight+" ; winHeight:"+winHeight);
	
	var contentHeight = docHeight - 122;
	var backgrndHeight = docHeight - 500;
	var tablebackW = docWidth + 30;
	if(navigator.appName=='Opera'){ contentHeight = docHeight - 172; }
	if(page=="mainpage"){
		//document.getElementById("mainpagecontent1").style.height = contentHeight + "px";
		//document.getElementById("mainpagecontent2").style.height = contentHeight + "px";
		//document.getElementById("mainpagecontent3").style.height = contentHeight + "px";
		document.getElementById("tabletopback").style.height = backgrndHeight + "px";
		document.getElementById("tabletopback").style.width = docWidth + "px";
	}else{
		//alert(document.getElementById("subnav").style.height);
		var subnavbackT = currTop + 30;
		var subnavbackH = contentHeight - currTop - 30;
		document.getElementById("subnav").style.height = contentHeight + "px";
		document.getElementById("subpagecontent").style.height = contentHeight + "px";
		document.getElementById("subnavback").style.top = subnavbackT + "px";
		document.getElementById("subnavback").style.height = subnavbackH + "px";
		document.getElementById("subnavtop").style.top = currTop + "px";
		var bottompos = document.getElementById("subpagebottom").offsetTop;
		if(subpage==14){
			document.getElementById("subpagecontentblock").style.height = (bottompos) + "px";
		}else{
			document.getElementById("subpagecontentblock").style.height = (bottompos-30) + "px";
		}
		//alert(bottompos);
	}
}
function setGalleryTop(){
	if (window.innerWidth) { //if browser supports window.innerWidth
		winHeight = window.innerHeight;
		docOffset = window.pageYOffset;
	}else if (document.all) { //else if browser supports document.all (IE 4+)
		winHeight = document.body.clientHeight;
		docOffset = document.body.scrollTop;
	}
	var fotoHeight = document.images.bigphoto.height;
	var fotoWidth = document.images.bigphoto.width;
	var clipLeft = (fotoWidth/2)-50;
	var clipRight = (fotoWidth/2)+50;
	//var clipValue = 
	//alert(fotoHeight);
	document.getElementById("galleryphoto").style.marginLeft = (414-(fotoWidth/2))+"px";
	document.getElementById("galleryphoto").style.width = fotoWidth + "px";
	document.getElementById("galleryphoto").style.height = fotoHeight + "px";
	document.getElementById("galleryphoto").style.clip = 'rect(0,'+clipRight+'px,'+fotoHeight+'px,'+clipLeft+'px)';
	document.getElementById("galleryphoto").style.top = (docOffset+50) + "px";
}

//////////// GALLERY ANIMATION /////////////
var fotoWidth = 0;
var fotoHeight = 0;
var imgPath = "pkp_info_01_lg.jpg";
var clipLeft = 0;
var clipRight = 0;

function slideClip(value){
	var newLeftClip = clipLeft - value;
	var newRightClip = clipRight + value;
	var clipDec = "rect(0 "+newRightClip+"px "+fotoHeight+"px "+newLeftClip+"px)";
	document.getElementById("galleryphoto").style.clip=clipDec;
}

function openGallery(){
	// FIRST GET WINDOW INFO
	if (window.innerWidth) { //if browser supports window.innerWidth
		winHeight = window.innerHeight;
		winWidth = window.innerWidth;
		docOffset = window.pageYOffset;
		docHeight = window.outerHeight;
	}else if (document.all) { //else if browser supports document.all (IE 4+)
		winHeight = window.innerHeight;
		winWidth = document.body.clientWidth;
		docOffset = document.body.scrollTop;
		docHeight = document.documentElement.clientHeight;
	}
	// SET UP GALLERY PHOTO
	document.images.bigphoto.src = "images/page/"+imgPath;
	fotoHeight = 900; // NEED TO GET THIS FROM DATABASE!!!!
	fotoWidth = 600;  // ADD PADDING
	clipLeft = fotoWidth/2;
	clipRight = fotoWidth/2;
	// POSITION PHOTO IN CENTER
	document.getElementById("galleryphoto").style.marginLeft = ((winWidth/2)-(fotoWidth/2))+"px";
	document.getElementById("galleryphoto").style.width = (fotoWidth + 12) + "px";  // ADD 12px FOR PADDING
	document.getElementById("galleryphoto").style.height = (fotoHeight + 12) + "px";
	document.getElementById("galleryphoto").style.clip = 'rect(0,'+clipRight+'px,'+fotoHeight+'px,'+clipLeft+'px)';
	document.getElementById("galleryphoto").style.top = (docOffset+50) + "px";
	document.getElementById("galleryphoto").style.display = "block";
	document.getElementById("galleryphototext").style.width = fotoWidth + "px";
	document.getElementById("screen").style.width = winWidth + "px";
	document.getElementById("screen").style.height = docHeight + "px";
	document.getElementById("screen").style.display = "block";
	// CALL ANIMATION
	openTo = (fotoWidth/2);
	openClip(openTo);
}

function openClip(openTo){
	startFrom = 0;
	startTo = openTo;
	animations.push(new Animation({
		from: startFrom,
		to: startTo,
		ontween: function(value){
			slideClip(value);
		},
		//oncomplete: nextAnimation
	}));
	nextAnimation();
}

function closeGallery(){
	startFrom = fotoWidth/2;
	startTo = 0;
	animations.push(new Animation({
		from: startFrom,
		to: startTo,
		ontween: function(value){
			slideClip(value);
		},
		oncomplete: hideGallery
	}));
	nextAnimation();
}

function hideGallery(){
	document.getElementById("galleryphoto").style.display = "none";
	document.getElementById("screen").style.display = "none";
}

////// OPEN IMAGE FUNCTIONS ////////////

var imgW = 0;
var imgH = 0;
var imgL = 0;
var imgT = 0;
var cimgW = 0;
var cimgH = 0;
var cimgL = 0;
var cimgT = 0;
var imgP = 1;
var initW = 0;
var targImg = "";
var targDiv = "";

function openFoto(imgname,targetdiv,targetimg,imgwidth,imgheight){
	initW = imgwidth;
	imgW = imgwidth;
	imgH = imgheight;
	imgP = imgH/imgW;
	targImg = targetimg;
	targDiv = targetdiv;
	//must set position of bigforo using offsetTop and offsetLeft
	setLeft = document.getElementById(imgname).offsetLeft-12; //compensate for margins
	setTop = document.getElementById(imgname).offsetTop-8;
	document.getElementById(targDiv).style.left = setLeft+"px";
	document.getElementById(targDiv).style.top = setTop+"px";
	document.getElementById(targDiv).style.display="block";
	startFrom = imgW;
	startTo = imgW * 1.5;
	animations.push(new Animation({
		from: startFrom,
		to: startTo,
		tweenType: 'blast',
		ontween: function(value){
			enlargeFoto(value);
		},
		//oncomplete: nextAnimation
	}));
	nextAnimation();
}

//function closeFoto(cimgname,ctargetdiv,ctargetimg,cimgwidth,cimgheight){
	//cimgW = cimgwidth;
	//cimgH = cimgheight;
	//imgP = cimgH/cimgW;
	//ctargImg = ctargetimg;
	//ctargDiv = ctargetdiv;
	//document.getElementById(ctargDiv).style.display="block";
	//startFrom = cimgW;
	//startTo = cimgW/1.5;
	//animations.push(new Animation({
		//from: startFrom,
		//to: startTo,
		//tweenType: 'blast',
		//ontween: function(value){
			//shrinkFoto(value);
		//},
		//oncomplete: resetImg
	//}));
	//nextAnimation();
//}

function closeFoto(cimgname,ctargetdiv,ctargetimg,cimgwidth,cimgheight){
	document.getElementById(ctargetdiv).style.display="none";
	document.getElementById(ctargetimg).width = initW;
	document.getElementById(ctargetimg).height = initW * imgP;
	document.getElementById(ctargetdiv).style.marginLeft = 0;
	document.getElementById(ctargetdiv).style.marginTop = 0;
}
function enlargeFoto(value){
	imgW = value;
	imgH = value*imgP;
	imgL = (value-initW) * -1;
	imgT = (value-initW) * -.6;
	document.getElementById(targImg).width =imgW;
	document.getElementById(targImg).height=imgH;
	document.getElementById(targDiv).style.marginLeft=imgL+"px";
	document.getElementById(targDiv).style.marginTop=imgT+"px";
}
function shrinkFoto(value){
	cimgW = value;
	cimgH = value*imgP;
	cimgL = (value-initW) * -1;
	cimgT = (value-initW) * -.6;
	document.getElementById(ctargImg).width =cimgW;
	document.getElementById(ctargImg).height=cimgH;
	document.getElementById(ctargDiv).style.marginLeft=cimgL+"px";
	document.getElementById(ctargDiv).style.marginTop=cimgT+"px";
}

function otworz(adres){
	var myWindow = window.open(adres, 'opis', 'height=820, width=580, top=0, left=100, scrollbars=yes, location=no').focus();
}
function otworz2(adres){
	var myWindow = window.open(adres, 'opis', ',height=600, width=800, top=0, left=100, scrollbars=yes, location=no').focus();
}
function otworz1(adres){
	var myWindow = window.open(adres, 'opis', 'height=720, width=800, top=0, left=100, scrollbars=yes, location=no').focus();
}
function otworz3(adres) /* --- gazela biznesu--- */
	{
		var myWindow = window.open(adres, 'opis', ',height=400, width=560, top=0, left=100, scrollbars=yes, location=no').focus();
	}
