/*
// File written by Jochen "Khuri" Höhmann <khuri@khuris.com>
// Copyright 2010
//
// File        : module_references_random.js
// Begin       : 2010.02.12 10:26:06
// Last Update : 2010.03.05 09:01:00
*/

var imgb = new Array();
var akti = 0;
var fadeid;
var fadelock = 0;
var banner_play = false;
var banner_textplay = false;
var banner_switchtime = 5000; // the initial wait time for images to switch, 5s
var banner_fadespeed = 50;
var banner_fademultiply = 30;
var pload = false;

// Image switching fade functions
function banner_failsafe() {
	if(pload && banner_play) {
		fade();
		window.clearInterval(banner_failsave_int);
	}
}
function banner_preload(frun) {
	pload = false;
	if(frun == 1) {
		for(i=0;i<imgb_array.length;i++) {
			imgb[i] = new Image();
			imgb[i].src = "user/references/special/"+imgb_array[i]+".jpg";
		}
	}
	for(i=0;i<2;i++) {
		// If first 2 images are cached, start fading loop...
		if(imgb[i].complete == false) {
			pload = false;
			break;
		}
		else {
			pload = true;
		}
	}
	if(!pload) {
		setTimeout("banner_preload(0)",500);
	}/*
	else if(banner_play == true) {
		//switch_imgb(2);
		setTimeout("fade()",0); // launch immediately when images are cached
	}*/
}
function opac(i,what) {
	var object = document.getElementById(what).style;
	object.opacity = (i / banner_fademultiply);
	object.MozOpacity = (i / banner_fademultiply);
	object.KhtmlOpacity = (i / banner_fademultiply);
	object.filter = "alpha(opacity="+(i * (1 / banner_fademultiply * 100))+")";
}
function fade() {
	var timer = 0;
	var j = 1;
	// set a lock on this function
	fadelock = 1;
	if(banner_textplay) {
		setTimeout("opac(0,'ref_textbox')",0);
	}
	setTimeout("opac(0,'ref_image')",0);
	setTimeout("switch_imgb(1);",banner_fadespeed);
	for(i=1;i<=banner_fademultiply;i++) {
		timer++;
		if(banner_textplay) {
			setTimeout("opac("+i+",'ref_textbox');",timer*banner_fadespeed);
		}
		setTimeout("opac("+i+",'ref_image');",timer*banner_fadespeed);
	}
	setTimeout("switch_imgb(2);",timer * banner_fadespeed);
	setTimeout("fadelock=0",timer * banner_fadespeed);
	banner_textplay = false;
	// the new image is loaded after the fade is done + X milliseconds
	setTimeout("fade()",(timer * banner_fadespeed) + banner_switchtime);
}
function switch_imgb(i) {
	if(i == 1) {
		document.getElementById('ref_image').src = imgb[akti].src;
		document.getElementById('ref_plink').href="index.php?id=17&mid="+imgb_array[akti];
		document.getElementById('ref_link').href=imgi[akti];
		document.getElementById('ref_link').innerHTML=imgi[akti].replace(/http:\/\//i,'');
	// switch maps off and on...
		if(!banner_nomap) {
			switch_maplayer();
		}
		if(img_special[akti] == "1") {
			document.getElementById('ref_image').setAttribute('usemap','#special_map');
		}
		else {
			document.getElementById('ref_image').setAttribute('usemap','');
		}
	}
	else {
		document.getElementById('ref_image2').src = imgb[akti].src;
		akti = (akti < (imgb.length -1)) ? (akti +1) : 0;
	}
}

function switch_maplayer() {
	// switch maps off and on...
	refmaps = img_maps[akti].split(",");
	for(y=1;y<img_maps_name.length;y++) {
		switchmap(img_maps_name[y],2);
		document.getElementById('area_'+y).setAttribute("onmouseover",((is_nav || (is_ie && ie_version >= 8.0)) ? "switchmap('"+img_maps_name[y]+"',1);" : function(){switchmap('\''+img_maps_name[y]+'\'',1)}));
		document.getElementById('area_'+y).setAttribute("onmouseout",((is_nav || (is_ie && ie_version >= 8.0)) ? "switchmap('"+img_maps_name[y]+"',2);" : function(){switchmap('\''+img_maps_name[y]+'\'',2)}));
		for(z=0;z<refmaps.length;z++) {
			if(refmaps[z] == y) {
				switchmap(img_maps_name[refmaps[z]],1);
				document.getElementById('area_'+y).removeAttribute("onmouseover");
				document.getElementById('area_'+y).removeAttribute("onmouseout");
			}
		}
	}
}