$(document).ready(function() {
	
	var $_GET = {};
	
	document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () {
	    function decode(s) {
	        return decodeURIComponent(s.split("+").join(" "));
	    }
	
	    $_GET[decode(arguments[1])] = decode(arguments[2]);
	});

	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]+'" />');
		}*/
		var list = ['10-09-15_HWG.jpg','101115_HWG039_a.jpg','HWG_11i.jpg','hwg_12i.jpg','HWG_15i.jpg','hwg_7i.jpg','hwg_8i.jpg'];
		
		for(var i = list.length-1; i > -1; i--) {
			$("#teaser").prepend('<img id="gallery_img_'+i+'" src="data-temp-hwg-3/images/news/110404/'+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(); */
		
	}
	
	$(".suedstadtMap_ImageMap area").hover(function(e){
		var attr = $(this).attr("suedstadt-connect");
		$(".suedstadtMap_overlay img").stop(true,true);
		$(".suedstadtMap_overlay img[suedstadt-connect='"+attr+"']").fadeIn("fast");
		e.preventDefault();
	},function(e){
		var attr = $(this).attr("suedstadt-connect");
		$(".suedstadtMap_overlay img").stop(true,true);
		$(".suedstadtMap_overlay img[suedstadt-connect='"+attr+"']").fadeOut("fast");
		e.preventDefault();
	});
	
	$("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", "no-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/,"").replace(/\% 0\%/,"").replace(/px 0\%/,"")*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/,"").replace(/\% 0\%/,"").replace(/px 0\%/,"")*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
	});
	
	if ($(".c25r iframe").length == 0) {
		var images_pp_list = [];
		
		$(".suedstadt_zoom").each(function(i){
			var this_src = $(this).find(".suedstadt_zoom_max img").attr("src");
			var link = $('<a rel="prettyphotogal[gal]" class="button images_pp_func" href="' + this_src + '" target="_blank">Ansicht vergr&ouml;&szlig;ern</a>').css("margin-top", "10px");
			var id = i;
			$(this).next("p").children().unwrap();
			$(this).next("p,br").remove();
			$(this).next("p,br").remove();
			if (i > 0) {
				$(this).css("margin-top", "10px");
			}
			$(this).find(".suedstadt_zoom_max").append(link);
			images_pp_list[i] = $(this).find(".suedstadt_zoom_max img").attr("src");
			var clone = $('<a href="' + this_src + '"></a>').css("padding", "0").css("background-image", "none");
			clone.click(function(e){
				$(this).parents(".suedstadt_zoom").find(".suedstadt_zoom_max a").trigger("click");
				e.preventDefault();
			});
			
			$(this).find(".suedstadt_zoom_thumb").append(clone.append($(this).find(".suedstadt_zoom_thumb img")));
		});
		
		$("a[rel^='prettyphotogal']").prettyPhoto({
			allowresize: true,
			overlay_gallery: false
		});
	}
	
});

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;

