












var ROOT = "/dev/";
//var debuggingEnabled = true;
var debuggingEnabled = false;


var HS = 0;
var VS = 0;
window.onscroll = function updateScroll(){

	if (window.innerWidth) {
		// All browsers but Internet Explorer
		HS = window.pageXOffset; VS = window.pageYOffset;
		}
		else if(document.documentElement && document.documentElement.clientWidth){
		// These are for Internet Explorer 6 when a DOCTYPE is defined
		HS = document.documentElement.scrollLeft;
		VS = document.documentElement.scrollTop; }
		else if (document.body.clientWidth) {
		// These are for Internet Explorer 5/6 without a DOCTYPE
		HS = document.body.scrollLeft; VS = document.body.scrollTop;
	}

}



document.getElementsByClassName = function(cl){

	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = this.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i++) {
		var classes = elem[i].className;
		if (myclass.test(classes)) retnode.push(elem[i]);
	}

	return retnode;

};



function toggle(divid){

	var me = document.getElementById(divid);
	me.style.display = me.style.display == "inline" ? "none" : "inline";

}

var curFadeOpa = 1;

function centerDivHorizontally(divId){

	var me = document.getElementById(divId);
	var myLeft = ((document.body.offsetWidth / 2) - (me.offsetWidth / 2)) + "px";
	me.style.left = myLeft;

}
function centerDivVertically(divId){

	var me = document.getElementById(divId);
	var myTop = ((document.body.offsetWidth / 2) - (me.offsetWidth / 2)) + "px";
	me.style.top = myTop;

}



var fadeInPace = 25;
var fadeInSteps = .15;
function fadeDivIn(divId, finalOpacity){

	if(!document.getElementById(divId)) return;

	if(!finalOpacity) finalOpacity = 1;

	var theDiv = document.getElementById(divId);

	if(!theDiv.getAttribute("myOpa")) theDiv.setAttribute("myOpa", 0);
	var myOpacity = parseFloat(theDiv.getAttribute("myOpa"));

	//trace("myOpacity: " + myOpacity);

	if(myOpacity < finalOpacity){

		myOpacity = myOpacity + fadeInSteps;

		theDiv.style.opacity = myOpacity;
		//theDiv.style.filter = "alpha(opacity=" + myOpacity + ")";

		theDiv.setAttribute("myOpa", myOpacity);

		setTimeout("fadeDivIn('" + divId + "', " + finalOpacity + ")", fadeInPace);

	}
	else{

		theDiv.setAttribute("myOpa", finalOpacity);
		//theDiv.style.filter = "alpha(opacity=" + finalOpacity + ")";
		theDiv.style.opacity = finalOpacity;

	}

}



function fadeDivOut(divId){

	var theDiv = document.getElementById(divId);
	if(curFadeOpa > 0){
		curFadeOpa -= .03;
		theDiv.style.opacity = curFadeOpa;
		setTimeout("fadeDivOut('" + divId + "')", 40);
	}
	else{
		curFadeOpa = 1;
		theDiv.style.opacity = 0;
		theDiv.style.display = "none";
	}

}



function getWindowHeight(){

	var minHeight = 800;
	var mh = document.getElementsByTagName("body")[0].offsetHeight;
	return mh > minHeight ? document.getElementsByTagName("body")[0].offsetHeight : minHeight;

}

function getZoomables(){

	var zooms = document.getElementsByClassName("zoomMe");

	for(var i in zooms){

		zooms[i].onclick = function(){

			zoomThis(this.href, this.rel);
			return false;

		}

	}

}
getZoomables();

function zoomThis(pic, product){

	getDimmer();
	getModal(pic, product);

}



function getDimmer(){

	var d = document.createElement("div");
	d.id = "dimmer";
	d.style.height = getWindowHeight() + "px";
	d.style.width = "100%";

	d.style.position = "absolute";
	d.style.top = "0";
	d.style.left = "0";
	d.style.background = "#000";
	d.style.opacity = ".8";
	d.style.filter = "alpha(opacity = 80)";
	d.style.zIndex = "100";

	document.body.appendChild(d);

	d.onclick = function(){
		removeModal();
	}

}



function removeDimmer(){

	if(!document.getElementById("dimmer")) return;
	document.body.removeChild(document.getElementById("dimmer"));

}



function getModal(pic, product){

	var modal = document.createElement("div");
	modal.id = "modalWindow";
	modal.innerHTML += "<a href='#' id='closeButton' onclick='removeModal(); return false;' style='position: absolute; top: -20px; right: -30px; color: #fff; text-decoration: none; font-weight: bold;'>Sulje</a>";
	modal.innerHTML += "<img src='" + pic + "' alt='' id='modalLoadImg' />";
	//if(product != "") modal.innerHTML += "<p class='modalTitle'>" + product + "</p>";

	modal.style.position = "absolute";
	modal.style.left = "0";
	modal.style.zIndex = "101";

	document.body.appendChild(modal);
	modal.style.top = (VS + 30) + "px";
	modal.style.visibility = "hidden";

	var myImg = document.getElementById('modalLoadImg');
	myImg.onload = function(){

		centerDivHorizontally("modalWindow");
		modal.style.visibility = "visible";

	}

}



function removeModal(){

	if(!document.getElementById("modalWindow")) return;
	document.body.removeChild(document.getElementById("modalWindow"));
	removeDimmer();

}



































var req;
var which;
function retrieveURL(url) {
if (window.XMLHttpRequest) { // Non-IE browsers
  req = new XMLHttpRequest();
  req.onreadystatechange = processStateChange;
  try {
	req.open("GET", url, true);
  } catch (e) {
	alert(e);
  }
  req.send(null);
} else if (window.ActiveXObject) { // IE
  req = new ActiveXObject("Microsoft.XMLHTTP");
  if (req) {
	req.onreadystatechange = processStateChange;
	req.open("GET", url, true);
	req.send();
  }
}
}
function processStateChange() {
if (req.readyState == 4) { // Complete
  if (req.status == 200) { // OK response
	eval(req.responseText);
  } else {
	//alert("Problem: " + req.statusText);
  }
}
}

var myURL = window.location.href;

if(myURL.indexOf("http://www.nokianpanimo.fi/juomat") > 0 && myURL.indexOf("http://www.nokianpanimo.fi/virvoitusjuomat") < 0) varmistaAikuisuus(0);

function varmistaAikuisuus(linkki){
	var myBody = document.getElementsByTagName("body")[0];
	var dimmer = document.createElement("div");
		dimmer.id = "dimmer";
		dimmer.style.position = "absolute";
		dimmer.style.top = "0px";
		dimmer.style.left = "0px";
		dimmer.style.width = "100%";
		dimmer.style.background = "#000";
		if (window.innerWidth) {
			dimmer.style.height = myBody.offsetHeight + "px";
			dimmer.style.opacity = ".9";
		}
		else{
			dimmer.style.height = "2500px"; // TODO: Purkkaa...
			dimmer.style.filter = "alpha(opacity=" + 90 + ")";
		}
		dimmer.style.zIndex = "1000";

	var qBox = document.createElement("div");
		qBox.id = "qBox";
		qBox.style.position = "absolute";
		qBox.style.width = "396px";
		qBox.style.height = "171px";
		qBox.style.top = "150px";
		qBox.style.left = (myBody.offsetWidth / 2) - (350 / 2) + "px";
		qBox.style.background = "url(http://www.nokianpanimo.fi/img/18v.jpg) no-repeat";
		qBox.style.color = "#fff";
		qBox.style.paddingTop = "90px";
		qBox.style.textAlign = "center";
		qBox.innerHTML = "<div><a href='#' onclick='olenAikuinen("+linkki+"); return false;' style='color: #fff;'>Kyllä</a> &nbsp;&nbsp;|&nbsp;&nbsp; <a href='http://www.nokianpanimo.fi/juomat/virvoitusjuomat/' style='color: #fff;'>En</a></div>";
		qBox.style.zIndex = "1010";

	myBody.appendChild(dimmer);
	myBody.appendChild(qBox);

}

function olenAikuinen(linkki){
	retrieveURL("/aikuinen.php?linkki=" + linkki);
	document.getElementById("dimmer").style.display	= "none";
	document.getElementById("qBox").style.display 	= "none";
}
if(document.getElementById("juomaLinkki")){
	document.getElementById("juomaLinkki").onclick = function(){
		varmistaAikuisuus(1);
		return false;
	}
}

if(myURL.indexOf("fi/juomat") > 0 && myURL.indexOf("fi/virvoitusjuomat") < 0) varmistaAikuisuus(0);
