init = function(){
	tooltips(null);
	startList();
}
/*LB*/
/*
Created By: Chris Campbell
Website: http://particletree.com
Date: 2/1/2006

Inspired by the lightbox implementation found at http://www.huddletogether.com/projects/lightbox/
*/

/*-------------------------------GLOBAL VARIABLES------------------------------------*/

var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

/*-----------------------------------------------------------------------------------------------*/

//Browser detect script origionally created by Peter Paul Koch at http://www.quirksmode.org/

function getBrowserInfo() {
	if (checkIt('konqueror')) {
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (checkIt('safari')) browser 	= "Safari"
	else if (checkIt('omniweb')) browser 	= "OmniWeb"
	else if (checkIt('opera')) browser 		= "Opera"
	else if (checkIt('webtv')) browser 		= "WebTV";
	else if (checkIt('icab')) browser 		= "iCab"
	else if (checkIt('msie')) browser 		= "Internet Explorer"
	else if (!checkIt('compatible')) {
		browser = "Netscape Navigator"
		version = detect.charAt(8);
	}
	else browser = "An unknown browser";

	if (!version) version = detect.charAt(place + thestring.length);

	if (!OS) {
		if (checkIt('linux')) OS 		= "Linux";
		else if (checkIt('x11')) OS 	= "Unix";
		else if (checkIt('mac')) OS 	= "Mac"
		else if (checkIt('win')) OS 	= "Windows"
		else OS 						= "an unknown operating system";
	}
}

function checkIt(string) {
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

/*-----------------------------------------------------------------------------------------------*/
Event.observe(window, 'load', init, true);
Event.observe(window, 'load', initialize, false);
Event.observe(window, 'load', getBrowserInfo, false);
Event.observe(window, 'unload', Event.unloadCache, false);

var lightbox = Class.create();

lightbox.prototype = {

	yPos : 0,
	xPos : 0,

	initialize: function(ctrl) {	
		this.content = ctrl.href;
		this.type = ctrl.rel;
		Event.observe(ctrl, 'click', this.activate.bindAsEventListener(this), false);
		ctrl.onclick = function(){return false;};
	},
	
	// Turn everything on - mainly the IE fixes
	activate: function(){	
	if(this.content == ""){
			node = $("lbfake");
			this.content = node;
		}
	var box = $("lightbox");
	if(this.type == "flash"){
		box.type = "flash";
		box.style.width = '600px';
		box.style.height = '650px';
		box.style.marginLeft = '-300px';
		box.style.marginTop = '-325px';
	}
	else if(this.type == "image"){
		box.type = "image";
		box.style.width = '850px';
		box.style.height = '600px';
		box.style.marginLeft = '-440px';
		box.style.marginTop = '-325px';
	}
	else if(this.type == "video"){
		box.type = "video";
		box.style.width = '850px';
		box.style.height = '600px';
		box.style.marginLeft = '-440px';
		box.style.marginTop = '-325px';
	}
	else if(this.type == "betoni"){
		box.type = "betoni";
		box.style.width = '355px';
		box.style.height = '395px';
		box.style.marginLeft = '-200px';
		box.style.marginTop = '-325px';
	}
	else if(this.type == "historiavideo"){
		box.type = "historiavideo";
		box.style.width = '700px';
		box.style.height = '540px';
		box.style.marginLeft = '-350px';
		box.style.marginTop = '-325px';
	}	
	else if(this.type == "lmkhistoriavideo"){
		box.type = "lmkhistoriavideo";
		box.style.width = '670px';
		box.style.height = '505px';
		box.style.marginLeft = '-350px';
		box.style.marginTop = '-325px';
	}
	else if(this.type == "kysely"){
		box.type = "kysely";
		box.style.width = '600px';
		box.style.height = '300px';
		box.style.marginLeft = '-300px';
		box.style.marginTop = '-325px';
	}	
	else{
		box.type = "html";
		box.style.width = '500px';
		box.style.height = '535px';
		box.style.marginLeft = '-250px';
		box.style.marginTop = '-267px';
	}
		if (browser == 'Internet Explorer'){
			this.getScroll();
			this.prepareIE('100%', 'no', '15px');
			this.setScroll(0,0);
			this.hideSelects('hidden');
		}
		this.displayLightbox("block");
	},
	
	// Ie requires height to 100% and overflow hidden or else you can scroll down past the lightbox
	prepareIE: function(height, overflow, padding){
		bod = document.getElementsByTagName('body')[0];
		bod.style.height = height;
		bod.style.paddingRight = padding;
 		bod.setAttribute("scroll",overflow);
		//bod.style.overflow = overflow;
  
		htm = document.getElementsByTagName('html')[0];
		htm.style.height = height;
		htm.setAttribute("scroll",overflow);
		//htm.style.overflow = overflow; 
	},
	
	// In IE, select elements hover on top of the lightbox
	hideSelects: function(visibility){
		selects = document.getElementsByTagName('select');
		for(i = 0; i < selects.length; i++) {
			selects[i].style.visibility = visibility;
		}
	},
	
	// Taken from lightbox implementation found at http://www.huddletogether.com/projects/lightbox/
	getScroll: function(){
		if (self.pageYOffset) {
			this.yPos = self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){
			this.yPos = document.documentElement.scrollTop; 
		} else if (document.body) {
			this.yPos = document.body.scrollTop;
		}
	},
	
	setScroll: function(x, y){
		window.scrollTo(x, y); 
	},
	
	displayLightbox: function(display){
		$('overlay').style.display = display;
		$('lightbox').style.display = display;
		if(display != 'none') this.loadInfo();
	},
	
	// Begin Ajax request based off of the href of the clicked linked
	loadInfo: function() {
		var myAjax = new Ajax.Request(
        this.content,
        {method: 'post', parameters: "", onComplete: this.processInfo.bindAsEventListener(this)}
		);
		
	},
	
	// Display Ajax response
	processInfo: function(response){
		info = "<div id='lbContent' class='box_"+ $('lightbox').type +"'>" + response.responseText + "</div>";
		new Insertion.Before($('lbLoadMessage'), info)
		$('lightbox').className = "done";		
		this.actions();			
	},
	
	// Search through new links within the lightbox, and attach click event
	actions: function(){
		lbActions = document.getElementsByClassName('lbAction');

		for(i = 0; i < lbActions.length; i++) {
			Event.observe(lbActions[i], 'click', this[lbActions[i].rel].bindAsEventListener(this), false);
			lbActions[i].onclick = function(){return false;};
		}

	},
	
	insert: function(e){
	    var pars = Form.serialize('formi');
	    link = Event.element(e);
	    Element.remove($('lbContent'));
	    var myAjax = new Ajax.Request(
	    link.href,
	    {method: 'post', parameters: pars, onComplete: this.processInfo.bindAsEventListener(this)}    	
		);     
    },
	
	deactivate: function(){
		Element.remove($('lbContent'));
		
		if (browser == "Internet Explorer"){
			this.setScroll(0,this.yPos);
			this.prepareIE("100%", "yes", "0");
			//this.prepareIE("100%", "visible");
			this.hideSelects("visible");
		}
		
		this.displayLightbox("none");
	}
}

/*-----------------------------------------------------------------------------------------------*/

// Onload, make all links that need to trigger a lightbox active
function initialize(){
	//alert("Lightboxing");
	addLightboxMarkup();
	lbox = document.getElementsByClassName('lbOn');
	for(i = 0; i < lbox.length; i++) {
		valid = new lightbox(lbox[i]);
		
	}
}
//var flashbox = new lightbox();
//flashbox.ctrl.href = "testing";
//alert(flashbox);
// Add in markup necessary to make this work. Basically two divs:
// Overlay holds the shadow
// Lightbox is the centered square that the content is put into.
function addLightboxMarkup() {	
	bod 				= document.getElementsByTagName('body')[0];
	overlay 			= document.createElement('div');
	overlay.id		= 'overlay';
	lb					= document.createElement('div');
	lb.id				= 'lightbox';
	lb.className 	= 'loading';
	lb.innerHTML	= '<div id="lbLoadMessage">' +
						  '<p>Loading</p>' +
						  '</div>';
	bod.appendChild(overlay);
	bod.appendChild(lb);
}
/*//LB*/
function tooltips(title){	
	if(title == null){
		title = getActiveStyleSheet();
	}
	var tt = $("ttText");
	var f1 = $("f1");
	var f2 = $("f2");
	var f3 = $("f3");
	var f4 = $("f4");
	var f5 = $("f5");
	var css1 = "standardfont";
	var css2 = "biggerfont";
	var css3 = "biggestfont";
	var biggerTxt = "Suurenna teksti&auml; yksi pyk&auml;l&auml;";
	var smallerTxt = "Pienenn&auml; teksti&auml; yksi pyk&auml;l&auml;";
	var printTxt = "Tulosta t&auml;m&auml; sivu";
	var sendTxt = "L&auml;het&auml; sivu yst&auml;v&auml;lle";
	if(tt){
		f4.tt = printTxt;
		f5.tt = sendTxt;
		if(title == css1){
			f1.tt = "";
			f2.tt = f3.tt = biggerTxt;
		}
		else if(title == css2){
			f1.tt = smallerTxt;
			f2.tt = "";
			f3.tt = biggerTxt;
		}
		else{
			f1.tt = f2.tt = smallerTxt;
			f3.tt = "";
		}	
		f1.onmouseover = function(){
		if(this.tt.length > 0){
			tt.style.display = "block";
			tt.style.left = this.offsetLeft + 10+"px"
			tt.innerHTML = this.tt;
			}
		};
		f2.onmouseover = function(){
		if(this.tt.length > 0){
			tt.style.display = "block";
			tt.style.left = this.offsetLeft + 10+"px";
			tt.innerHTML = this.tt;		
			}
		};
		f3.onmouseover = function(){
		if(this.tt.length > 0){
			tt.style.display = "block";
			tt.style.left = this.offsetLeft + 10 + "px";
			tt.innerHTML = this.tt;
			}
		};
		f4.onmouseover = function(){
			tt.style.display = "block";
			tt.style.left = this.offsetLeft - 10 + "px";
			tt.innerHTML = this.tt;
		};
		f5.onmouseover = function(){
			tt.style.display = "block";
			tt.style.left = this.offsetLeft - 20 + "px";
			tt.innerHTML = this.tt;
		};
		f1.onmouseout = f2.onmouseout = f3.onmouseout = f4.onmouseout = f5.onmouseout = function(){
			tt.style.display = "none";
		}
	}
}

function setActiveStyleSheet(title) {
	var i, a, main;
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.attributes["rel"] != undefined){
		var aStyle = a.getAttribute("rel").toLowerCase();
		if(aStyle.indexOf("style") != -1 && a.getAttribute("title")) {
				a.disabled = true;
				if(a.getAttribute("title") == title) a.disabled = false;
			}
		}
	}
	tooltips(title);
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if((a.getAttribute("rel").indexOf("style") != -1 || a.getAttribute("rel").indexOf("Style") != -1) && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {

    if((a.getAttribute("rel").indexOf("style") != -1 || a.getAttribute("rel").indexOf("Style") != -1)
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
fonts = function(e){
	var cookie = readCookie("style");
	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);
}
window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

flashLbClick = function(lbUrl){
	var lbLink = document.getElementById("lbfake");
	lbLink.setAttribute("href", lbUrl);
	if(document.createEvent){
		var evt = document.createEvent("MouseEvents");
		evt.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
		 lbLink.dispatchEvent(evt);
	}
	else if(document.createEventObject ) {
		var evt = document.createEventObject();
		lbLink.fireEvent("onclick");
	}
}

startList = function() {
	if (document.all&&document.getElementById) {
	/*navRoot = document.getElementById("naviList");*/
	navRoot = document.getElementById("SAMenu1");
		for (i=0; i<navRoot.childNodes.length; i++) {
		node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
				this.className+=" over";
				}
				node.onmouseout=function() {
				this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}