var time=100;

var prevpage;
var currentpage='';
var H;
var AJAXDATA='';
var EXCLAMATION='!';
var redirect=false;
var prevundefined=true;

function XM(str)
				 {
				 return str.replace('!','');
				 }	

function linkcolor(HH)
				 {
				 //document.getElementById('debug').innerHTML=HH;
				 $("a.selected").removeClass('selected');	
				 if(HH.slice(0,5)=='Clips')
            					{
            					$('a[href*="Clips.htm"]').addClass('selected');
            					}
       if(HH!='Clips'){
							$('a[href*="'+HH+'"]').addClass('selected');
						}	
					}
function preload()
				 {
				 for(var X in menuitems)
				 		{
						if(X!='Kontakt')
								 {
								 $.ajax({
                    type: "GET",
                    url: X+".htm_ajax",
                     dataType: "html",
                    success: function(data){
										var ajx=data.split('***');
                    AJAXDATA+='~-~-~-~-'+data;
                    }
                  });
								 } 
						}
				 }

function fetch(X)
				 {
				 $.ajax({
                    type: "GET",
                    async: false,
                    url: X+".htm_ajax",
                    success: function(data){
                    document.getElementById('stageA').innerHTML=data.split('*-*-*')[1];
                    }
                  });
				 
				 }	
		
function hash()
				 {
				 if(document.location.href.search('#')>0)
      				{
      				var SHASH=document.location.hash.split('#');			
      				if(SHASH.length>1){currentpage=XM(SHASH[1].replace('.htm',''));} 
      				}
				else				 
  						{
      				currentpage=XM(document.location.href.split('.htm')[0].split('.de/')[1]);	
      				}
				 //document.getElementById('debug').innerHTML+=prevpage+' -> '+currentpage;
				}	

function pagechange(type)
				 { 
				 if(prevpage)
				 		{
						prevundefined=false;
						}
				 prevpage=currentpage;	
				 hash();
				 
				 if(currentpage.slice(0,6) =='Clips-')
										{
										
										if(currentpage=='Clips')
														{
														$("#clipA").css("margin-left","-600");
														document.getElementById('clipA').innerHTML='';
														}
												else{
														PAGE('Clips');
														if(!H)
																		{
																		H=currentpage+'.htm';
																		}
        										$("#clipA").css("margin-left","-600");
														document.getElementById('clipA').innerHTML='';
        										$.ajax({
                            type: "GET",
                            async: false,
                            url: 'serveclip_'+H,
                            success: function(data)
        														 {
                            				 document.getElementById('clipA').innerHTML=data;
                            				 //alert('finito');
																		 }
                         		});
        										$("#clipA").animate({"margin-left":600},200);
														try
															 {
															 var myManyPlayers = VideoJS.setup("All");
															 myManyPlayers.play();
															 }catch(e){}
														}
  								  }
				else
										{
										animate_content();
										}
				 linkcolor(currentpage);
				 }

function PAGE(URL)
				 {
				 var pages=AJAXDATA.split('~-~-~-~-');
				 var gotit=false;
				 for(p in pages)
				 					{
									var data=pages[p].split('*-*-*');
									if(URL==data[0].replace (/^\s+/, '').replace (/\s+$/, ''))
														{
														gotit=true;
														document.getElementById('stageA').innerHTML=data[1];
														}
									}
				 if(gotit==false)
				 					{
									return fetch(URL);
									}
				 }

function animate_content()
				 {
				 if(prevundefined)
				 							{
											var alen=100;
											}
					else
											{
											var alen=280;
											}
											
          if(menuitems[XM(currentpage)]>menuitems[XM(prevpage)]) //
          						{var Xa=1900;var Xb=-200;}
          						else
          						{var Xa=-200;var Xb=1900;}
          						var Xn=350;
      		if(currentpage.search('lips')>0)
    								 {
    								 Xn=320;
    								 }
   
          try{
          document.getElementById('stageB').innerHTML=document.getElementById('stageA').innerHTML;
          }catch(e){}
           $("#clipA").animate({"margin-left":Xa*2},alen);
          $("#stageB").css("margin-left",Xn);
          $("#stageA").css("margin-left",Xb);
          $("#stageA").css("opacity",0);
          $("#stageB").css("opacity",1);
      		
          PAGE(currentpage);
          
          $("#stageA").animate({"margin-left":Xn,opacity:1},alen);	
          $("#stageB").animate({"margin-left":Xa,opacity:0},alen);
         
      		try{
          document.getElementById('clipA').innerHTML='';
          }catch(e){}
          
          window.setTimeout("unset()",alen);
				 }
function unset()
				 {
				 try{
				 document.getElementById('cB').innerHTML="";
				 }catch(e){}
				 }			 
function move(it,x,z,offX,time)
				{
	 			var W=$(window).width();
				var dx=Math.round(x/z+offX);
				$('#'+it).animate({'left': dx},time);
				}

				 
window.onstatechange = function(event) 
				{
				pagechange('event');
  			}

jQuery(document).ready(function(){


if(!!(window.history && history.pushState))
					 {
					 EXCLAMATION='';
					 }
					 else
					 {
					 var url=document.location.href.split('.de/')[1];
					 if((url.search('#')<0 || url.search('#')>0) && url.length>0 )
					 		   {
								 redirect=true;
								 //document.getElementById('debug').innerHTML+='redirect';
								 }			
				   }
preload();
hash();



$('a').live('click', function() {
				prevundefined=false;
				H=$(this).attr('href').split('.de/')[1];
				_gaq.push(['_trackPageview', H]);
				
				if(redirect)
								{
								//
								$(this).attr('href',document.location.href.split('.de/')[0]+'.de/#'+H);
								}
				else		{
            		document.location.hash=EXCLAMATION+H;
            			
								linkcolor(H);
             	  return false;
								}
				
				});
$(document).mousemove(function(e){
				
        var W=$(window).width();
        var x= Math.round(-1*(W/2-e.pageX));
        move('redline',x,40,-100,time);	
        move('thomas',x,15,10,time);			
        move('menu',x,20,10,time);				
        move('stageA',x,8,10,time);														 
        move('stageB',x,8,10,time);
				move('clipA',x,4,50,time);
				time=0;
        }); 

})				
////////////////////////////////////////////////////////////

