
	
$(document).ready(function() {
	//Wenn das Dokument fertig geladen ist, gehts los
	check_browser();
	// Newsticker 
	setTimeout("init_ticker()",100); //Google crome braucht ein wenig bis die width ordentlich gesetzt ist
});


////////////////////////////////////////////////
// Ipad unterstützt kein flash -> Weiterleitung  
////////////////////////////////////////////////
function check_browser(){
	is_index = /index.php/i.test(window.location.pathname);
	
	if(is_index){		
		var ua = navigator.userAgent;
		var isiPad = /iPad/i.test(ua) || /iPhone OS 3_1_2/i.test(ua) || /iPhone OS 3_2_2/i.test(ua);
		if(isiPad)	{
			var path=window.location.pathname;			
			var url="http://"+window.location.host+path.substring(0,path.lastIndexOf("/"))+"/start.php"+window.location.search;
			window.location.href = url;						
		}
	}
}



////////////////////////////////////////////
// Code by Sebastian Krimmer 1.03.2011
// Newsticker 
////////////////////////////////////////////


function init_ticker(){
	init_newsticker('newsticker1');
	start_movie();
}


var fps=40;
var steplength=1;

var msg_margin=4;
//var steplength=4;
var intJumpAtzero=0;				
var playticker=0;


var monitor='';
var div_msg1='';
var div_msg2='';


function init_newsticker(id_newsticker){
//1. Kopiere unsichtbare msg mit breitenangabe in Monitor als msg1
//2. Kopiere unsichtbare msg mit breitenangabe in Monitor als msg1 mit relativer position
//3. Starte film
	//cz("#"+id_newsticker+" .msg");
	var msg = $("#"+id_newsticker+" .msg");
	//cz(msg.width());	
	
	monitor=$("#"+id_newsticker+" .monitor");
	var html_msg1='<div class="msg1" style="width:'
								+msg.css('width')
								+';position:relative;top:0px;top:'
								+PxToInt(msg.css('top'))+'px;left:'
								+monitor.css('width')
								+'">'+ msg.html() +'</div>';
	
	
	monitor.append(html_msg1);
	
	var msg2_left=PxToInt(monitor.css('width'))+PxToInt(msg.css('width'))+msg_margin;
	//cz(msg2_left);
	//alert(PxToInt(msg.css('top')));
	var html_msg2='<div class="msg2" style="width:'
								+msg.css('width')
								+';position:relative;top:-'
								+(PxToInt(msg.css('height'))-PxToInt(msg.css('top')))+'px'
								+';left:'
								+msg2_left
								+'px">'+ msg.html() +'</div>';		
	monitor.append(html_msg2);
	
	//Wann wird geh�pft?
	intJumpAtzero=2*PxToInt(msg.css('width'))+msg_margin; 
	
	div_msg1=$("#"+id_newsticker+" .msg1");
	div_msg2=$("#"+id_newsticker+" .msg2");
	
	//Monitor handler
	monitor.mouseover(function(){ pause_movie();});	
	monitor.mouseout(function(){ play_movie();});
	
 }
 
function pause_movie(){
	window.clearInterval(playticker); //bricht den aufruf von film() ab
	playticker=0; 
}
function play_movie(){
	if(playticker==0){
		playticker=setInterval("film()",parseInt(1000/fps));
	}
}
function start_movie(){	
	play_movie();
}

//Verschiebt die beiden divs(msg,msgclone)
//um die Pixelanzahl x nach links
//Verwendet Function: addpixel(str_px, int_y);
function move(x){					
   div_msg1.css('left',addpixel(div_msg1.css('left'), -x));
   div_msg2.css('left',addpixel(div_msg2.css('left'), -x));   					 
}

//Der eigentliche newsticker
//Verwendet funtion: move(x)
function film(){

	if(intJumpAtzero<=0){
		//cz(intJumpAtzero);
		jumpback();
		move(steplength);
	}else{
		move(steplength);
	}
	intJumpAtzero-=steplength;	
}
	
//Setzt die beiden divs(msg,msgclone) auf die startposition
//Verwendet Function: PxToInt(str_px);				
function jumpback(){ 
	            	    
	var int_msg1_left=PxToInt(div_msg1.css('left'));	
	var int_msg2_left=PxToInt(div_msg2.css('left'));
	
	
	
	if(int_msg1_left<int_msg2_left){
		
		div_msg1.css('left',PxToInt(monitor.width())+msg_margin);
				
	}else{
		div_msg2.css('left',PxToInt(monitor.width())+msg_margin);
	}		
	//pause_movie();			
	intJumpAtzero=PxToInt(div_msg2.css('width'));	
	
}					

//Verschiebt die beiden divs(msg,msgclone)
//um die Pixelanzahl x nach links
//Verwendet Function: addpixel(str_px, int_y);
function move_old(x){	
	div_msg1.css('left',(PxToInt(div_msg1.css('left'))-x));
	div_msg2.css('left',(PxToInt(div_msg2.css('left'))-x));	   					 
}

//Addiert auf eine Pixelangabe einen Integerzahl
//und gibt das Ergebnis als string Pixelangabe zurueck
//Verwendet Function: PxToInt(x);
//Bsp.: "30px" + 3 = "33px"
function addpixel(str_px, int_y){										
	return (PxToInt(str_px)+int_y)+'px';
}

//Wandelt eine Pixelangabe einen Integerzahl um
//Return: Int
//Bsp.: "30px"  --> 30
function PxToInt(str_px){
	int_x=0;
	str_px+=' ';//sicherstellen das str_px ein string ist
	str_px=str_px.replace('px', '');
	if(str_px!=' '){
		int_x+=parseInt(str_px);					
	}					
	return int_x;
}	

////////////////////////////////////////////
// F�llt ein Div mit Log-Texten zum debuggen
////////////////////////////////////////////
function cz(text){
	$console=$("#console");
	$console.html($console.html()+text+"<br>");
}
