// JavaScript Document
var idTimer;
var menu_opacity = new Array();
var menu_dir = new Array();
var menu_size = new Array(100,150,300,50);


function showmessage(id){
	var object = document.getElementById(id);
	object.style.display="block";
	return true;
}

function menu_setup(){
	for(c=0; c<4; c++){
		menu_opacity[c]=0;
		changeOpac(0, 'submenu' + c);
		var e = document.getElementById('submenu' + c).style
		e.display = "block"
		
	}
	
	
	var navigation = document.getElementById('navigation');
	var links = navigation.getElementsByTagName("li");
	
		/* we are only using certain links */
		links[1].onmouseover=function(){menu_direction(0,1)}
		links[1].onmouseout=function(){menu_direction(0,2)}
		links[2].onmouseover=function(){menu_direction(1,1)}
		links[2].onmouseout=function(){menu_direction(1,2)}
		links[3].onmouseover=function(){menu_direction(2,1)}
		links[3].onmouseout=function(){menu_direction(2,2)}
		links[4].onmouseover=function(){menu_direction(3,1)}
		links[4].onmouseout=function(){menu_direction(3,2)}
	
/* ----------------------------------------------------------------------------- */	
	var cnt=0;
	for(var f=0;f<5;f++){

		var navigation = document.getElementById('submenu' + f);
		var links = navigation.getElementsByTagName("li");
	
		for(var i=0; i<links.length;i++){
			links[i].setAttribute("id",cnt);
			links[i].onmouseover = function() {	coloron(this); return false; }
			links[i].onmouseout = function() {	coloroff(this); return false; }
			cnt++;
		}
	
	
	}
		var menus = document.getElementById('submenu0');
		menus.onmouseover=function() { onMouseOver=md2(0,1) }
		menus.onmouseout=function() { onMouseOut=md2(0,2) }
		
		var menus = document.getElementById('submenu1');
		menus.onmouseover=function() { onMouseOver=md2(1,1) }
		menus.onmouseout=function() { onMouseOut=md2(1,2) }
		
		var menus = document.getElementById('submenu2');
		menus.onmouseover=function() { onMouseOver=md2(2,1) }
		menus.onmouseout=function() { onMouseOut=md2(2,2) }
		
		var menus = document.getElementById('submenu3');
		menus.onmouseover=function() { onMouseOver=md2(3,1) }
		menus.onmouseout=function() { onMouseOut=md2(3,2) }
		
		var menus = document.getElementById('submenu4');
		menus.onmouseover=function() { onMouseOver=md2(4,1) }
		menus.onmouseout=function() { onMouseOut=md2(4,2) }
/* ----------------------------------------------------------------------------- */		
	
	if(document.getElementById('shadow')) defineLGEimage();
	
	setInterval ("fademenus()", 10)
	setInterval ( "menuitems()", 30 )
	/* setupfooter(); */
	moveElement("sponsor",sponsorleft,60);
	
}
function defineLGEimage(){
	
	var img = document.getElementById('gallery_lge');
	links = img.getElementsByTagName('img');
	links[0].onclick=function() { showShadow(); return false; }
	var container = document.getElementById('shadow').style;
	container.width = "0";
	container.height = "0";
	changeOpac(75,'shadow');
	
	img = document.getElementById('Limage');
	links = img.getElementsByTagName('img');
	links[0].onclick=function() { hideShadow(); return false; }
	links[1].onclick=function() { hideShadow(); return false; }
	
}
function showShadow(){
	var thumb = document.getElementById('placeholder');
	var src = thumb.getAttribute("target")
	thumb = document.getElementById('placeholder2');
	thumb.setAttribute("src",src);
	
	var container = document.getElementById('shadow').style;
	container.width="800px";
	container.height="1200px";
	container.display="block";
	container = document.getElementById('Limage').style;
	container.height="384px";
	container.width="580px";
	container.display="block";
	return false;
}
function hideShadow(){
	
	var container = document.getElementById('shadow').style;
	container.width="0px";
	container.height="0px";
	container.display="none";
	container = document.getElementById('Limage').style;
	container.height="0px";
	container.width="0px";
	container.display="none";
	return false;
}




function menu_direction(index,dir){
	menu_dir[index]=dir;
	
	if(dir==1) {
			var object = document.getElementById('submenu' + index).style; 
			object.height = menu_size[index] + "px";
			}
}




function md2(index,dir){
	if(menu_opacity[index]) menu_direction(index,dir)
}
function fademenus(){
	for(c=0; c<4; c++){
		
		if(menu_dir[c]==1){
			
			
			menu_opacity[c] += 8;
			if(menu_opacity[c]>=100){
				menu_opacity[c]=100;
				menu_dir[c]=0;
			}
			changeOpac(menu_opacity[c], 'submenu' + c)
		}
		
		if(menu_dir[c]==2){
			menu_opacity[c] -=8;
			if(menu_opacity[c]<=0){
				menu_opacity[c]=0;
				menu_dir[c]=0;
				var object = document.getElementById('submenu' + c).style; 
				object.height = "0px";
			}
			changeOpac(menu_opacity[c], 'submenu' + c)
		}
	
	}
	
}

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 + ")";
	
}


/* -------------------------------------------------------- */
var icolours = Array();
var icolours_shade= Array();

function d2h(d){
	if(d.toString(16) == 0 ) {
		return "00";
		}
	return d.toString(16).toUpperCase();
}

function coloron(whichlink){
	var i = whichlink.getAttribute("id");
	icolours[i] = 1;
	if(!icolours_shade[i]) icolours_shade[i] = 0; /* cc */
}
function coloroff(whichlink){
	var i = whichlink.getAttribute("id");
	icolours[i] = 2;
}

function menuitems(){
	for(cc=0; cc<icolours.length; cc++){
		if(icolours[cc]==1){ /* fade color darker */
			var e=document.getElementById(cc);
			var h = icolours_shade[cc];
			h = h + 24;
			if(h >= 100) {
				h = 100;
				icolours[cc] = 0;
			}
			icolours_shade[cc]=h;
			h = 224 - h;
			var hex = d2h(h);
			e.style.backgroundColor = "#" + hex + "0000";
		}
		
		
		
		if(icolours[cc]==2){ /* fade color lighter */
			var e=document.getElementById(cc);
			var h = icolours_shade[cc];
			h = h - 2;
			if(h <= 0) {
				h = 0;
				icolours[cc] = 0;
			}
			icolours_shade[cc]=h;
			h = 224 - h;
			var hex = d2h(h);
			e.style.backgroundColor = "#" + hex + "0000";
		}
		
		
		
	}
}

/* ------------------------------------------------------------------ */
function showPic(whichpic) {
  if (!document.getElementById("placeholder")) return true;
  
  var source = whichpic.getAttribute("href");
  var target = whichpic.getAttribute("target");
  var placeholder = document.getElementById("placeholder");
  placeholder.setAttribute("src",source);
  placeholder.setAttribute("target",target);
  return false;
  
}

function prepareGallery() {
  if (!document.getElementsByTagName || !document.getElementById) return false;
  if (!document.getElementById("imagegallery")) return false;
  
  var gallery = document.getElementById("imagegallery");
  var links = gallery.getElementsByTagName("a");
  for ( var i=0; i < links.length; i++) {
    links[i].onclick = function() {
      return showPic(this);
	}
  }
}

/* ------------------------------------------------------- */
function moveElement(elementID, sponsorleft, interval){
	
	if(!document.getElementById) return false;
	if(!document.getElementById(elementID)) return false;
	var elem = document.getElementById(elementID);
	
	if(elem.movement) clearTimeout(elem.movement);
	
	
	
	
	
	
	
	if(!elem.style.left) elem.style.left="0px";
	if(!elem.style.top) elem.style.top="0px";
	
	
	var xpos = parseInt(elem.style.left);
	var ypos = parseInt(elem.style.top);
	var repeat = "moveElement('" + elementID + "'," + sponsorleft + "," + interval + ")";
	
	
	if(document.getElementById("shadow")){
		var sd = document.getElementById("shadow").style;
		if(sd.display=="block") {
			setTimeout(repeat,interval);
			return false;
		}
	}
	if(sponsorleft < -1200) {
				sponsorleft=-240;
				xpos=0;
				elem.style.left = "0px";
				var repeat = "moveElement('" + elementID + "'," + sponsorleft + "," + interval + ")";
				setTimeout(repeat,3000);
				return false
		}
	
	if(xpos == sponsorleft) {
		sponsorleft = sponsorleft - 240;
		var repeat = "moveElement('" + elementID + "'," + sponsorleft + "," + interval + ")";
		setTimeout(repeat,3000);
		return false
	}
	
	if(xpos > sponsorleft) {
		var dist = Math.ceil((xpos - sponsorleft)/10);
		xpos=xpos-dist;
	}
	
	elem.style.left = xpos + "px";
	
	elem.movement = setTimeout(repeat,interval);
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

var sponsorleft = -240;

addLoadEvent(menu_setup);
addLoadEvent(prepareGallery);
//addLoadEvent(prepareSlideshow);

