onload = onresize = function() {
	var windowHeight = 0;
	if( typeof( window.innerHeight ) == 'number' ) {
		windowHeight = window.innerHeight;
		windowWidth = window.innerWidth;
  } else if ( document.documentElement && document.documentElement.clientHeight ) {
		windowHeight = document.documentElement.clientHeight;
		windowWidth = document.documentElement.clientWidth;
	} else if ( document.body && document.body.clientHeight ) {
		windowHeight = document.body.clientHeight;
		windowWidth = document.body.clientWidth;
	}
	centerPointY = ( windowHeight - 400 ) / 2;
	centerPointX = ( windowWidth - 700 ) / 2;
	document.getElementById("blockMainContent").style.top = centerPointY + "px";
	document.getElementById("blockMainContent").style.left = centerPointX +"px";

	for ( i = 1; i <= numWork; i++ ) {
		document.getElementById("work"+i).style.left = ico[i]["posX"]+"px";
		if (ico[i]["valign"] == "bottom") {
			document.getElementById("work"+i+"Aligner").style.height = ( ico[i]["posY"] - 17 + centerPointY - document.getElementById("work"+i+"IcoDescription").offsetHeight ) + "px";
			document.getElementById("work"+i).style.height = ( ico[i]["posY"] +  centerPointY )+ "px";
			document.getElementById("work"+i).style.top = ( 0 - centerPointY) + "px";
		} else {
			document.getElementById("work"+i+"Aligner").style.height = ( centerPointY + 400 - 17 - ico[i]["posY"]  - document.getElementById("work"+i+"IcoDescription").offsetHeight ) + "px";;
			document.getElementById("work"+i).style.height = ( windowHeight - ico[i]["posY"] - centerPointY ) + "px";
			document.getElementById("work"+i).style.top = ico[i]["posY"] + "px";
		}
	}
	document.getElementById("work"+numWork+"Ico").src = "frontend/images/ico_white_"+ico[numWork]["orient"]+"_"+ico[numWork]["version"]+".gif";
	document.getElementById("work"+numWork).style.backgroundColor = "#ffffff";
	if (ico[numWork]["valign"] == "bottom") {
		document.getElementById("work"+numWork+"Description").style.top = ( ico[numWork]["posY"] - document.getElementById("work"+numWork+"Description").offsetHeight - 17)+"px";
	} else {
		document.getElementById("work"+numWork+"Description").style.top = ( ico[numWork]["posY"] + 17)+"px";
	}
	document.getElementById("work"+numWork+"Description").style.left = ( ico[numWork]["posX"] + 25 )+"px"
	document.getElementById("work"+numWork+"Description").style.visibility = "visible";
	document.getElementById("blockMainContent").style.visibility = "visible";
}

function changeIco(icoId, icoStyle) {
	if (activeWorkId != icoId) {
		if ( icoStyle != 'white' ) {
			if ( ico[icoId]["status"] == "gray" ) {
				document.getElementById("work"+icoId+"Ico").src = "frontend/images/ico_lightgray_"+ico[icoId]["orient"]+"_"+ico[numWork]["version"]+".gif";
				document.getElementById("work"+icoId).style.backgroundColor = "#555555";
			} else {
				document.getElementById("work"+icoId+"Ico").src = "frontend/images/ico_darkgray_"+ico[icoId]["orient"]+"_"+ico[numWork]["version"]+".gif";
				document.getElementById("work"+icoId).style.backgroundColor = "#444444";
			}
		} else {
			document.getElementById("work"+icoId+"Ico").src = "frontend/images/ico_overgray_"+ico[icoId]["orient"]+"_"+ico[numWork]["version"]+".gif";
			document.getElementById("work"+icoId).style.backgroundColor = "#666666";
		}
	}
}

function changeImage(imageId, opacityValue) {
	var nextPicture;
	if ( opacityValue != 100 ) {
		opacityValue = opacityValue + 10;
		nextPicture = ico[imageId]["activePicture"];
	} else {
		opacityValue = 0;
		if (ico[imageId]["activePicture"] == ico[imageId]["numPicture"]) {
			nextPicture = 1;
		} else {
			nextPicture = ico[imageId]["activePicture"] + 1;
		}
	}
	document.getElementById("work"+imageId+"DescriptionPicture").src = "frontend/images/portfolio/work_"+imageId+"_"+nextPicture+".jpg";
/*	if (!document.all) {
		document.getElementById("work"+imageId+"DescriptionPicture").style.MozOpacity = opacityValue / 100;
	} else {
		document.getElementById("work"+imageId+"DescriptionPicture").style.filter = "alpha(opacity="+opacityValue+")";
	}	*/
	ico[imageId]["activePicture"] = nextPicture;
	myTimer = setTimeout("changeImage("+imageId+", "+opacityValue+")", 100);
}

function activeWork(workId) {
	if ( typeof( myTimer ) != "undefined") {
		clearTimeout(myTimer);
	}
	if ( activeWorkId != workId ) {
		if ( activeWorkId != 0 ) {
			document.getElementById("work"+activeWorkId+"Ico").src = "frontend/images/ico_lightgray_"+ico[activeWorkId]["orient"]+"_"+ico[numWork]["version"]+".gif";
			document.getElementById("work"+activeWorkId).style.backgroundColor = "#555555";
		}
		document.getElementById("work"+workId+"Ico").src = "frontend/images/ico_white_"+ico[workId]["orient"]+"_"+ico[numWork]["version"]+".gif";
		document.getElementById("work"+workId).style.backgroundColor = "#ffffff";
		if ( ico[workId]["valign"] == "bottom" ) {
			document.getElementById("work"+workId+"Description").style.top = ( ico[workId]["posY"] - document.getElementById("work"+workId+"Description").offsetHeight - 17 ) + "px";
		} else {
			document.getElementById("work"+workId+"Description").style.top = ( ico[workId]["posY"] + 17 ) + "px";
		}
		if ( ico[workId]["align"] == "right" ) {
			document.getElementById("work"+workId+"Description").style.left = ( ico[workId]["posX"] + 25 ) + "px"
			document.getElementById("work"+workId+"Description").style.textAlign = "left";
		} else {
			document.getElementById("work"+workId+"Description").style.left = ( ico[workId]["posX"] - document.getElementById("work"+workId+"Description").offsetWidth - 8 ) + "px";
			document.getElementById("work"+workId+"Description").style.textAlign = "right";
		}
		if ( activeWorkId != numWork && activeWorkId != 0 ) {
			document.getElementById("work"+activeWorkId+"Description").style.visibility = "hidden";
			document.getElementById("work"+activeWorkId+"Description").style.zIndex = 1;
			ico[activeWorkId]["status"] = "gray";
		}
		document.getElementById("work"+workId+"Description").style.visibility = "visible";
		document.getElementById("work"+workId+"Description").style.zIndex = 3;
		activeWorkId = workId;
		if ( workId != numWork ) {
					myTimer = setTimeout("changeImage("+workId+", -10)", 250);
		}
	} else {
		if ( activeWorkId != 0 ) {
			document.getElementById("work"+activeWorkId+"Ico").src = "frontend/images/ico_lightgray_"+ico[activeWorkId]["orient"]+"_"+ico[numWork]["version"]+".gif";
		}
		document.getElementById("work"+activeWorkId).style.backgroundColor = "#555555";
		if ( activeWorkId != numWork && activeWorkId != 0 ) {
			document.getElementById("work"+activeWorkId+"Description").style.visibility = "hidden";
			document.getElementById("work"+activeWorkId+"Description").style.zIndex = 1;
		}
		ico[activeWorkId]["status"] = "gray";
		activeWorkId = 0;
	}
}

function goURL (linkId, windowName) {
	if (windowName == 'this') {
		window.location.href = linkId;
	} else {
		window.open(linkId.href, "newWin");
	}
	return false;
}
