//var imgArr = ["pool", "sp_glas", "sp_fenster", "flughafen2", "sing_fenster2", "berlint2", "trashplatte2", "w"];
var imgArr = ["pool",  "saoneo", "sing_fenster2", "flughafen2","mavid", "singaindia", "saopalm", "sp_glas", "sp_fenster"];
var bg =  0;
var filename = 0;
var menuSelect = "";

var projArr = [ 'arbeit-sinn-und-sorge.htm', 'ctm10_zeitraffermaschine.htm', '25000+x.htm', 'maschinenraum.htm', 'yellow0409.htm', 'crystalmesh.htm', 'ctm09_structures.htm', 'sh06-08.htm', 'transitions.htm', 'celebration.htm', 'use.htm', 'ctm08_predictable.htm', 'circular.htm', 'breit+schmal.htm', 'nullzeit.htm', 'vergangenheit.htm', 'qcells.htm',  'nothing.htm', 'sh06_praxiskop.htm', 'medea.htm', 'hexity.htm', 'gestortesfruhstuck.htm', 'absolut.htm', 'ctm06.htm'];

var projDokuArr = [ 'weltreise.htm', 'arbeit-sinn-und-sorge.htm', 'crystalmesh.htm', 'sh06-08.htm', 'celebration.htm', 'use.htm'];

var projInstallArr = [  'ctm10_zeitraffermaschine.htm', '25000+x.htm', 'maschinenraum.htm', 'ctm09_structures.htm', 'transitions.htm', 'ctm08_predictable.htm',  'nullzeit.htm',  'sh06_praxiskop.htm', 'gestortesfruhstuck.htm',  'ctm06.htm'];

var projInteraktArr = [  '25000+x.htm', 'sh06_praxiskop.htm'];

var projMedienfArr = [ 'crystalmesh.htm', 'circular.htm', 'breit+schmal.htm', 'hexity.htm'];

var projPerformArr = [  'yellow0409.htm', 'use.htm'];

var projTheaterArr = [  'sh06-08.htm', 'use.htm', 'nullzeit.htm', 'vergangenheit.htm',  'medea.htm', 'hexity.htm', 'gestortesfruhstuck.htm'];

var nextURL = '#';
var prevURL = '#';
var baseURL = 'http://www.autokolor.org/proj/';


function initBG(){     	//aufruf von onload
	menuInit();
	checkBGCookie();			// coockie abfragen
	}
	
function initBGsub(){     	//aufruf von onload
	checkBGCookie();			// coockie abfragen
	checkMenuCookie();			// coockie abfragen
	initPrevNext();
	}
	
	
function getFilename(){
	var fullPath = location.href;
	filename = fullPath.split('\\').pop().split('/').pop();
	}
	
function menuInit(){
	getFilename();
	if (filename == 'projekte_doku.htm'){setMenuselection('doku');}
	else if (filename == 'projekte_installationen.htm'){ setMenuselection('installationen');}
	else if (filename == 'projekte_interaktiv.htm'){ setMenuselection('interaktiv');}
	else if (filename == 'projekte_medienfassaden.htm'){ setMenuselection('medienfass');}
	else if (filename == 'projekte_performance.htm'){ setMenuselection('perform'); }
	else if (filename == 'projekte_theater.htm'){ setMenuselection('theater');}
	else if (filename == 'index.htm'){ setCookie('menuSelect', "",1);}
	else if (filename == 'projekte.htm'){ setCookie('menuSelect', "",1);}
	}

	
function switchBG(){ 		//manueller bg wechsel
	bg++;
	if(bg>imgArr.length-1){bg=0;}
	setCookie('bg',bg,1);
	changeBG(bg);
}

	
	
function changeBG(bgID){		//schreibt den hintergrund
	// Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }  

	var Limg = 'http://www.autokolor.org/img/'+imgArr[bgID]+'_L.jpg';	// bild links
	var Ldiv = document.getElementById("Limg");
	Ldiv.style.background="url("+Limg+") repeat";
    Ldiv.style.height= pageHeight;
	Ldiv.style.width= '202px';
	
	var Mimg = 'http://www.autokolor.org/img/'+imgArr[bgID]+'_M.jpg';														
	var cimg = document.getElementById('centerImg');					// bild in der mitte
	cimg.style.background="url("+Mimg+") repeat-y";
    cimg.style.height= pageHeight;
	cimg.style.width= '90px';
	document.body.background='http://www.autokolor.org/img/'+imgArr[bgID]+'_R.jpg'	// body bg
}


// ____coockie management_____________________________________
function getCookie(c_name){
	if (document.cookie.length>0){
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{ 
		c_start=c_start + c_name.length+1 ;
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length
		return unescape(document.cookie.substring(c_start,c_end));
		} 
	  }
	return ""
}


function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate.toUTCString())+"; path=/";
}

function checkBGCookie(){
	bg =  getCookie('bg');
	if (bg=="" || bg==null) {
		bg = getRandom( 0, imgArr.length-1 );
		setCookie('bg',bg,4);
	  }
	//else {}
	changeBG(bg);
	
}

function checkMenuCookie(){
	menuSelect =  getCookie('menuSelect');
	
	if (menuSelect=="" | menuSelect==null) {}
	else {
	setMenuselection(menuSelect);}
	}


//	macht zufallszahl mit spezifizierbarer range
function getRandom( min, max ) {
	if( min > max ) {
		return( -1 );
	}
	if( min == max ) {
		return( min );
	}
        return( min + parseInt( Math.random() * ( max-min+1 ) ) );
}



function setMenuselection(whichMenu){
	//alert(menuSelect);
	menuSelect=whichMenu;
	var m = document.getElementById(whichMenu);
	m.setAttribute('class','sub_nav_sel');
	setCookie('menuSelect', whichMenu,1);
}


// next prev

Array.prototype.findIndex = function(value){
	var ctr = "";
	for (var i=0; i < this.length; i++) {
	// use === to check for Matches. ie., identical (===), ;
		if (this[i] == value) {
			return i;
			}
		}
	return ctr;
};
	
function initPrevNext(){
	var myArr = "";
	
	if (menuSelect == 'doku'){ myArr = projDokuArr;}
	else if (menuSelect == 'installationen'){ myArr = projInstallArr;}
	else if (menuSelect == 'interaktiv'){ myArr = projInteraktArr;}
	else if (menuSelect == 'medienfass'){ myArr = projMedienfArr;}
	else if (menuSelect == 'perform'){ myArr = projPerformArr;}
	else if (menuSelect == 'theater'){ myArr = projTheaterArr;}
	else {myArr = projArr;}
	
	getFilename();
	var myPos = myArr.findIndex(filename);
	pPos=myPos;
	myPos++;
	if(myPos>myArr.length-1){myPos=0;}
	nextURL=baseURL+myArr[myPos];
	myPos=pPos-1;
	if(myPos<0){myPos = myArr.length - 1;}
	prevURL=baseURL+myArr[myPos];
	//alert (prevURL + " mypos: "+myPos)
	
	//var xy = (pPos+1)+' / '+myArr.length;
	//document.getElementById('pCounter').innerHTML = xy;
	
	 var htmlNext = '<a href="javascript:document.location=nextURL">'+myArr.length+' &gt;</a>';
	 //alert(htmlNext)
	 document.getElementById('bnext').innerHTML = htmlNext;
	 
	 var htmlPrev= '<a href="javascript:document.location=prevURL">&lt; '+(pPos+1)+'</a>';
	 document.getElementById('bprev').innerHTML = htmlPrev;
	
	}
// _________________________




// Unique Random Numbers Picker
// -Picks a number of unique random numbers from an array
// (c) 2002 Premshree Pillai
// http://www.qiksearch.com, http://javascript.qik.cjb.net
// E-mail : qiksearch@rediffmail.com

var numArr = new Array("0","1","2","3","4","5","6","7","8","9"); // Add elements here
var pickArr = new Array(); // The array that will be formed
var count=0;
var doFlag=false;
var iterations=0;

function pickNums(nums)
{
 iterations+=1;
 var currNum = Math.round((numArr.length-1)*Math.random());
 if(count!=0)
 {
  for(var i=0; i<pickArr.length; i++)
  {
   if(numArr[currNum]==pickArr[i])
   {
    doFlag=true;
    break;
   }
  }
 }
 if(!doFlag)
 {
  pickArr[count]=numArr[currNum];
 // document.write('<b>' + numArr[currNum] + '</b> <font color="#808080">|</font> ');
  count+=1;
 }
 if(iterations<(numArr.length*3)) // Compare for max iterations you want
 {
  if((count<nums))
  {
   pickNums(nums);
  }
 }
 else
 {
  location.reload();
 }
}

//pickNums(5); // Call the function, the argument is the number of elements you want to pick.
             // Here we pick 5 unique random numbers


