var T = new Array();


//--------------------------------------------------------------##


function reset() { // reset screen widgets
	for (var t in T) {
		clearTimeout(t);
	}
}

function browserTest () {
	return document.getElementById || document.all;
}

function init () {
//	window.resizeTo(780,650);
//	window.moveTo((screen.availWidth-780)/2, (screen.availHeight-650)/2 );
//	startSideStory();
	if (browserTest()) {
			var menu = document.getElementById?document.getElementById("mainMenu"):document.all?document.all("mainMenu"):"";
			slide(menu, 1, 20, 0, 30);
	}
}

function slide (o, step, delay, mLeft, mRight) { 
	mLeft = mLeft || 0;
	mRight = mRight || 0;
	if (T[o.id]) {window.clearInterval(T[o.id]); }
	if (step != 0) {
		var p = o.parentNode;
		var stop;
		var start = o.offsetLeft + step;
		step > 0 ?stop = p.offsetWidth-mRight: stop = 0;
		if ( step > 0 ) {
			if ( start < stop ) {
				T[o.id] = setInterval(function () { Slide( o, step, mLeft, mRight) }, delay );
			} else o.style.left = stop +"px";
		}
		else {
			if ( start > stop ) {
				o.style.left = start +"px";
				T[o.id] = setInterval(function () { Slide( o, step, mLeft, mRight) }, delay );
			} else o.style.left = stop +"px";
		}
	}
	return true;
}

function Slide (o, step, mLeft, mRight) {
	mLeft = mLeft || 0;
	mRight = mRight || 0;
	var padding= 18;
	var c = o.parentNode;
	step> 0 ? stop = c.offsetWidth-mRight-padding: stop = 0;
	var pos = o.offsetLeft + step;
	if ( step > 0 ) {
		if ( pos < stop ) {
			o.style.left = pos +"px";
			} else {
				o.style.left = stop +"px";
				window.clearInterval(T[o.id]);
			}
		} else {
		if ( pos > stop ) {
			o.style.left = pos +"px";
			} else {
				o.style.left = stop +"px";
				window.clearInterval(T[o.id]);
			}
		}
}

function ssb (o, stepX, stepY) {
	var posX, posY;
	if (T[o.id]) { window.clearTimeout(T[o.id]) }
//	o.style.backgroundPosition = "50% 0%";
	if (o.style.backgroundPositionY) {
		posX = parseInt(o.style.backgroundPositionX);
		posY = parseInt(o.style.backgroundPositionY);
	} else {
		posX = parseInt(o.style.backgroundPosition.split(" ")[0]);
		posY = parseInt(o.style.backgroundPosition.split(" ")[1]);
	}
	T[o.id] = setTimeout(function() { Ssb( o, posX, stepX, posY, stepY) }, 200);
}

function Ssb(o, posX, stepX, posY, stepY) {
	stepX ? posX += stepX : stepX=0;
	stepY ? posY += stepY : stepY=0;
	posY %= 800;
	posX %= 800;
	if (o.style.backgroundPositionY) 
		o.style.backgroundPositionY = posY +"px"
	else
		o.style.backgroundPosition = posX + "px "+ posY +"px";
	T[o.id] = setTimeout(function() { Ssb(o,posX, stepX, posY, stepY) }, 100);
}


//--------------------------------------------------------------##


function displayBlockz(o, tag) {
	var p = o.parentNode;
	var navList = p.getElementsByTagName(tag);
	if (navList) {
		var L;
		var S = o.id.slice(0,-1);
		for (var i=0; i<navList.length; i++) {
			L=  navList[i].id.slice(0,-1);
			if (L != S) shideDisplay(L, 'none');
		}
		shideDisplay(S, 'block');
	}
}

function shideDisplay(elemID, state) { // create / destroy display blocks
	var LmNt = document.getElementById?document.getElementById(elemID):document.all?document.all(elemID):"";
	if ( LmNt ) {
		if ( state == 'toggle') {
			 if (LmNt.style.display != 'block') {LmNt.style.display = 'block'}
			 else LmNt.style.display = 'none';
		} else
			if (LmNt.style.display != state) LmNt.style.display = state ;
		}
}


//--------------------------------------------------------------##


function startSideStory () {
	var node = document.getElementById?document.getElementById("sideStory"):document.all?document.all("sideStory"):"";
	if (node) {
		node.style.backgroundPosition = "50% 0px"
		node.onmouseover=function() { window.clearTimeout(T[this.id]);}
		node.onmouseout=function() { ssb(this, 2, 0) }
//		alert(node.style.backgroundPosition);
		ssb(node, 2, 0);
	}
}

function startMenu ( menuName ) {
	if (document.getElementById || document.all) {
		var navRoot = false;
		navRoot = document.getElementById?document.getElementById(menuName):document.all?document.all(menuName):"false";
		if (navRoot) {
			navRoot.onmouseover=ieHover;
			navRoot.onmouseout=ieOut;
	//		navRoot.onclick=function() { getLocation( this.getElementsByTagName('A')[0].getAttribute('href') ) };
			if (navRoot) {
				var navList = navRoot.getElementsByTagName("LI");
				var node = "";
				for (var i=0; i<navList.length; i++) {
					node = navList[i];
					node.onmouseover= ieHover;
					node.onmouseout= ieOut
					node.onclick = getLocation;
				}
			}
		}
	}
}

function startSubMenu (id) {
	var navRoot = document.getElementById?document.getElementById(id):document.all?document.all(id):"";
	if (navRoot) {
		var navList = navRoot.getElementsByTagName("LI");
		var node;
		for (var i=0; i< navList.length; i++) {
			node = navList[i];
			node.onmouseover=ieHover;
			node.onmouseout=ieOut;
			node.onclick = function() { displayBlockz( this, "LI"); return false }
			shideDisplay(node.id.slice(0,-1), "none");
		}
		shideDisplay(navList[0].id.slice(0,-1), "block");
	}
}
function startArtistes (id, tag1, tag2) {
	var navRoot = document.getElementById?document.getElementById(id):document.all?document.all(id):"";
	if (navRoot) {
		var navList = navRoot.getElementsByTagName(tag1);
		var node;
		var ref = document.location.href.split("#")[1];
/*		alert(ref); */
		for (var i=0; i< navList.length; i++) {
			node = navList[i];
			node.onmouseover=ieHover;
			node.onmouseout=ieOut;
			node.onmousedown = function() { displayArtiste( this, tag2); return false };
			if (node.id.slice(0,-1) == ref) displayArtiste( node, tag2);
		}
	}
}

function displayArtiste(o, tag) {
	var p = o.parentNode.parentNode;
	var navList = p.getElementsByTagName(tag);
	if (navList) {
		var L;
		var S = o.id.slice(0,-1);
		for (var i=0; i<navList.length; i++) {
			L=  navList[i].id.slice(0,-1);
			if (L != S) {
				 shideDisplay(navList[i].id, 'none')
				}
			else {
				shideDisplay(navList[i].id, 'block');
				navList[i].onclick = function () { this.style.display = "none"; }
			}
		}
	}
}



function menuSlider (id) {
	var menu = document.getElementById?document.getElementById(id):document.all?document.all(id):"";
	T[menu.id] = "";
	var stop = menu.offsetLeft;
	var start="";
	menu.onmouseover= function () { window.clearInterval(T[menu.id]); slide(this, -5, 30, 0, 30) }
//	if (menu.captureEvents) menu.captureEvents(Event.MOUSEOVER);
	menu.onmouseout= function () { window.clearInterval(T[menu.id]); slide(this, 5, 10, 0, 30) } 
//	if (menu.captureEvents) menu.captureEvents(Event.MOUSEOUT);
}

function getLocation (e) {
	if (!e) var e = window.event;
	var n = (window.event) ? e.srcElement : e.target;
	if ( n.getElementsByTagName('A') ) {
		var a = n.getElementsByTagName('A');
		if (a.length > 0) {
				document.location.href = a[0].href;
				e.cancelBubble = true;
				if (e.stopPropagation) e.stopPropagation();
				return false;
			}
		}
	return true;
}

function ieHover (e) { // replace hover in ie
	if (!e) {
		var n = window.event.srcElement;
		n.className = "over";
	}
}
function ieOut (e) { // replace hover in ie
	if (!e) {
		var n = window.event.srcElement;
		n.className = "";
	}
}