//Zeitraum News Anzeige
var news_switch = 14000;
var news_switch_aktive = false; 
var news = false;

var bg_image = 0;
var news_pos = -1;
var arr_news = new Array('/images/news/04_osgv.png',
		'/images/news/01_shell.png',
		'/images/news/02_rp.png',
		'/images/news/03_nsg.png'
		);

$(document).ready(function() {

	// Willkommens Screen
	$('#screen_pic').html('<img src="/images/news/willkommen.png" alt="" />')
	
	// Light switch
	$('#switch').click(function() {
		
		/*if(bg_image == 0){
			$('#wrap2').css('background-image', 'url(/images/02_start_hell.jpg)');
			$('#navigation,#trepose_logo').css('visibility','visible');
			$('body').css('background-color','#000');
			bg_image = 1;
		}else if (bg_image == 1){
			$('#wrap2').css('background-image', 'url(/images/03_start_hell.jpg)');
			$('body').css('background-color','#fff');
			bg_image = 2;
		}else{
			$('#wrap2').css('background-image', 'url(/images/01_start.jpg)');
			$('#navigation,#trepose_logo').css('visibility','hidden');
			$('body').css('background-color','#000');
			bg_image = 0;
		}*/
		if(bg_image == 0){
			$('#wrap2').css('background-image', 'url(/images/03_start_hell.jpg)');
			$('#navigation,#trepose_logo,#team, #aufsteller').css('visibility','visible');
			$('body').css('background-color','#fff');
			start_news();
			bg_image = 1;
		}else{
			$('#wrap2').css('background-image', 'url(/images/01_start.jpg)');
			$('#navigation,#trepose_logo,#team, #aufsteller').css('visibility','hidden');
			$('body').css('background-color','#000');
			$('#screen_pic').html('<img src="/images/news/willkommen.png" alt="" />')
			window.clearTimeout(news_switch_aktive);
		    window.clearTimeout(news);
			bg_image = 0;
		}
		
	});
	
	
	//Navigation
	$("#agentur_link,#referenzen_link,#news_link").mouseover(function() {
		$('#'+$(this).attr('id')+' img').attr('src', '/images/buttons/btn_'+$(this).attr('id')+'_act.png');		
	})
	
	$("#agentur_link,#referenzen_link,#news_link").mouseout(function() {
		$('#'+$(this).attr('id')+' img').attr('src', '/images/buttons/btn_'+$(this).attr('id')+'.png');		
	})
	
	$('#agentur_link,#referenzen_link,#news_link').click(function(){
		switch($(this).attr('id')){
			case 'agentur_link': switch_screen_notNews('/images/news/vielen_dank.png'); break;
			case 'referenzen_link': switch_screen_notNews('/images/news/vielen_dank.png'); break;
			case 'news_link': if(news_switch_aktive == false)start_news(); break;
			//case 'switch': if(news_switch_aktive == false)start_news(); break;
			default: switch_screen(null); break;
			
			//$('#'+$(this).attr('id')+' img').attr('src', '/images/buttons/btn_'+$(this).attr('id')+'_act.png');
		}
		
		
		if('#'+$(this).attr('id') == '#agentur_link'){
			$('#referenzen_link img').attr('src', '/images/buttons/btn_referenzen_link.png');
			$('#news_link img').attr('src', '/images/buttons/btn_news_link.png');
		}else if('#'+$(this).attr('id') == '#referenzen_link'){
			$('#agentur_link img').attr('src', '/images/buttons/btn_agentur_link.png');
			$('#news_link img').attr('src', '/images/buttons/btn_news_link.png');
		}else if('#'+$(this).attr('id') == '#news_link'){
			$('#referenzen_link img').attr('src', '/images/buttons/btn_referenzen_link.png');
			$('#agentur_link img').attr('src', '/images/buttons/btn_agentur_link.png');
		}
		
		
		
		$("#agentur_link,#referenzen_link,#news_link").mouseout(function() {
			$('#'+$(this).attr('id')+' img').attr('src', '/images/buttons/btn_'+$(this).attr('id')+'.png');		
		})
		
		$('#'+$(this).attr('id')).unbind('mouseout');

	})
	
	// Trepose Logo
	$("#trepose_logo").click(function() {
		//if(news_switch_aktive == false)start_news();
		switch_screen_notNews('/images/news/willkommen.png');
	})	
	
	// Logos
	$("#logos div").mouseover(function() {
		bg_image != 0 ? $('#'+$(this).attr('id')+' > img').css('visibility', 'visible') : '';
	})
	
	$("#logos div").mouseout(function() {
		bg_image != 0 ? $('#'+$(this).attr('id')+' > img').css('visibility', 'hidden') : '';
	})
	
	$("#logos div").click(function() {
		bg_image != 0 ? switch_screen_notNews('/images/news/vielen_dank.png') : '';
	})
	
	
	// Team
	$("#team").click(function(){
		switch_screen_notNews('/images/news/vielen_dank.png');
	})
	
	// Aufsteller
	$("#aufsteller").click(function(){
		switch_screen_notNews('/images/news/vielen_dank.png');
	})

	// Impressum
	$("#impressum").click(function() {
		
		if($("#impressum_div").css('visibility') == 'visible'){			
			$("#impressum_div").css('visibility','hidden');
		}else{
			// Overlay
			/*var layer = $("<div id=\"overlay\"></div>");
			$("body:last").append(layer);			
			$("#overlay").css({'position':'relative', 'top':'0px', 'left':'0px', 'height':'100%', 'width':'100%', 'zindex':'100', 'background':'red'});
			*/
			$("#impressum_div").css('visibility','visible');
		}
	})
	
	// Impressum
	$("#kontakt").click(function() {
		switch_screen_notNews('/images/news/kontakt.png');
	})
	
	$("#switch, #navigation a, #trepose_logo, #logos div, #channel_left, #channel_right").click(function() {
		$("#impressum_div").css('visibility','hidden');
	})
	
	// Screen navigation
	$("#channel_left").click(function(){
		//news_switch_aktive = false;
		window.clearTimeout(news_switch_aktive);
		window.clearTimeout(news);
		news_pos = (news_pos <= 0 ? (arr_news.length-1) : (news_pos-1));
		switch_screen(arr_news[news_pos]);
	});

	$("#channel_right").click(function(){
		//news_switch_aktive = false;		
		window.clearTimeout(news_switch_aktive);
		window.clearTimeout(news);
		news_pos = (news_pos >= (arr_news.length-1) ? 0 : (news_pos + 1));
		switch_screen(arr_news[news_pos]);
	});
	
	// News Intervall unterbrechen
	$("#trepose_logo, #agentur_link, #referenzen_link, #logos, #team, #aufsteller, #kontakt, #impressum, #logos div").click(function() {
		window.clearTimeout(news_switch_aktive);
		window.clearTimeout(news);
		news_switch_aktive = false;
	})
	
	// News Intervall unterbrechen (Monitor-Buttons)
	$("#channel_left, #channel_right").click(function() {
		window.clearTimeout(news_switch_aktive);
		news_switch_aktive = false;
	})


});


// Screen functions
/*function switch_screen(picture){
	$('#screen_pic').html('<img src="/images/rauschen_compl.gif" alt="" />')
	setTimeout("screen_picture('"+picture+"')", 250);
}*/

function switch_screen(picture){
	$('#screen_pic').html('<object style="margin-left:-31px;margin-top:-5px;" type="application/x-shockwave-flash" data="/images/monitor.swf" width="320" height="175" style="-moz-user-focus:ignore;"><param name="movie" value="/images/monitor.swf" /><param name="wmode" value="transparent"/></object>	');
	news = window.setTimeout("screen_picture('"+picture+"')", 4000);
	
}
function switch_screen_notNews(picture){
	$('#screen_pic').html('<img src="/images/rauschen_compl.gif" alt="" />')
	setTimeout("screen_picture('"+picture+"')", 250);
}

function screen_picture(picture){
	if(picture == 'null')
		$('#screen_pic').html('<img src="/images/news/vielen_dank.png" alt="" />')
	else
		$('#screen_pic').html('<img src="'+picture+'" alt="" />')
}

function start_news(){
		news_pos = (news_pos >= (arr_news.length-1) ? 0 : (news_pos + 1));
		switch_screen(arr_news[news_pos]);	
		news_switch_aktive = window.setTimeout("start_news('"+arr_news[(news_pos+1)]+"')", news_switch);	
}

