function setWidth() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
//	window.alert( 'Width = ' + myWidth);
//	window.alert( 'Height = ' + myHeight );	

var realWidth = myWidth -60;
	document.getElementById("content-inner").style.width = realWidth+"px";
//	document.getElementById("viiva").style.width = realWidth+"px";
//	document.getElementById("content-inner").style.border="1px solid red";
}


function hover(nimi) {
	if (paikka==nimi) {
		document.getElementById(nimi).src='gfx/n-'+nimi+'_over.png';
	} else {
		document.getElementById(nimi).src='gfx/n-'+nimi+'_over.png';
	}
}
function normal(nimi) {
	if (paikka==nimi) {
		document.getElementById(nimi).src='gfx/n-'+nimi+'_on.png';
	} else {
		document.getElementById(nimi).src='gfx/n-'+nimi+'_off.png';
	}
}


function backGround(tausta) {
	document.body.style.backgroundImage='url(gfx/bg-'+tausta+'.jpg)';
}



var exists;
var allStretch;

//the main function, call to the effect object
function init(){
	var divs = document.getElementsByClassName("stretch");
	allStretch = new fx.MultiFadeSize(divs, {duration: 200});

	items = document.getElementsByClassName("display");
	for (i = 0; i < items.length; i++){
		var h3 = items[i];
		div = h3.nextSibling;
		h3.title = h3.className.replace("display ", "");

		if (window.location.href.indexOf(h3.title) < 0) {
			allStretch.hide(div, 'height');
			if (exists != true) exists = false;
		}
		else exists = true;

		h3.onclick = function(){
			allStretch.showThisHideOpen(this.nextSibling, 100, 'height');
		}
	}
	// This code breaks, because (according to Prototype Lite, at least ) childNodes
	// contains comments, as well:
	// if (exists == false) $('block-news').childNodes[1].fs.toggle('height');
	
	if( exists == false ) {
		var kids = $('block-news').childNodes;
		for( var i = 0 ; i < kids.length ; ++i ) {
			if( kids[i].className == 'stretch' ) {
				setTimeout( function() { kids[i].fs.toggle('height') } , 100 );
				break;
			}
		}
	}
}

function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}

function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}


function hide(el) {
	el_obj = document.getElementById(el)
	el_obj.style.display = 'none';
}

function show(el) {
	el_obj = document.getElementById(el)
	el_obj.style.display = 'block';
}



//jQuery plugin - dynamic email transformer / spam preventor.
// takes text from inside the link and transforms it to mailto:-url
//like this: <a href="#whatever" class="emailMaybe">myaddress (at) mydomain.com</a> becomes
//<a href="mailto:myaddress@mydomain.com" ...
(function(jQuery){
  jQuery.fn.extend({
    textToMailTo:function() {
	return this.each(function(){
	  this.href = 'mailto:'+ jQuery.trim(jQuery(this).text().replace(/\s?\(at\)\s?/,'@'));
	});
    }
  });
}) (jQuery);

//do the email transform
jQuery(function(){
  jQuery('.email').textToMailTo();
}) 
