/* PRELOADING IMAGES */

	/* GLOBAL */
	var loaded=0;

	var OS,browser,version,total,thestring;
	checkBrowser();

	// all image paths, to preload them in in row...
	imgSources = new Array (
			'images/psynami_logo.gif',
			'images/fractbg.gif',
			'images/flower.gif',
			'images/zegels2.gif',
			'images/mandala.gif',
			'images/bassid.gif',
			'images/mark.jpg',
			'images/pradox.gif',
			'images/psynami_text.gif',
			'images/kokopelli.gif',
			'images/firespinning.jpg',
			'images/menu_left_shorter_with_buttons_light.gif',
			'images/menu_bars_flipped.gif',
			'images/simsalabim.gif',
			'images/kokopelli.gif',
			'images/bars_cropped_reversed.gif',
			'images/bars_cropped.gif',
			'images/button_welcome.gif',
			'images/button_welcome_over.gif',
			'images/button_presale_down.gif',
			'images/button_presale.gif',
			'images/button_presale_over.gif',
			'images/button_liveacts.gif',
			'images/button_liveacts_over.gif',
			'images/button_liveacts_down.gif',
			'images/button_liveacts.gif',
			'images/button_liveacts_over.gif',
			'images/button_djs.gif',
			'images/button_djs_over.gif',
			'images/button_djs_down.gif',
			'images/button_djs.gif',
			'images/button_djs_over.gif',
			'images/button_guestbook.gif',
			'images/button_guestbook_over.gif',
			'images/button_guestbook_down.gif',
			'images/button_guestbook.gif',
			'images/button_guestbook_over.gif',
			'images/button_contact.gif',
			'images/button_contact_over.gif',
			'images/button_contact_down.gif',
			'images/button_contact.gif',
			'images/button_contact_over.gif',
			'images/menu_only.gif',
			'images/questionmark.jpg',
			'images/jongens_van.gif'
	)

	arImageList = new Array ();

	// actual pre-loading images...
	for (counter in imgSources) {
		arImageList[counter] = new Image();
		arImageList[counter].src = imgSources[counter];
	}


	var entered=0;


	function enter() {
		//entered=1;
		//element = getObj('overall');
		//element.className = 'display';
		showScreen('welcome');
	}


/* VISIBLE ARRAY MANIPULATION */

	/* GLOBAL */

	// default welcome 1 and welcome 2 divs are shown
	var visible = new Array ("welcome1","welcome2");


	/* FUNCTIONS */

	// I keep an array of visual elements in the left and right
	// text area's, so that when selecting an other menu-item
	// we know which visual elements (texts) have to be set to
	// invisible before making the new ones visible...

	// remove element from visible array...
	function removeFromVisibleArray (objname){

		for (var i=0; i < visible.length; i++) {
			if (visible[i] == objname) {
				removeElementFromArray(i);
				break;
			}

		}
	}

	// removes an element x from the visible array...
	function removeElementFromArray(elementnr) {
		for (;elementnr<visible.length;elementnr++) {
			visible[elementnr] = visible[elementnr + 1];
		}
		visible.length=visible.length-1;
	}

	// adds an element to the visible array...
	function addToVisibleArray (objname){
		visible[visible.length] = objname;
	}

	// debug function to know what is currently in the visible array..
	function alertArray (array) {
		var str = '';
		for (var i=0; i < array.length; i++) {
			str += array[i] + '\n';
		}
		alert('visible array : \n' + str);
	}

	// hide all visible elements and (logically) clear the visible array
	// by re-initiating it to a new Array.
	function hideAllVisible () {
		for (var i=0; i < visible.length; i++) {
			switchDisplay(visible[i], 'hide');
		}
		// all visible elements must be off the visible-list
		visible = new Array();
	}



/* DISPLAYING ACTIONS */

	// switch an element to visible ('display') or invisible ('hide')
	function switchDisplay ( objName, hideOrDisplay) {
		element = getObj(objName);
		element.className = hideOrDisplay;
		if (hideOrDisplay == 'display') {
			addToVisibleArray(objName);
		}
	}

	// Sets which elements will be set to visible for a certain 'screen'
	// When someone pushes a button, this method will make sure the correct
	// information is shown in the right text-areas...
	function showScreen(scnname) {

		// remove whatever texts are visible...
		hideAllVisible();

		// depending on the choice, show appropriate text-divs
		if (scnname == 'welcome') {
			switchDisplay("welcome1", "display");
			switchDisplay("welcome2", "display");
		}

		if (scnname == 'location') {
			switchDisplay("location1", "display");
			switchDisplay("location2", "display");
		}

		if (scnname == 'presale') {
			switchDisplay("presale1", "display");
			switchDisplay("presale2", "display");
			//switchDisplay("zegelback", "display shinethrough overall");
		}

		if (scnname == 'liveacts') {
			switchDisplay("liveacts1", "display");
			switchDisplay("liveacts2", "display");
		}

		if (scnname == 'djs') {
			switchDisplay("djs1", "display");
			switchDisplay("djs2", "display");
		}

		if (scnname == 'guestbook') {
			if (loaded == 0) {
				var guestbook = getObj('guestbook');
				guestbook.src="http://psypicnic2009.mygb.nl";
				loaded=1;
			}
			switchDisplay("guestbook", "display");
		}

		if (scnname == 'contact') {
			switchDisplay("contact1", "display");
			switchDisplay("contact2", "display");
		}

	}


/* STATUS BAR MANIPULATION */

	// not used yet, but might be...

	function statusbar(tekst) {
		window.status=tekst;
	}

	function clearStatus() {
		window.status='';
	}

/* IMAGE SIZING */
	function supersizeMe(obj) {
		var element = getObj(obj.id);
		element.width = element.width + 90;
		element.style.zIndex += 10;
		//obj.height = obj.height * 2;
	}

	function smallsizeMe(obj) {
		var element = getObj(obj.id);
		element.width = element.width - 90;
		element.style.zIndex -= 10;
	}

/* WINDOW MANIPULATION */

	// open a new window for links...
	function openInWindow(thisurl) {
		window.open(thisurl, 'Psynami_links', 'width=800,height=600,location=yes,menubar=yes,copyhistory=yes,resizable=yes,scrollbars=yes,toolbar=yes');
	}


	// open a new window for links...
	function openInWindowWithSize(thisurl, mywidth, myheight) {
		if (!(mywidth)) {
			mywidth = 800;
		}
		if (!(myheight)) {
			mymyheight= 800;
		}
		window.open(thisurl, 'Psynami_links', 'width='+mywidth+',height='+myheight+',location=no,menubar=no,copyhistory=no,resizable=yes,scrollbars=yes,toolbar=no');
	}

/* BROWSER INDEPENDANT object fetching */
    function getObj(name)
    {
      if (document.getElementById) {
        return document.getElementById(name);
      } else if (document.all) {
        return document.all[name];
      } else if (document.layers) {
        return document.layers[name];
      }
    }

	function getMax(coordinate) {

		var d=document;
		var xMax=0;
		var yMax=0;

		if (d.getElementById) {
			if (d.documentElement&&d.documentElement.clientHeight) {
  				xMax=d.documentElement.clientWidth;
  				yMax=d.documentElement.clientHeight;
 			} else {
  				xMax=(d.all)?d.body.clientWidth:window.innerWidth;
  				yMax=(d.all)?d.body.clientHeight:window.innerHeight;
 			}
		} else if(d.layers){
 			xMax=window.innerWidth;
 			yMax=window.innerHeight;
		}

		if (coordinate == 'y') {
			return yMax;
		} else if (coordinate == 'x') {
			return xMax;
		} else {
			return 0;
		}
	}

	function safeDivide(number, divider) {
		var remainder = number % divider;
		number = number - remainder;
		return number / divider;
	}

/* MAP 24 Stuff */
	function map24_removeDefaultValues() {
		if (document.link2map24.sstreet.value == 'Street') 	document.link2map24.sstreet.value 	= '';
		if (document.link2map24.szip.value 	  == 'ZIP') 		document.link2map24.szip.value 		= '';
		if (document.link2map24.scity.value   == 'City') 		document.link2map24.scity.value 	= '';

	}


/* Date functions */

	function formatDate(datum) {

	    var day   = datum.substring(3,5);
	    if (day.substring(0,1) == '0') {
			day = day.substring(1,2);
	    }

	    var month = datum.substring(0,2);
	    if (month == '01') { month = 'January';}
	    if (month == '02') { month = 'Februari';}
	    if (month == '03') { month = 'March';}
	    if (month == '04') { month = 'April';}
	    if (month == '05') { month = 'May';}
	    if (month == '06') { month = 'June';}
	    if (month == '07') { month = 'July';}
	    if (month == '08') { month = 'August';}
	    if (month == '09') { month = 'September';}
	    if (month == '10') { month = 'October';}
	    if (month == '11') { month = 'November';}
	    if (month == '12') { month = 'December';}

	    var year  = datum.substring(6,10);

	    return month + ' ' + day + ', ' + year;
	}

	function formatTime(datum) {
		var hh = datum.substring(11, 13);
		var mm = datum.substring(14, 16);
		return hh + ':' + mm;
	}

/* Browser detection */
function checkBrowser() {

	var detect = navigator.userAgent.toLowerCase();

	if (checkIt('konqueror')) {
		browser = "Konqueror";
		OS = "Linux";
	} else if (checkIt('safari')) {
		browser = "safari"
	} else if (checkIt('omniweb')) {
		browser = "omniweb"
	} else if (checkIt('opera')) {
		browser = "opara"
	} else if (checkIt('webtv')) {
		browser = "webtv";
	} else if (checkIt('icab')) {
		browser = "icab"
	} else if (checkIt('msie')) {
		browser = "ie"
	} else if (!checkIt('compatible')) {
		browser = "netscape"
		version = detect.charAt(8);
	} else {
		browser = "unknown";
	}

	if (!version) version = detect.charAt(place + thestring.length);

	if (!OS)
	{
		if (checkIt('linux')) OS = "Linux";
		else if (checkIt('x11')) OS = "Unix";
		else if (checkIt('mac')) OS = "Mac"
		else if (checkIt('win')) OS = "Windows"
		else OS = "an unknown operating system";
	}
}

function checkIt(string)
{
	var detect = navigator.userAgent.toLowerCase();
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

