/*
window.addEvent('domready', function(){
	//
});
*/

function addJavascript(jsname,pos) {
	var th = document.getElementsByTagName(pos)[0];
	var s = document.createElement('script');
	s.setAttribute('type','text/javascript');
	s.setAttribute('src',jsname);
	th.appendChild(s);
}

function includeCSS(p_file) {
	var v_css  = document.createElement('link');
	v_css.rel = 'stylesheet'
	v_css.type = 'text/css';
	v_css.href = p_file;
	document.getElementsByTagName('head')[0].appendChild(v_css);
}

function arrayShuffle(){
	var tmp, rand;
	for(var i =0; i < this.length; i++){
		rand = Math.floor(Math.random() * this.length);
		tmp = this[i]; 
		this[i] = this[rand]; 
		this[rand] =tmp;
	}
}

Array.prototype.shuffle =arrayShuffle;

var csspath = "/imageslider/css/";
var jspath = "/imageslider/js/";

addJavascript(jspath + 'mootools.js','head');
includeCSS(csspath + "imageMenu.css");
addJavascript(jspath + 'imageMenu.js','head');
addJavascript(jspath + 'NLB_bgFade.js','head');

function mixSlides(imageFiles, imageUrls, fixAction) {
	
	keys = new Array();
	
	if(fixAction) {
		slideStart = 1;
	}
	else
		slideStart = 0;
	
	for (var i = slideStart; i < imageFiles.length; i++) {
		keys.push(i);
	}
	keys.shuffle();
	
	if(fixAction) {
		actionKey = new Array();
		actionKey.push(0);
		keys = actionKey.concat(keys);
	}
	
	//max = keys.length;
	max = 5;
	
	for (var i = 0; i < max; i++) {
		id = "slidef" + i;
		k = keys[i];
		document.getElementById(id).style.backgroundImage = "url(/imageslider/img/" + imageFiles[k] + ")";
		if(imageUrls[k] != "")
		document.getElementById(id).href=imageUrls[k];
		else
		document.getElementById(id).href="#";
	}
}

function fadeColor (object, go) {
	var duration = 400;
	var id = object.id;
	var number = id.substring(id.length-1, id.length);
	var color;

	switch (number) {
		case "0": color = "#FF0000"; break;
		case "1": color = "#FFFF33"; break;
		case "2": color = "#00CCFF"; break;
		case "3": color = "#FFC125"; break;
		case "4": color = "#00FF00"; break; //#00FFFF
		default: color = "#FF0000"; 
	}

	if(go)
	NLBfadeBg(id,'#FFFFFF',color,duration);
	else
	NLBfadeBg(id,color,'#FFFFFF',duration);
}
