$(document).ready(function() {
	
	if($("#teaser").hasClass("t_339")) {
		$("#teaser").attr("style",'background-image: none;')
		var list = ['HWG_Sued124_a_fin.jpg','HWG_Sued129_a_fin.jpg','HWG_Sued145_a_fin.jpg','HWG_Sued149_a_fin.jpg','HWG_Sued33_fin.jpg','HWG_Sued36_a_fin.jpg','HWG_Sued40_a_fin.jpg','HWG_Sued44_a_fin.jpg','HWG_Sued51_a_fin.jpg','HWG_Sued_158_a_fin.jpg','HWG_Sued_163_a_fin.jpg','HWG_Sued_166_a_fin.jpg','HWG_Sued_167_a_fin.jpg','HWG_Sued_171_a_fin.jpg','HWG_Sued_174_a_fin.jpg','HWG_Sued_175_a_fin.jpg','HWG_Sued_188_a_fin.jpg','HWG_Sued_192_a_fin.jpg','HWG_Sued_196_a_fin.jpg','HWG_Sued_199_a_fin.jpg','HWG_Sued_200_a_fin.jpg','HWG_Sued_234_a_fin.jpg','HWG_Sued_242_a_fin.jpg']
		
		for(var i = list.length-1; i > -1; i--) {
			$("#teaser").prepend('<img id="gallery_img_'+i+'" src="data-temp-hwg-3/images/news/1009/'+list[i]+'" />');
		}
		
	} else if($("#teaser").hasClass("t_101")){
		$("#teaser").attr("style",'background-image: none;')
		var list = ['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg'];
		
		list.shuffle();
		
		for(var i = list.length-1; i > -1; i--) {
			$("#teaser").prepend('<img id="gallery_img_'+i+'" src="data-temp-hwg-3/images/StartGalerie/0'+list[i]+'" />');
		}
		
		/* if($("#teaser").length > 0) {
			var a = 0 + list.length * (Math.random());
			a = Math.round(a);
		}

		$("#gallery_img_"+a).appendTo("#teaser").show(); */
		
	}

	$("input[name='alle_stadtteile']").toggle(function(e) {
		$(this).attr("checked","checked");
		$("input[name='regionaler_zusatz__geo[]']").attr("checked","checked");
		e.preventDefault();
	}, function(e) {
		$(this).removeAttr("checked");
		$("input[name='regionaler_zusatz__geo[]']").removeAttr("checked");
		e.preventDefault();
	});

	
	if($("#invisible_loader").length > 0) {
		$(document).everyTime(1000, "loader", function(i) {
			if($("#invisible_loader").attr("complete") == true) {
				$(document).stopTime("loader");
				var w = $("#invisible_cont").width();
				var h = $("#invisible_cont").height();
				$("#teaser_g").attr("style",'background-image: url("'+$("#invisible_loader").attr("src")+'");');
				$("#teaser_g").css("background-position","0px 0px");
				$("#teaser_g").css("background-repeat", "repeat");
				$("#teaser_g").css("position", "relative");
				var max = (w-928)*-1;
				var min = 0;
				var next = $('<a href="#"></a>').css({
					position: "absolute",
					width: "100px",
					height: "100px",
					bottom: "0px",
					right: "0px",
					backgroundImage: "url(/data-live-hwg-3/css/css/screen/prettyPhoto/next.png)"
				}).click(function(e){
					e.preventDefault();
					prev.show();
					var bgp = $("#teaser_g").css("background-position");
					if(typeof bgp == "undefined") {
						var bgp = $("#teaser_g").css("backgroundPosition");
					}
					bgp = bgp.replace(/px 0px/,"")*1;
					var newbgp = (Math.round(bgp*1)-400);
					if(newbgp < max) {
						$(this).hide();
						$("#teaser_g").css("background-position",max+"px 0px");
					} else {
						$("#teaser_g").css("background-position",newbgp+"px 0px");
					}
				}).addClass("teaser_next");
				var prev = $('<a href="#"></a>').css({
					position: "absolute",
					width: "100px",
					height: "100px",
					bottom: "0px",
					left: "0px",
					backgroundImage: "url(/data-live-hwg-3/css/css/screen/prettyPhoto/last.png)"
				}).click(function(e){
					e.preventDefault();
					next.show();
					var bgp = $("#teaser_g").css("background-position");
					if(typeof bgp == "undefined") {
						var bgp = $("#teaser_g").css("backgroundPosition");
					}
					bgp = bgp.replace(/px 0px/,"")*1;
					var newbgp = (Math.round(bgp*1)+400);
					if(newbgp > min) {
						$(this).hide();
						$("#teaser_g").css("background-position","0px 0px");
					} else {
						$("#teaser_g").css("background-position",newbgp+"px 0px");
					}
				}).addClass("teaser_prev");
				$("#teaser_g").append(next);
				$("#teaser_g").append(prev);
				
			}
		});
	}
	if($("#teaser").length > 0) {
		$(document).everyTime(5000, function(i) {
		  $("#teaser > img:last-child").fadeOut(1500, function(){
		  		$(this).prependTo("#teaser").show();
		  }); 
		});
	}
	
	$(".hideme").removeClass("hideme");
	
	$(".global_check").click(function(e) {
		var myc = $(this).parents("tr").next("tr").find("input:first").attr("class");
		if($(this).attr("checked") == false) {
			$("."+myc).attr("checked","");
		} else {
			$("."+myc).attr("checked","checked");
		} 
	});
	
	$("a[rel^='prettyPhoto']").prettyPhoto({
		allowresize: true
	});
	
});

function arrayShuffle(){
	  var tmp, rand;
	  for(var i =0; i < this.length; i++){
	    rand = Math.floor(Math.random() * this.length);
	    tmp = this[i]; 
	    this[i] = this[rand]; 
	    this[rand] =tmp;
	  }
	}

Array.prototype.shuffle = arrayShuffle;
