function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function setFinalPage(finalpage) {
      window.location = finalpage;
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec, finalpage) {
        var steps = 50;
	var speed = Math.round(millisec / steps);
	var timer = 0;
        var opac = 0;

	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= steps; i++) {
                opac = 100*i/steps;
		setTimeout("changeOpac(" + opac + ",'" + imageid + "')",(timer * speed));
		timer++;
	}

        // replace page now
        setTimeout("setFinalPage('"+finalpage+"')", (300+millisec));
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec);
} 

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0; i<vars.length; i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
      //  alert('Query Variable ' + variable + ' not found');
}

// place and initiate blending in new image
function place_image_for_transition(i, j, xs, ys, t1, t2) {
	if (j>0) {
		lang = getQueryVariable("language");
		if (j<10) {
			setTimeout ("blendimage('blenddiv','blendimage', 'slides/slide_0"+j+".jpg', "+t1+", 'index.php?language="+lang+"&index="+(j+1)+"')", t2);
		} else {
			setTimeout ("blendimage('blenddiv','blendimage', 'slides/slide_"+j+".jpg', "+t1+", 'index.php?language="+lang+"&index="+(j+1)+"')", t2);
		}
	}
	document.write('<TABLE cellspacing=0 cellpadding=2><TR><TD>');
	if (i<10) {
		slide = 'slide_0'+i;
	} else {
		slide = 'slide_'+i;
	}
	document.write('<DIV style="background-image: url(slides/'+slide+'.jpg); background-repeat: no-repeat; width: '+xs+'px; height: '+ys+'px;" id="blenddiv">');
	document.write ('<img class="slide"  src="slides/'+slide+'.jpg" width='+xs+' height='+ys+' style="width: '+xs+'px; height: '+ys+'px; border: 0 none; filter: alpha(opacity=0); -moz-opacity: 0; opacity: 0;" id="blendimage" alt="" /></DIV>');

	document.write ('</TD></TR>');
	document.write ('</TABLE>');
}

//If the browser is W3 DOM compliant, execute setImageSwaps function
if (document.getElementsByTagName && document.getElementById) {
if (window.addEventListener) window.addEventListener('load', setImageSwaps, false);
else if (window.attachEvent) window.attachEvent('onload', setImageSwaps);
}

//When document loads, apply the prepareImageSwap function to various images with our desired settings
function setImageSwaps() {
//Hover with restore, most basic usage - for any image in document.body that are not yet processed (function accepts elements,too)
prepareImageSwap(document.body);
//Note that once an image is processed, it won't be processed again, so you should set more specific images first, e.g. document.body, as it is the grand
//container, has to be processed last.
}


//The following is the function that do the actual job

function prepareImageSwap(elem,mouseOver,mouseOutRestore,mouseDown,mouseUpRestore,mouseOut,mouseUp) {
//Do not delete these comments.
//Non-Obtrusive Image Swap Script by Hesido.com
//V1.1
//Attribution required on all accounts
	if (typeof(elem) == 'string') elem = document.getElementById(elem);
	if (elem == null) return;
	var regg = /(.*)(_nm\.)([^\.]{3,4})$/
	var prel = new Array(), img, imgList, imgsrc, mtchd;
	imgList = elem.getElementsByTagName('img');

	for (var i=0; img = imgList[i]; i++) {
		if (!img.rolloverSet && img.src.match(regg)) {
			mtchd = img.src.match(regg);
			img.hoverSRC = mtchd[1]+'_hv.'+ mtchd[3];
			img.outSRC = img.src;
			if (typeof(mouseOver) != 'undefined') {
				img.hoverSRC = (mouseOver) ? mtchd[1]+'_hv.'+ mtchd[3] : false;
				img.outSRC = (mouseOut) ? mtchd[1]+'_ou.'+ mtchd[3] : (mouseOver && mouseOutRestore) ? img.src : false;
				img.mdownSRC = (mouseDown) ? mtchd[1]+'_md.' + mtchd[3] : false;
				img.mupSRC = (mouseUp) ? mtchd[1]+'_mu.' + mtchd[3] : (mouseOver && mouseDown && mouseUpRestore) ? img.hoverSRC : (mouseDown && mouseUpRestore) ? img.src : false;
				}
			if (img.hoverSRC) {preLoadImg(img.hoverSRC); img.onmouseover = imgHoverSwap;}
			if (img.outSRC) {preLoadImg(img.outSRC); img.onmouseout = imgOutSwap;}
			if (img.mdownSRC) {preLoadImg(img.mdownSRC); img.onmousedown = imgMouseDownSwap;}
			if (img.mupSRC) {preLoadImg(img.mupSRC); img.onmouseup = imgMouseUpSwap;}
			img.rolloverSet = true;
		}
	}

	function preLoadImg(imgSrc) {
		prel[prel.length] = new Image(); prel[prel.length-1].src = imgSrc;
	}

}

function imgHoverSwap() {this.src = this.hoverSRC;}
function imgOutSwap() {this.src = this.outSRC;}
function imgMouseDownSwap() {this.src = this.mdownSRC;}
function imgMouseUpSwap() {this.src = this.mupSRC;}


// make menu helpers
function AddMenuItem(itemname, link, linkargs, lang) {
	document.write ('<li class="mainmenuitem"><a href="'+link+'?language='+lang+linkargs+'"><img src="menu/'+lang+'/'+itemname+'_nm.png" alt="'+itemname+'" border=0></a></li>');
}

function AddMenuItemPmenu(itemname, link, linkargs, lang) { 
	return 'showmenu='+itemname+';text=<img src="menu/'+lang+'/'+itemname+'_nm.png" alt="'+itemname+'" border=0>;';
}

function AddMenuItemPitem(itemname, link, linkargs, lang) { 
	return 'text=<img src="menu/'+lang+'/'+itemname+'_nm.png" alt="'+itemname+'" border=0>;url='+link+'?language='+lang+linkargs+';';
}

function AddSubMenuItemGr(itemname, link, linkargs, lang) {
	document.write ('<li class="submenuitem"><a href="'+link+'?language='+lang+linkargs+'"><img src="menu/'+lang+'/sub_'+itemname+'_nm.png" alt="'+itemname+'" border=0></a></li>');
}

function AddSubMenuItem(itemname, link, linkargs, lang) {
	document.write ('<li class="submenuitem"><a href="'+link+'?language='+lang+linkargs+'">'+itemname+'</a></li>');
}

