var ie = 0;
var ie7 = 0;
var du_options = new Array();
var du_current=null;

function doinit()
{
	var du;
	var du2;
	var tmp;

	du = $$("div.drop_up");

	for (i=0 ; i<du.length ; i++) {

		du2 = $(du[i]).select("div.drop_up2");
		du_fixMarginTop(du2[0]);
		du2[0].style.display="none";

		var arrow = $(du[i]).select("img.du_arrow");
		arrow[0].src=imageBaseUrl+"/arrow_u.png";

		//get all the options from the drop up box
		tmp = $(du[i]).select("div.du_option");

		//Save inner html of all options
		for (t=0 ; t<tmp.length ; t++)
		{
			var c = (t%2) == 0 ? '#ffffff' : '#f9f9f9';
			tmp[t].style.backgroundColor = c;
			tmp[t].originalBackgroundColor = c;
			du_options[t] = tmp[t].innerHTML;
		}

	}

	document.onclick=du_check;
}


function du_check(e){
	var target = (e && e.target) || (event && event.srcElement);
	var obj = du_current;
	//var obj2 = document.getElementById('sho');
	var cp = du_checkParent(target);
	if(!cp) {
		du_current = null;
	}
	else {
		doinit();
	}
	//target==obj2?obj.style.display='block':null;
}
function du_checkParent(t){
	while(t.parentNode){
		if(t==du_current){
			return false
		}
		t=t.parentNode
	}
	return true
}

function du_fixMarginTop(du2,t)
{
	du2.style.marginTop = "17px";
}

function du_toggle(t)
{

	du2 = t.select("div.drop_up2");
	arrow = t.select("img.du_arrow");

	if (du2[0].style.display == "block")
	{
		du2[0].style.display="none";
		arrow[0].src=imageBaseUrl+"/arrow_u.png";
	}
	else
	{
        doinit();
        du2[0].style.display="block";
		arrow[0].src=imageBaseUrl+"/arrow_d.png";

		du_fixMarginTop(du2[0],t);
	}

	du_current = t;
}

function du_select(t)
{
	if (ie || ie7) du_toggle(t);
}

function du_hover(t, on_or_off)
{
	//change the background and color of text
	if (on_or_off)
	{
		t.style.color = "#000";
		t.style.backgroundColor = "#e5e5e5";
		//t.style.border='1px solid black';
	}
	else
	{
		t.style.color = "#000";
		t.style.border='none';
		t.style.backgroundColor = t.originalBackgroundColor;
	}
}


function selectBackground() {
	var s = getViewportSize();
	var w = s[0];
	var h = s[1];

	var im = new Array();

	im[0] = new Array();
	im[0][0] = 800;
	im[0][1] = 600;

	im[1] = new Array();
	im[1][0] = 1024;
	im[1][1] = 768;

	im[2] = new Array();
	im[2][0] = 1280;
	im[2][1] = 800;

	im[3] = new Array();
	im[3][0] = 1280;
	im[3][1] = 1024;

	im[4] = new Array();
	im[4][0] = 1440;
	im[4][1] = 900;

	im[5] = new Array();
	im[5][0] = 1680;
	im[5][1] = 1050;

	var back = '1024x768';
	for(i=0;i<im.length;i++) {
		back = im[i][0]+'x'+im[i][1];
		if(w < im[i][0]) break;
	}

	//document.body.style.backgroundImage='url('+imageBaseUrl+'/taustakuvat/'+back+'.jpg)';

}
function getViewportSize() {

	 var viewportwidth;
	 var viewportheight;

	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

	 if (typeof window.innerWidth != 'undefined')
	 {
	      viewportwidth = window.innerWidth,
	      viewportheight = window.innerHeight
	 }

	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

	 else if (typeof document.documentElement != 'undefined'
	     && typeof document.documentElement.clientWidth !=
	     'undefined' && document.documentElement.clientWidth != 0)
	 {
	       viewportwidth = document.documentElement.clientWidth,
	       viewportheight = document.documentElement.clientHeight
	 }

	 // older versions of IE

	 else
	 {
	       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
	       viewportheight = document.getElementsByTagName('body')[0].clientHeight
	 }

	 var a = new Array();
	 a[0] = viewportwidth;
	 a[1] = viewportheight;

	 return a;
}


if (document.all && document.styleSheets && document.styleSheets[0] && document.styleSheets[0].addRule)
{
  // Feel free to add rules for specific tags only, you just have to call it several times.
  document.styleSheets[0].addRule('*', 'behavior: url('+jsBase+'pngfix.htc)');
}

