/*
* Aktualisierte Version für Mootools
* 21.05.2009 10:50:05
* g.gothe@westhost.de
*/


function swapin(tagID,i,maxi) {
  i = i-1;
  maxi = maxi-1;
  for (var a=0;a<=maxi;a++) {
    if (i == a) {
      document.getElementById(tagID).getElementsByTagName("li")[a].id='active';
//      $(tagID).getElement('li')[a].id='active';
    } else {
      document.getElementById(tagID).getElementsByTagName("li")[a].id='';
//      $(tagID).getElement('li')[a].id='';
    }
  }
}

//----------------------------------------------------------------------------------------//
// hinzufügen von css-dateien, einige Browser (z.B. ie) machen Probleme, wenn der CssLink nicht im header steht. Doppelte Header verstehen sie auch nicht.
function changeCSS (url) {

  var cssBasePath = 'fileadmin/css/modifications/';
  var cssFile = 'basemod_mission_aktuell.css';
  var id = 8;
  var bodyElement = $(document.body);
  var myCSSFile = '';
  var myIdArray;

  if (url.match(/index\.php\?id=[0-9]+/)) {
  //this is the default
    id = parseInt( url.match(/[0-9]+/) );
  } else if (url.match(/\.html/)) {
  //in case of Simulate Static

      myIdArray = url.match(/\d+\.\d+\.html/).toString();
      myIdArray = myIdArray.match(/\d+/g);
      id = myIdArray[0];
      type = myIdArray[1];

  }

    switch(id)
    {
      case 8:
      //Mission
        cssFile = 'basemod_kunden.css';
//        cssFile = 'basemod_mission_aktuell.css';
        break;
      case 15:
      case 27:
//        cssFile = 'basemod_kunden.css';
        cssFile = 'basemod_mission.css';
        break;
      case 6:
      case 14:
//        cssFile = 'basemod_knowhow.css';
        cssFile = 'basemod_kunden.css';
        break;
      case 7:
        cssFile = 'basemod_kunden.css';
          break;
      case 29:
        cssFile = 'basemod_kunden.css';
//        cssFile = 'basemod_crew.css';
          break;
      case 69:
      case 33:
        cssFile = 'basemod_links.css';
        bodyElement.setStyle('background-image','url(../../img/bg_links.jpg)');
          break;
      case 31:
        cssFile = 'basemod_kontakt.css';
        bodyElement.setStyle('background','transparent url(../../img/bg_kontakt.jpg) no-repeat static center 375px;');
          break;
      case 30:
        cssFile = 'basemod_impressum.css';
        bodyElement.setStyle('background-image', 'url(../../img/bg_mission.jpg)');
          break;
      default:
    }

myCSSFile = cssBasePath + cssFile;
document.getElementsByTagName("link")[2].href = myCSSFile.toString();

}
//----------------------------------------------------------------------------------------//
// prototype: laden der inhaltsseiten main
function getHTML(myUrl) {

  var myContainer = $('placeholder');

	getMyHTML(myUrl,myContainer);
}

/*
* myUrl, string               URL to retrieve
* targetElement, string       Element to load Content into
* indicatorElement, string    Element to change class depending on request state
*/
function getMyHTML(myUrl,targetElement,indicatorElement) {

  var myIndicator = new Element('div', {id: 'indicator'});
  var backup;

  new Request.HTML({
    method:'get',
//    url:myUrl+"?type=12",
    url:myUrl,
    evalResponse: true,
    evalScripts: false,
    autoCancel: true,
    onRequest: function() {
//console.log ('request started');
    	//backup = targetElement.getProperty('html');

/*
    	if (targetElement.getProperty('id') = 'placeholder') {
        targetElement.set('html', '');
      }
*/

    },
    onFailure: function(xhr) {
//console.log ('request error');
    	alert('The request to ' + myUrl + ' failed.' + "\n" + 'Please try again later');
    },
    onComplete: function(responseTree, responseElements, responseHTML, responseJavaScript) {
//console.log ('request complete');

			changeCSS(myUrl);
			myIndicator.dispose();
    	targetElement.set('html', responseHTML);
    }
  }).send();
}
function preloadImages(images,targetElement) {

var imageArray = [];

var i = 0;
images.each( function(im) {
  imageArray[i] = im.src;
  i=i+1; 
});

  var loader = new Asset.images(imageArray, {
  
    onComplete: function() {
        if (!Browser.Engine.trident) { targetElement.fade('in'); }
    }
  });

}

//----------------------------------------------------------------------------------------//
// prototype: laden der inhaltsseiten col3
function getHTML2(myUrl) {

  myContainer2 = $('placeholder2');

	getMyHTML(myUrl,myContainer2);

}
//----------------------------------------------------------------------------------------//
// bedingung: startseite wird immer geladen, egal welche url eingegeben wird. Unterseiten werden automatisch nachgeladen
function start() {

  var myIndicator = new Element('div', {id: 'indicator'});
  myIndicator.inject($('placeholder'));

  if ((window.location.pathname != "")&&(window.location.search !="")&&(window.location.search != '?id=4')&&(window.location.search != '?moonid=4')) 
	{
		var myString = window.location.search;
		var myPathString = window.location.pathname;
		var tlink = myPathString.substr(1,myPathString.length)+'?'+myString.substr(5,myString.length);
    getHTML(tlink);
	} else {
		getHTML("index.php?id=8?type=12");
	}
}
//----------------------------------------------------------------------------------------//
// menu für col1_content
function movedown() {
var speed=18

iens6=document.all||document.getElementById

	if (iens6){
		var crossobj=document.getElementById? document.getElementById("mainMenu") : document.all.content
		var contentheight=crossobj.offsetHeight
	}
	if (window.moveupvar) clearTimeout(moveupvar)
	if (iens6&&parseInt(crossobj.style.top)>=(contentheight*(-1)+270))
		crossobj.style.top=parseInt(crossobj.style.top)-speed+"px"
	//movedownvar=setTimeout("movedown()",20)
}

function moveup(){
var speed=18

iens6=document.all||document.getElementById

	if (iens6){
		var crossobj=document.getElementById? document.getElementById("mainMenu") : document.all.content
		var contentheight=crossobj.offsetHeight
	}
	if (window.movedownvar) clearTimeout(movedownvar)
	if (iens6&&parseInt(crossobj.style.top)<0)
		crossobj.style.top=parseInt(crossobj.style.top)+speed+"px"
	//moveupvar=setTimeout("moveup()",20)
}

