/************** Document Ready ****************/
	$(function(){
		// $('#mainitem').center({parentElement: '#content', center_y: false});
		// $('a[rel*=facebox]').facebox();
		// hide_items(false);
		// $('#content').dv2_gridAlign();
		
		
		// $(".breadCrumb").jBreadCrumb()
		
		init_CSS();
		show_items('home');
		
		
		
		$('.controllerLinks a').bind("click", function(){
			var href = ($(this).attr("href")).substr(1);
			if (!$(this).hasClass("static") && href.indexOf('#')>=0) {
				var itemClass = href.substr(href.indexOf('#')+1);
				toggle_items(itemClass);
				return false;
			}
			else return true;
		});
		
		
		$('.hyper_linkliste').hyper_linkliste({	color_normal: "000000",
            									color_hover: "f2b2cf",
												speed: 300,
												activeClass: "active"
											});
		init_slideImages();
									
	});
/************** Document Ready ****************/








/************** Spezielle Funktionen ****************/

	

	
	// Für die items mit den Kundenlogos
	function init_slideImages() {
		$('.slideImage').addClass("pink");
		$('.slideImage .has_image').css("overflow", "hidden").css("position", "relative").css("height", "125px");
		$('.slideImage .has_image img').css("position", "absolute").css("top", "0px").css("left", "0px");
		// $('.slideImage .link').hide();
		$('.slideImage .title').css("position", "static").addClass("pink");
		
		$('.slideImage').mouseenter(function(){
			$(".has_image img", this).stop().animate({
				left: "175px"
			}, "fast");
		}).mouseleave(function(){
			$(".has_image img", this).stop().animate({
				left: "0px"
			}, "fast");
		});
	}
	

	
	function init_CSS() {
		$("#mainitem").css({
							position: "absolute",
							left: "0px",
							top: "10px",
							margin: "0px",
							float: "none"
						});
		$('#mainitem').data("orgHeight", $('#mainitem').height());
		
		$('.item').each(function(){ 
			$(this).css("position", "absolute").css("margin", "0px").css("top", "0px").css("left", "0px");
			$(this).hide();
		});
		
		$('a').click(function(){
			this.blur();
		});
		
	}
	
	
	function toggle_items(itemClass) {
		if (itemClass=="kunden") {
			$('#mainitem').height(425);
		}
		else {
			$('#mainitem').height($('#mainitem').data("orgHeight"));
		}
		show_items(itemClass);
		hide_items(true, $('.item').not("#mainitem, ."+itemClass));
		
	}
	
	
	function hide_items(do_animation, items) {
		$(items).each(function(){
			
			var origLeft = parseInt($(this).css("left"));
			var origTop = parseInt($(this).css("top"));
			
			$(this).data("left", origLeft+"px").data("top", origTop+"px")
			
			if (do_animation===true) {
				speed = 500;
				// speed = speed + getRandom(1,10)*80;
				$(this).stop().fadeOut(speed);
				/*
				$(this).stop().animate({
						left: "0px",
						top: "0px"
						}, speed, "easeInSine", function(){
							$(this).hide();
						});
				*/
			}
			else {
				$(this).css("left", "0px").css("top", "0px");
			}
		});
		
	}
	
	
	
	
	
	function show_items(itemClass, options) {
		
		if (options==undefined) {
			var options = {
				itemclass: "#mainitem, ."+itemClass,
				// itemclass: ".item",
				offset: { 
							left: 570,
							top: 0
				},
				itemWidth: 180,
				itemHeight: 370,
				easing: "easeInOutCubic",
				// easing: "linear",
				resizeContainerID: "#grid_wrapper"
			}
		}
			
		$("."+itemClass).not(".static").each(function(){
			// alert($(this).html());
			$(this).show();
		});
		
		$('#grid_content').dv2_gridAlign(options);
		
	}
	
	
	/**
	 * Lädt alle Items für die HOME Seite per Ajax neu. Blendet die alten aus und die neuen ein.
	 **/
	function remix() {
		
		$('#item_home_0').addClass("static"); // Der Aktuelles-Teaser soll bleiben
		var old_items = $('.item.home').not(".static");
		var container = $('#grid_content'); // Hier drin werden die Item ausgetauscht
		var num = $(old_items, container).length;
		var i=1;
		
		$('#remix').fadeOut("normal");	
		$(old_items, container).fadeOut("normal", function(){
			
			if (i==(num))	{ // Erst nach dem Fadeout des letzten Elements Ajax ausführen
				$.ajax({
					type: "POST",
					url: baseUrl+"home/remix",
					data: "",
					success: function(html){
						
						$(old_items, container).remove();
						
						$("#remix", container).before(html);
						
						init_CSS();
						$(".static:not(#remix)").show();
						show_items('home');
						init_slideImages();
						$('#remix').fadeIn("normal");
					}
				}); // Ajax
			}
			i++;
		}); // fade Out
		
		return false;
	}
	
	
/************** Spezielle Funktionen ****************/









/************** ALLGEMEINE FUNKTIONEN ****************/
	function debug(text, is_xhtml) {
		// var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
		// text = (text + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
		text = "<pre>"+text+"</pre>";
		$('#bottom div').html(text);
	}
	
	


	function print_r(das_array, ebene) {
		var result = '';
		for (var wert in das_array)
			if (typeof das_array[wert] == "object")
				result = result + ' ' + padding(ebene) + wert + "\n" + print_r(das_array[wert], ebene + 1);
			else
				result = result + ' ' + padding(ebene) + wert + ' = ' + das_array[wert] + "\n";
		return result;
	}
	function padding(laenge) {
		result = '';
		for (i = 0; i < laenge; i++)
			result = result + '   ';
		return result;
	}
	
	
	function getRandom(min, max ) {
	    if( min > max ) {
	            return( -1 );
	    }        
	    if( min == max ) {
	            return( min );
	    }
	    return( min + parseInt( Math.random() * ( max-min+1 ) ) );
	} 
	
	
	
/************** ALLGEMEINE FUNKTIONEN ****************/



