Event.observe(window, "load", InitDefaultPage);
Event.observe(window, "resize", SetDefaultScreenObjects);

var oldobj = null;
var oldindex = -1;
var maxphoto = 10;
var currentpage;
var ph = 768;
var pw = 1024;
var pll = 0;
var plt = 0;


function InitDefaultPage()
{
  
  SetDefaultScreenObjects();   
  ShowScreen();
  SelectPage("nieuws");       
}

function SetDefaultScreenObjects()
{
	pw = parseInt(document.body.clientWidth);
	ph = parseInt(document.body.clientHeight);
	
	var vp = $("viewport");
	var lg = $("logoleft");
	var pl = $("promotionlayer");
	var pa_gb = $("popuparea_gb");
	var pa_ti = $("popuparea_tickets");
	var pa_p = $("popuparea_photo");
	
	if ((vp) && (lg) && (pl)) {
		var vpl = (pw / 2) - 511;
		if (vpl < 0) { vpl = 0 }
		var lgw = 428;
		var lgl = vpl - 57;
		if (lgl < 0) {
		  lgw = lgw + lgl;
		  lgl = 0;	
		} 
		
		var vpt = (ph / 2) - 350;
		if (vpt < 0) { vpt = 0 }
		 lgt = vpt + 78;
	  
	  vp.style.left = vpl + "px";
	  vp.style.top = vpt + "px"; 
	 
	  lg.style.width = lgw + "px";
	  lg.style.left = lgl + "px";
	  lg.style.top = lgt + "px"; 
	  
		pll = lgl + 30;
    plt = (ph / 2) + 200;    
    if (pll < 60) {pll = 60};
		if (plt < 558) { plt = 558; }
	  pl.style.left = pll + "px";	
	  pl.style.top =  plt + "px"; 
	}
	
	if (pa_gb) {
	  var pagbl = (pw / 2) - (Element.getWidth(pa_gb) / 2) + 36;	
	  var pagbt = (ph / 2) - (Element.getHeight(pa_gb) / 2) - 16;
	  if (pagbl < 0) { pagbl = 0; }
	  if (pagbt < 0) { pagbt = 0; }
	  pa_gb.style.left = pagbl + "px";
	  pa_gb.style.top = pagbt + "px"; 	
	}
	if (pa_ti) {
	  var patil = (pw / 2) - (Element.getWidth(pa_ti) / 2) + 36;	
	  var patit = (ph / 2) - (Element.getHeight(pa_ti) / 2) - 16;
	  if (patil < 0) { patil = 0; }
	  if (patit < 0) { patit = 0; }
	  pa_ti.style.left = patil + "px";
	  pa_ti.style.top = patit + "px"; 	
	}
	if (pa_p) {
	  var papl = (pw / 2) - (Element.getWidth(pa_p) / 2) + 36;	
	  var papt = (ph / 2) - (Element.getHeight(pa_p) / 2) - 16;
	  if (papl < 0) { papl = 0; }
	  if (papt < 0) { papt = 0; }
	  pa_p.style.left = papl + "px";
	  pa_p.style.top = papt + "px"; 	
	}	
}


function ShowScreen()
{
  var vp = $("viewport");
	if (vp) {
	  Element.show(vp);
	} 	
	var pl = $("promotionlayer");
	if (pl) {
		pl.style.left = "-250px";
		pl.style.top = ph + 250 + "px";
	  Element.show(pl);
		new Effect.Move(pl, {x:pll, y:plt, mode: 'absolute', duration:2.0, transition: Effect.Transitions.spring });
	} 
}

function ShowVideoLayer()
{
  var st = $("videolayer");
	if (st) {
		Element.show(st);
	  //Effect.Appear(st, {duration: 4.0});	  
	} 	
}

function OverTextLink(obj)
{
	if (obj.getAttribute("selected") != "true") {
	  var image = $("img_" + obj.id);
	  var imagehot = $("img_" + obj.id + "_hover");
	  if ((image) && (imagehot)) {
	    Element.hide(image);
	    Element.show(imagehot);  	
	  } 
	}
}

function OutTextLink(obj)
{
  if (obj.getAttribute("selected") != "true") {
	  var image = $("img_" + obj.id);
	  var imagehot = $("img_" + obj.id + "_hover");
	  if ((image) && (imagehot)) {
	    Element.show(image);
	    Element.hide(imagehot);  	
	  } 
	}
}

function SelectPage(id) 
{
  var obj = $(id);
  if (obj) {
    if (obj.parentNode.id == "topmenu") {
      ClickTopMenu(obj);     	
    } else if (obj.parentNode.id == "bottommenu") {
      ClickBottomMenu(obj);  	
    } else {
      obj = null;	
    }
  }	
  
  ShowVideoLayer();
}

function ClickTopMenu(obj)
{
  if (obj) {
	  //ResetOldMenuItem();
	  SetBottomMenuLine(null);
	  obj.setAttribute("selected", "true");
	  //var image = $("img_" + obj.id);
		//var imagehot = $("img_" + obj.id + "_hover");
		//if ((image) && (imagehot)) {
		//  Element.hide(image);
		//  Element.show(imagehot);  	
		//}
	   
	  SetTopMenuLine(obj);
	  
	  var extension = ".htm";	  
	  if (obj.id == "gastenboek") {
	    extension = ".asp";	
	  }	  
	  var page = "content/" + obj.id + extension;
	  LoadPage(page);
	  oldobj = obj;
	}
}

function ClickBottomMenu(obj)
{
  if (obj) {
	  //ResetOldMenuItem();
	  SetTopMenuLine(null);	  
	  obj.setAttribute("selected", "true");
	  
	  SetBottomMenuLine(obj);
	  var extension = ".htm";	  	  	  
	  var page = "content/" + obj.id + extension;
	  LoadPage(page);	
	  oldobj = obj;
	}
}

function ResetOldMenuItem()
{
	if (oldobj) {
	  oldobj.setAttribute("selected", "false");
	  var image = $("img_" + oldobj.id);
	  var imagehot = $("img_" + oldobj.id + "_hover");
	  if ((image) && (imagehot)) {
	    Element.show(image);
	    Element.hide(imagehot);  	
	  }
	}
}

function SetTopMenuLine(obj)
{
  var topmenuline_left = -600; 
  var topmenuline = $("topmenu_line");  
  if (topmenuline) {
	  if (obj) {
	  	
		  if (obj.id == "nieuws") {
		    topmenuline_left = -542;
		  } else if (obj.id == "band") {
		    topmenuline_left = -484;  		
		  } else if (obj.id == "shows") {
		    topmenuline_left = -422; 	
		  } else if (obj.id == "live-pics") {
		    topmenuline_left = -332;	
		  } else if (obj.id == "music") {
		    topmenuline_left = -272;	
		  } else if (obj.id == "gastenboek") {
		    topmenuline_left = -176;	
		  } else if (obj.id == "shop") {
		    topmenuline_left = -122;		
		  } else if (obj.id == "links") {
		    topmenuline_left = -74;
		  } else if (obj.id == "contact") {
		    topmenuline_left = -5;	
		  } 
		}	  	   	  
  }
  DoMoveLine(topmenuline, topmenuline_left);
}

function SetBottomMenuLine(obj)
{
  var bottommenuline_left = -390;
  var bottommenuline = $("bottommenu_line");
  if (bottommenuline) {	  
	  if (obj) {
		  if (obj.id == "login") {
		    bottommenuline_left = -290;  	
		  } else if (obj.id == "tickets") {
		    bottommenuline_left = -228;  		
		  } else if (obj.id == "hyves") {
		    bottommenuline_left = -110; 	
		  }
		}   	  
  }
  DoMoveLine(bottommenuline, bottommenuline_left);
}

function DoMoveLine(lineobj, xpos)
{
	new Effect.Move(lineobj, { x:xpos , y:23, mode: 'absolute', duration:0.5, transition: Effect.Transitions.sinoidal });
}

function LoadPage(page)
{
  currentpage = page;
  frames["contentframe"].document.location.href = currentpage;	
  //LoadRandomPhoto(page);	
  LoadRandomFadePhoto(page);
}

function LoadRandomPhoto()
{
  photocontainer = $("photoleft");
	if (photocontainer) {
	  var pli1 = $("photoleft_inner1");
	  var pli2 = $("photoleft_inner2");
	  if ((pli1) && (pli2)) {
	  	var index = Math.floor(Math.random()* maxphoto) + 1;
	  	if (index == oldindex) {
	  	  index = index + 1;
	  	  if (index > maxphoto)	{
	  	    index = 1;	
	  	  }	  	  
	  	}
	  	oldindex = index;  	
		  var imgobj = $("photoleft" + index);
		  if (imgobj) {	  	
			  if (pli1.getAttribute("inview") != "true") {
			    pli1.style.left = "-340px";
			    pli1.style.backgroundImage = "url(" + imgobj.src + ")";
			    pli2.style.left = "0px";
			    new Effect.Move(pli2, { x:340 , y:0, mode: 'absolute', duration:0.8, afterFinish: ResetPli });	
			    new Effect.Move(pli1, { x:0 , y:0, mode: 'absolute', duration:0.7 });
			  } else {
			    pli2.style.left = "-340px";
			    pli2.style.backgroundImage = "url(" + imgobj.src + ")";
			    pli1.style.left = "0px"	
			    new Effect.Move(pli1, { x:340 , y:0, mode: 'absolute', duration:0.8, afterFinish: ResetPli });	
			    new Effect.Move(pli2, { x:0 , y:0, mode: 'absolute', duration:0.7 });
			    
			  }
			} else {
			  
			} 
	  }
	}
}

function LoadRandomFadePhoto()
{
  photocontainer = $("photoleft");
	if (photocontainer) {
	  var pli1 = $("photoleft_inner1");
	  var pli2 = $("photoleft_inner2");
	  if ((pli1) && (pli2)) {
	  	var index = Math.floor(Math.random()* maxphoto) + 1;
	  	if (index == oldindex) {
	  	  index = index + 1;
	  	  if (index > maxphoto)	{
	  	    index = 1;	
	  	  }  	  
	  	} 
	  	oldindex = index;	
		  var imgobj = $("photoleft" + index);
		  if (imgobj) {	  	
			  if (pli1.getAttribute("inview") != "true") {
			    pli1.style.backgroundImage = "url(" + imgobj.src + ")";
			    pli1.style.left = "0px";
			    pli2.style.left = "0px";
			    Effect.Fade(pli2, {duration:0.7, afterFinish: ResetPli } );
			    Effect.Appear(pli1, {duration:0.7} );
			  } else {
			    pli2.style.backgroundImage = "url(" + imgobj.src + ")";
			    pli1.style.left = "0px";	
			    pli2.style.left = "0px";
			    Effect.Fade(pli1, {duration:0.7, afterFinish: ResetPli } );
			    Effect.Appear(pli2, {duration:0.7} );			    
			  }
			} else {
			  
			} 
	  }
	}	
}

function ResetPli()
{
  var pli1 = $("photoleft_inner1");
	var pli2 = $("photoleft_inner2");
	if ((pli1) && (pli2)) {
	  if (pli1.getAttribute("inview") != "true") {
	    pli1.setAttribute("inview","true");
	    pli2.setAttribute("inview","false"); 
	  } else {
	    pli1.setAttribute("inview","false");
	    pli2.setAttribute("inview","true"); 	
	  }
	}  	 	
}

function ShowGbPopup()
{
  var popup = $("popuparea_gb");
  if (popup) {
    Effect.Appear(popup, {duration: 1.0, from:0.0, to:0.85} );  	
  }
}

function HideGbPopup()
{
  var popup = $("popuparea_gb");
  if (popup) {
    Effect.Fade(popup, {duration: 1.0, from:0.85, to:0.0} );  	
  }	
}

function ShowTicketsPopup()
{
  var popup = $("popuparea_tickets");
  if (popup) {
    Effect.Appear(popup, {duration: 1.0, from:0.0, to:0.85} );  	
  }
}

function HideTicketsPopup()
{
  var popup = $("popuparea_tickets");
  if (popup) {
    Effect.Fade(popup, {duration: 1.0, from:0.85, to:0.0} );  	
  }	
}

function ShowPhotoPopup(id)
{
  var popup = $("popuparea_photo");
  var popuptitle = $("phototitle");
  if ((popup) && (popuptitle)) { 	
  	if (id) {
      popuptitle.innerHTML = '<img src="content/images/live-pics/' + id + '/titel.gif"/>';
      Element.show(popuptitle);	
    } else {
      Element.hide(popuptitle);	
    }
    Effect.Appear(popup, {duration: 0.5, from:0.0, to:1.0} );     	
  }
}

function HidePhotoPopup()
{
  var popup = $("popuparea_photo");
  var popuptitle = $("phototitle");
  if ((popup) && (popuptitle)) { 	
  	popuptitle.innerHTML = "";
  	Effect.Fade(popup, {duration: 0.5, from:1.0, to:0.0} );  
  } 	
}

function OverClose(obj)
{
  obj.style.textDecoration = 'underline';	
}

function OutClose(obj)
{
  obj.style.textDecoration = 'none';		
}
