var fade_speed   = 2000;  // fadeout-speed des intobildes, kürzer = schneller
var fade_timeout = 10000; // wie lange bleiben die bilder stehen?

function dom_init() {
	
	$('ul#navi li:first').addClass('active');	
	
	$('ul#navi li').click( function(){

		$('ul#navi li.active').removeClass('active');				
		$(this).addClass('active')

		var this_category = $(this).find('a').attr('rel');				
		
		$('#content a.' + this_category + ' img')
			.css('opacity', '1')
			.addClass('active')
			
		$('#content a img').not('.active')
			.animate({'opacity' : '0'}, 100)

		$('#content a img.active').removeClass('active')
			
		return false;
		
	
	});
	
	 
	
	
	
	// wenn man von einer projekt seite auf die index seite kommt
	// wird der intro_images container nicht angezeigt
	if( getCookie('show_introimages') == '0' ){
	
		$('#intro_images').css('width', '10px');
	
	}
	
	// intro images container slide left
	$('#arrow_right').click( function(){
		
		setCookie('show_introimages', '0')
		var new_left = $(window).width() - 10 ;		
		$('#intro_images').animate( { width : '10px' }, 500 );
		
	});
	
	// intro images container slide right
	$('#arrow_left.show_introimages').click( function(){
	
		setCookie('show_introimages', '1')
		var window_width	= $(window).width()
		$('#intro_images').animate( { width : window_width + 'px' }, 500 );
		
	});
	
	// vergebe preload classen + lade erstes bild
	$('#intro_images div a').each( function(){
	
		$(this).addClass('preload_me')
		
	});	
	//preloadIntroImage();
	/*@cc_on 
		@if (@_jscript)
			var this_a = ('#intro_images div a.preload_me:first');
			$(this_a)
				.html( '<img src="http://www.conradheise.de/wp-content/uploads/2010/06/4.jpg" />' )
				.removeClass('preload_me')
				.attr('href', '#')
				.find('img')
				.load( function(){
					sizeIntroImagesToWindow( $(this) )
			});
		@else */ 
			preloadIntroImage();
	/* @end @*/

	
	
	// beim resize des fensters wird auch das intoimage scaliert
	$(window).resize( function(){		
		
		sizeIntroImagesToWindow( $('#intro_images a img') );
		
		$('#intro_images').css('width', '');
		
		if( getCookie('show_introimages') == '0' ){
			//var new_width = $(window).width() - 10 ;
			$('#intro_images').css('width', '10px');
		}

				
	});
	
	// fade intro images into each other
	how_many_things_to_fade = 12;
	fadeIntroImages();
	setInterval( "fadeIntroImages()", fade_timeout )	

}

// resize introbild to screen
function sizeIntroImagesToWindow( intro_img ){

	$(intro_img).each( function(){
	
		var window_height	= $(window).height()
		var window_width	= $(window).width()
		
		var img_height		= $(this).height()
		var img_width		= $(this).width()
		
		if( window_height > window_width ){
		
			$(this).css('width', '');
			$(this).css('height', window_height + 'px');
			//alert( 1 )
		
		}
		if( window_width > window_height ){
		
			$(this).css('height', '');
			$(this).css('width', window_width + 'px');
			//alert( 2 )
			
			if( $(this).height() < window_height ){
			
				$(this).css('width', '');
				$(this).css('height', window_height + 'px');
				//alert( 3 )
				//alert( $(this).height() )
			
			}
		
		}

	})
	
}

// fade die intro bilder in einander über
var how_many_things_to_fade = 0;
var first_fade_run_is_done = false;
var i = 0;
function fadeIntroImages( ){
	
	$('#intro_images div a')
		.css('visiblity', 'hidden')
		.css('opacity', '0')
	
	$('#intro_images div a').eq( i )
		.css('visiblity', 'visible')
		.animate( {'opacity' : '1'}, fade_speed );

	i++;
	
	// wenn am ende angekommen wird wieder vorne angefangen
	if( i == how_many_things_to_fade ){
		i = 0;	
	}

}

// preload images function
var intervall = false;
var first_load_run_is_done = false;
function preloadIntroImage (){
	
	var this_a = $('#intro_images div a.preload_me:first');
	$(this_a)
		.html( '<img src="' + $(this_a).attr('href') + '" />' )
		.removeClass('preload_me')
		.attr('href', '#')
		.find('img')
			.load( function(){

				setTimeout( "preloadIntroImage()", 1000 );				
				
				sizeIntroImagesToWindow( $(this) )
				
				if(first_load_run_is_done == true){
				
					intervall == true;			
				
				}
				if(first_load_run_is_done == true && intervall == true){
					
					setInterval( "preloadIntroImage()", fade_timeout );
					
					intervall = false;
					
				}
				first_load_run_is_done = true;
				
					
		});
		
}

// zeit messungs functions
var b=0;
var y;
function startCount1(){

    //document.getElementById('Text1').value=b
    b = b+1;
    y = setTimeout("startCount1()",1000);
	
}

function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}
function getCookie(c_name){

	if (document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1){
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}
