var status = 0;
var bgPosition = 0;
var viewed = "";  // which person was viewed as last, temporary variable to fade up the old entry.
var tempLink = "manifesto"; // save actual position 

var animationDone = true;

// hide all elements which not need yet
function init() {	
	/*if(document.getElementById('backgroundNavigation')) {
		new Effect.Opacity('backgroundNavigation',{duration:0, from:1, to:0});   // background navigation
	}*/

	if(document.getElementById('cases_arrow_left')) {
		new Effect.Opacity('cases_arrow_left',{duration:0, from:1, to:0});   // background navigation arrow
	}
	if(document.getElementById('cases_arrow_right')) {
		new Effect.Opacity('cases_arrow_right',{duration:0, from:1, to:0});   // background navigation arrow
		
	}	
	//hide Person and Cases content for later animation.
	if (navigator.appName == "Microsoft Internet Explorer") {
		getElementsByName_iefix('li','listContent');
	} else {
		
		var listpoints = document.getElementsByName('listContent');

		for (var j=0; j<listpoints.length; j++) {		
			 var id = listpoints[j].getAttribute('id');
			 new Effect.BlindUp(id,{duration:0});
			 
		}
	}
	
	//hide left_right_arrows for later animation.
	if (navigator.appName == "Microsoft Internet Explorer") {
		getElementsByName_iefix('img','cases_arrow_left');
		getElementsByName_iefix('img','cases_arrow_right');
	} else {
		
		var listpoints = document.getElementsByName('cases_arrow_left');

		for (var j=0; j<listpoints.length; j++) {		
			 var id = listpoints[j].getAttribute('id');
			 new Effect.Opacity(id,{duration:0,from: 1.0, to:0});
			 document.getElementById(id).style.display="none";
		}
		
		listpoints = document.getElementsByName('cases_arrow_right');

		for (var j=0; j<listpoints.length; j++) {		
			 var id = listpoints[j].getAttribute('id');
			 new Effect.Opacity(id,{duration:0,from: 1.0, to:0});
			 
		}
	}

}



		
	function getElementsByName_iefix(tag, name) {
     
		 var elem = document.getElementsByTagName(tag);
		 var arr = new Array();
		 for(i = 0,iarr = 0; i < elem.length; i++) {
			  att = elem[i].getAttribute("name");
			  if(att == name) {
				   arr[iarr] = elem[i];
				   iarr++;
					  var id = elem[i].getAttribute('id');
					  new Effect.BlindUp(id,{duration:0});
					 /* if(document.getElementById(id+"Gal")) {
						new Effect.BlindUp(id+"Gal",{duration:0});
					  }*/
			  }
		 }
	
	 
	//document.getElementById('blacklabel').style.display="none";

	}

// BlindDown and BlindUp Effect for Persons and Cases
function listBlind(id) {
	// if a person/case was viewed yet, close it
	if(animationDone) {
		animationDone = false;
	if(viewed != "") {
		document.getElementById(viewed+"_link").style.backgroundImage="none";
		new Effect.BlindUp(viewed,{duration:1,
			afterFinish: function() { 
				
				new Effect.BlindDown(id,{duration:1, 
					afterFinish: function() {
						document.getElementById(id+"_link").style.backgroundImage="url('img/bg_personen.jpg')";
						document.getElementById(id+"_link").style.backgroundPosition="bottom";			
						
					}});
					
			}});
	} else {

				new Effect.BlindDown(id,{duration:1});
				document.getElementById(id+"_link").style.backgroundImage="url('img/bg_personen.jpg')";
				document.getElementById(id+"_link").style.backgroundPosition="bottom";
	}
	
	viewed = id;
	
	animationDone = true;
	}
}

// BlackLabel Scale Effekt
   function ScaleEffect(element,time){
		 
	  if(status == 0) {
			 document.getElementById('subnavi').style.zIndex='50';
			 document.getElementById('maincontent').style.display='none';
			 document.getElementById('blacklabel').style.backgroundImage='none';
			 
 
	      new Effect.Morph(element, {style:
			'background-color:#fff;'+
			'width:568px;'+
			'height:850px;'+
			'min-height:600px;'+
			'padding:40px;'+
			'color:#000;'+
			'overflow:hidden;'+
		    'float:none;'+
			'margin-left:284px;'+
			'text-align:left;'+
			'position:absolute;'+
			// 'z-index:40;'
			'left:324px;'
			, duration:time,afterFinish: function() { 
			 // change css file for blacklabel
			  new Effect.Appear('maincontent');
			 
			document.getElementById('blacklabel_onload').removeAttribute('href');
			
		    document.getElementById('blacklabel_onload').setAttribute('href', 'blacklabel_onclick.css');
		    document.getElementById('blacklabel').style.height="auto";
			if(document.getElementById('field2')) {
				document.getElementById('field2').style.background="#fff";
			}
				
		   
			
		  }});
		
		  
			// disable small white arrows in top right and bottom left corners
		  // document.getElementById('blacklabel_arrow_up').style.display='none';
		  // document.getElementById('blacklabel_arrow_down').style.display='none';

		  
		   
		   // fill whitespace with white background color
		  // document.getElementById('subcontent').style.background='#ffffff';
		  // new Effect.Morph('subcontent',{style:'background:#fff;', duration:4});
		   // allows animation just once
	       status = 1;
		   
	  } 
  }
  
function sliderOnMouseHover(id) {
	new Effect.Opacity(id, {duration:0.5, from:0, to:1});
}

function sliderOnMouseOut(id) {
	new Effect.Opacity(id, {duration:0.5, from:1, to:0.0});
}

function moveClientsImangeBoxInside(id,direction,size) {
	var px = 580;  // picture width
	var pos = isNaN(parseInt(document.getElementById(id).style.left)) ? 0 : parseInt(document.getElementById(id).style.left);  // actual margin position, if NaN than 0
	
	if(animationDone) {
		animationDone = false;
	var movePx = 0;
	// right direction
	document.getElementById('cases_arrow_right_'+id).style.display='block';
	document.getElementById('cases_arrow_left_'+id).style.display='block';
	if(direction == 0) {
		movePx = -px;
		// if it is not the last picture on the right, than move 
		if(pos != ( (size*-1)*px) ) {
			new Effect.Move(id,{x: movePx, y: 0,mode: 'realtive', transition: Effect.Transitions.sinoidal, afterFinish: function() {
			// disable right arrow
		
				if( (pos-px)  == ( (size*-1)*px)) { document.getElementById('cases_arrow_right_'+id).style.display='none'; }
			
			}});
		// if it is the last picture on the right, than move back to the first one
		} else if(pos == ( (size*-1)*px)) {
			new Effect.Move(id,{x: movePx*( (size*-1) ), y: 0, mode: 'realtive', transition: Effect.Transitions.sinoidal, duration:0});
			
		}
	// left direction
	} else if(direction == 1) {
		movePx = px;
		// if it is not the last picture on the left
		if(pos != 0) {
			new Effect.Move(id,{x: movePx, y: 0,mode: 'realtive', transition: Effect.Transitions.sinoidal,afterFinish: function() {
					if( (pos+px)  == ( (size*-1)*px)) { document.getElementById('cases_arrow_left_'+id).style.display='none'; }
			
			}});
		// if it is the last picture on the left, than move back to the last one
		} else {
			new Effect.Move(id,{x: movePx*( (size*-1) ), y: 0, mode: 'realtive', transition: Effect.Transitions.sinoidal, duration:0});
		}
	}
	
	animationDone = true;
	}
	
}


function backgroundHoverNavigationOnMouseOver() {
	new Effect.Opacity('backgroundNavigation', {duration:0.5, from:1.0, to:0});
	//new Effect.Opacity('arrow_bg', {duration:0.5, from:0, to:1.0});
}

function backgroundHoverNavigationOnMouseOut() {
	new Effect.Opacity('backgroundNavigation', {duration:0.5, from:0.0, to:1.0});
	//new Effect.Opacity('arrow_bg', {duration:0.5, from:1.0, to:0.0});
}


// Subfunction to change screen
function changeScreen(section) {
 var linksArray = new Object();
  linksArray["manifesto"] = "menuLinkMANIFESTO";
  linksArray["cases"] = "menuLinkCASES";
  linksArray["netzwerk"] = "menuLinkNETZWERK";
  linksArray["manifesto_temp"] = "menuLinkMANIFESTO";
  linksArray["impTemp"] = "menuLinkMANIFESTO";
  linksArray["konTemp"] = "menuLinkMANIFESTO";
  
						window.location.hash=section;
					//	document.getElementById("changeContent").innerHTML="";//xmlhttp.responseText;
						document.getElementById('blacklabel').style.display="block";
						document.getElementById('news_frameLINK').style.visibility="visible";

						for(description in linksArray) {
								
							if(document.getElementById(linksArray[description])) {
								if(document.getElementById( linksArray[description]).getAttribute('class') == "active") {
									document.getElementById( linksArray[description] ).removeAttribute('class');
								}
							 }
								
						}
						if(document.getElementById( linksArray[section]) ) {
							document.getElementById( linksArray[ section ] ).setAttribute('class', 'active');
						}
						//talktoServer();
						
}

// move To function vor main Navigation
function moveTo(section, subnavi) {

if(animationDone) {
	animationDone = false;
  var pixel = 0;
  var link = "index.php?p=";
  var f = "includes/";
  var newsId = 0;
  tempLink = section;

  
  if(moveTo.arguments.length > 1 ) { subnavi = false; }
  
  if(section == 'manifesto') {
	pixel=(0+bgPosition)*-1;
	link=link+"manifesto";
	f = f + "manifesto/manifesto.php?site=manifesto";
	newsId = 0;
  } /* else if(section == 'personen') {
    pixel=(990+bgPosition)*-1;
	link = link + "personen";
  }  */else if(section == 'cases') {
	pixel=(990+bgPosition)*-1;
	link = link + 'cases';
	f = f + "cases_clients/cases_clients.php?site=cases";
	newsId = 2;
  } else if(section == 'netzwerk') {
	pixel=(1980+bgPosition)*-1;
	link = link + 'netzwerk';
	f = f + "netzwerk/netzwerk.php?site=netzwerk";
	newsId = 3;
  } else if(section == 'impressum') {
	pixel=(3960+bgPosition)*-1;
	link = link + 'impressum';
	f = f + "impressum.php?site=impressum";
	newsId = 10;  // um NewsLinkDiv auszublenden
  } else if(section == 'kontakt') {
	pixel=(5940+bgPosition)*-1;
	link = link + 'kontakt';
	f = f + "kontakt.php?site=kontakt";
	newsId = 10; // um NewsLinkDiv auszublenden
  } else if(section == 'manifesto_temp') {
	pixel=(2970+bgPosition)*-1;
	link = link + "manifesto";
	f = f + "manifesto/manifesto.php?site=manifesto";
	newsId = 0;
  } else if(section == 'impTemp') {
	pixel=(4950+bgPosition)*-1;
	link = link + "manifesto";
	f = f + "manifesto/manifesto.php?site=manifesto";
	newsId = 10;
 } else if(section == 'konTemp') {
	pixel=(6930+bgPosition)*-1;
	link = link + "manifesto";
	f = f + "manifesto/manifesto.php?site=manifesto";
	newsId = 10;
 }
 
  function doMove(displayarrows) {
	 document.getElementById('blacklabel').style.display="none";
	 document.getElementById('backgroundNavigation').style.backgroundImage="none";
	 if(document.getElementById('news_frameLINK')) {
		document.getElementById('news_frameLINK').style.display="none";
	 }
	 
	 var dur = (section == 'impressum' || section == 'kontakt') ? 0:0.8;
	 
	  var showLeftArrow = (section == 'netzwerk' || section == 'cases') ? true : false ;
	  if(showLeftArrow) {
			document.getElementById('subnavi_arrow_left').style.display="block";
		 } else {
			document.getElementById('subnavi_arrow_left').style.display="none";
		 }

		
	 new Effect.Move('imageBoxInside',
			{x: pixel, y: 0,mode: 'absolute', transition: Effect.Transitions.sinoidal, duration: dur, afterFinish: 
					
					function () { 
						
						if(newsId == 10) {
							document.getElementById('news_frameLINK').style.visibility="hidden";
						} else {
							document.getElementById('news_frameLINK').style.display="block";
						}
						loadXMLDoc(f, section, newsId);
						document.getElementById('backgroundNavigation').style.backgroundImage="url(img/transparent.png)";	
						// wenn subnavi parameter gesetzt, dann background noch bewegen
						 // if ( subnavi ) {

							if(section == 'manifesto_temp' || section == 'impTemp' || section == 'konTemp') {
								new Effect.Move('imageBoxInside',
									{x: 0, y: 0,mode: 'absolute', transition: Effect.Transitions.sinoidal,duration:0});
									tempLink = 'manifesto';
							} 
						animationDone = true;
						//  }
					}
					
			});
  }
  
// change css file for blacklabel
		     document.getElementById('blacklabel_onload').removeAttribute('href');
			 document.getElementById('blacklabel_onload').setAttribute('href', 'blacklabel_onload.css');
			 
  if(status == 1) {  // if content was viewed, undo scaling first
  		 
	  if(viewed != "") {
		document.getElementById(viewed+"_link").style.backgroundImage="none";
		new Effect.BlindUp(viewed,{duration:1});
			
	  }
	 document.getElementById('subnavi').style.zIndex="10";
	new Effect.Morph('blacklabel', {style:
			'padding-top:45px;',duration:0, afterFinish: function() {
						new Effect.Morph('blacklabel', {style:
								//'padding-top:45px;'+
								'width:320px;'+
								'height:245px;'+
								'min-height:245px;'+
								 'padding-left:0;'+
								 'padding-bottom:0;'+
								 'padding-right:0;'+
								 'margin-left:440px;'+
								 'text-align:left;'+

								'background-color:#000;'
								
								, duration:0.8,afterFinish: function() { 
									//new Effect.Morph('blacklabel', {style: 'padding-top:45px;'});
								 
								document.getElementById('blacklabel').style.backgroundImage="url(img/blacklabelstatic.png)";
								
								status = 0;
							    doMove(true);
								
							  }})
						}
		}); 
	} else { // if content wasn't viewed, just hide the overlaying blacklabel

		doMove(false);
	}
	

	}
			
}  
//subfunction move To for subnavigation
function moveToSubnavigation(section, direction) {

	if(tempLink == 'manifesto') {
		section = 'cases';
	} else if(tempLink == 'cases') {
		section = (direction == 'right') ? 'netzwerk' : 'manifesto';
	} else if(tempLink == 'netzwerk') {
		section = (direction == 'right') ?'manifesto_temp' : 'cases';
	} else if(tempLink == 'manifesto_temp') {
	    section = 'manifesto';
	} else if(tempLink == 'impressum') {
		section = 'impTemp';
	} else if(tempLink == 'kontakt') {
		section = 'konTemp';
	}
	
	
		tempLink = section;
	moveTo(section,true);
}


function moveBackground(move) {
	var pixel = 990*move;
	var s = "0 0 0 -"+pixel+"px";
	document.getElementById('imageBoxInside').style.margin=s;
	bgPosition = -pixel;
}








/***************************************** AJAX METHODS ************************************************/

function loadXMLDoc(file,section,newsId)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
  
    document.getElementById("blacklabel").innerHTML=xmlhttp.responseText;
		if(newsId != 10) {
			loadXMLNews(newsId, section);
		} else {
			
			changeScreen(section);
			init();
		}
    }
  }
xmlhttp.open("GET",file,true);
xmlhttp.send();
}

function loadXMLNews(id, section)
{
file2 = "includes/getNews.php?site="+id;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp2=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp2.onreadystatechange=function()
  {
  if (xmlhttp2.readyState==4 && xmlhttp2.status==200)
    {
    document.getElementById('news_frameLINK').innerHTML = "";
    document.getElementById("news_frameLINK").innerHTML=xmlhttp2.responseText;
	changeScreen(section);
	
	init();
    }
  }
xmlhttp2.open("GET",file2,true);
xmlhttp2.send();
}
