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 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) 
{
	var speed = Math.round(millisec / 100);
	var timer = 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 <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

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 resetButtons()
{
	document.getElementById('frontbutton1').className='frontbutton';
	document.getElementById('frontbutton2').className='frontbutton';
	document.getElementById('frontbutton3').className='frontbutton';
	document.getElementById('frontbutton4').className='frontbutton';
	
	document.getElementById('frontpage_block1_id').style.display='none';
	document.getElementById('frontpage_block2_id').style.display='none';
	document.getElementById('frontpage_block3_id').style.display='none';
	document.getElementById('frontpage_block4_id').style.display='none';
	
	document.getElementById('maincontent_block1').style.display='';
	document.getElementById('maincontent_block2').style.display='none';
	document.getElementById('maincontent_block3').style.display='none';
	document.getElementById('maincontent_block4').style.display='none';
	
	//currentOpac('frontpage_block1_id',0,2000);
	//currentOpac('frontpage_block2_id',0,2000);
	//currentOpac('frontpage_block3_id',0,2000);
	//currentOpac('frontpage_block4_id',0,2000);
	
	currentOpac('frontpage_block1_img_id',10,2000);
	currentOpac('frontpage_block2_img_id',10,2000);
	currentOpac('frontpage_block3_img_id',10,2000);
	currentOpac('frontpage_block4_img_id',10,2000);
}
var frontbutton=1;
function changeFrontbutton(nr,resetInterval)
{
	resetButtons();
	document.getElementById('frontbutton'+nr).className='frontbutton_selected';
	document.getElementById('frontpage_block'+nr+'_id').style.display='';
	//document.getElementById('maincontent_block'+nr).style.display='';
	
	//currentOpac('frontpage_block'+nr+'_id',0,2000);
	
	currentOpac('frontpage_block'+nr+'_img_id',100,1000);
	
	if(resetInterval)
	{
		try
		{
			clearInterval(xinterval);
		}
		catch(err)
		{
			
		}
	}
}
function frontButtonChanger()
{
	frontbutton=frontbutton+1;
	if(frontbutton>4)
	{
		frontbutton=1;
	}
	changeFrontbutton(frontbutton,false);
}
// preloading images
if (document.images)
{
  pic1= new Image(0,0); 
  pic1.src="images/frontpage/frontpage_block5.jpg"; 

  pic2= new Image(0,0); 
  pic2.src="images/frontpage/frontpage_block6.jpg"; 

  pic3= new Image(0,0); 
  pic3.src="images/frontpage/frontpage_block7.jpg"; 
  
  pic4= new Image(0,0); 
  pic4.src="images/frontpage/frontpage_block5_over.jpg"; 

  pic5= new Image(0,0); 
  pic5.src="images/frontpage/frontpage_block6_over.jpg"; 

  pic6= new Image(0,0); 
  pic6.src="images/frontpage/frontpage_block7_over.jpg"; 
}
try
{
	var xinterval =setInterval("frontButtonChanger()",3000);
}
catch(err)
{
	
}
