MapPins = {
	"Region Widnau": [ 312, 13 ],
	"Region Diepoldsau": [ 317, 34 ],
	"Region Altstätten": [ 268, 52 ],
	"Region Lienz": [ 240, 119 ],
	"Region Sennwald": [ 217, 158 ],
	"Region Grabs": [ 170, 229 ],
	"Region Buchs": [ 218, 234 ],
	"Region Sevelen": [ 210, 263 ],
	"Region Walenstadt": [ 130, 270 ],
	"Region Wartau": [ 205, 298 ],
	"Region Flums": [ 129, 313 ],
	"Region Flumserberg": [ 89, 349 ],
	"Region Sargans": [ 206, 334 ],
	"Region Fläsch": [ 242, 346 ],
	"Region Maienfeld": [ 259, 369 ],
	"Region Jenins": [ 277, 373 ],
	"Region Mels": [ 127, 402 ],
	"Region Pfäfers": [ 184, 441 ],
	"Region Bad Ragaz": [ 221, 376 ]
};
RegionAlt = "No Region Set";
ActiveRegion = "No Active Region";
PinSet = false;
Changed = 0;
ContentVisible = false;

$(document).ready(function() {
	// Edit Support-Tool Question: Editor Size , #dnn_ctr485_Form_Answer_Answer, #dnn_ctr485_Form_Answer_tblTextEditor
	window.setTimeout(function() { $("#dnn_ctr485_Form_Answer_AnswerWrapper").css("height", "200px");
																	$("#dnn_ctr485_Form_Answer_Answer").css("height", "400px"); $("#dnn_ctr485_Form_Sort").css("text-align", "left"); }, 100);
													 
	$(".ContainerMapContent .Normal table").css({"table-layout": "fixed"}).find("tr td:eq(0)").css({"width": "165px"});
	$(".ContainerMapContent").parent().appendTo("#MapContentWrapper").wrapAll("<div class='MapContentTableWrapper'></div>");
	$(".MapCell").append("<div class='MapPin'></div>").append(
		$("#RegionMap").clone().addClass("RegionMap2").attr("src", SkinPath + "Images/TransparentMap.png")
	);
	$(".ContainerMapWrapper map area").hover(function(el) {
		if(!PinSet)
		{
			RegionAlt = $(this).attr("alt");
			//RegionTimeOut = window.setTimeout(ChangeRegion, 50);
			ChangeRegion();
		}
		document.body.style.cursor = 'pointer';
	}, function() { /*clearTimeout(RegionTimeOut);*/ document.body.style.cursor = 'default'; })
	.click(function() {
		if(!PinSet || RegionAlt != $(this).attr("alt"))
		{
			$(".MapPin").css({"left": MapPins[$(this).attr("alt")][0] + 2})
									.css({"top": MapPins[$(this).attr("alt")][1] - 49})
									.show();
			RegionAlt = $(this).attr("alt");
			ChangeRegion();
			PinSet = true;
		}
		else
		{
			$(".MapPin").hide();
			PinSet = false;
		}
	});
	
	// Format Tables
	$(".ColouredTable tr:even td").not(".SpecialCell").css({ 'background-color': '#F7F7F7' });
	
	// wrap slide link to whole image
	$(".slide-inner").each(function(){
	var SlideLink = $(".readon", this).attr("href");
	//$("img", this).wrap("<a />");
	});
	
	// Home: Gallery Fix (click IE7)
	if($.browser.msie && ($.browser.version == 7 || $.browser.version == 6))
	{
		$("#navi-outer_415").click(function(e) {
			if(e.target == this)
			{
				var Url = $("#slide-outer_415 .slide:eq(" + $("#ul_container_415 ul li").has(".navi-active").index() + ") .slide-inner .mss_img").attr("href");
				if(Url !== undefined) window.location.href = Url;
			}
		});
	}
	
	// Fix for "Mein Login / Benutzerkonto" Authorization in Chrome
	// http://code.google.com/p/chromium/issues/detail?id=91814
	
	if(/chrome/.test(navigator.userAgent.toLowerCase()) && $("#Nav172.Active").length != 0)
	{
		var iFrame = $(".ModuleContent iframe");
		iFrameSrc = $(iFrame).attr("src");
		window.open(iFrameSrc);
		$(iFrame).after('<div class="AuthenticationMessage">Das Benutzerkonto wird in einem neuen Fenster geöffnet. Falls kein neues Fenster erscheint, klicken Sie auf folgenden Link, um zum Benutzerkonto zu gelangen:<br /><br /><a href="#" id="ReOpen">Zum Benutzerkonto</a></div>').remove();
		$("#ReOpen").click(function() { window.open(iFrameSrc); });
	}
	
	// Open Links to PDF's in new Tab / Window
	$("a[href$='.pdf']").attr("target", "_blank");
	
	// Enable PIE (CSS3 in IE)
	$(function() {
		if (window.PIE && $.browser.msie && $.browser.version < 9) {
			$('#NavSystem li div div').each(function() {
				PIE.attach(this);
			});
		}
	});
	
	// Cell Hover
	$("table.CellHover").each(function() {
		$("td:not('.xTableSpacer')", this).hover(function() { $(this).addClass("Hover"); }, function() { $(this).removeClass("Hover"); })
			.click(function() {
				var CellHoverLink =  $(".CellHoverLink", this).attr("href");
				if(CellHoverLink !== undefined)
					window.location.href = CellHoverLink
			});
	});
	
	// Cell Hover Replacemenet 2sexy content
	EqualizeHeight($(".UebersichtWrapper"));
	$(".UebersichtWrapper").hover(function() { $(this).addClass("Hover"); }, function() { $(this).removeClass("Hover"); })
		.click(function() {
			var CellHoverLink =  $(".CellHoverLink", this).attr("href");
			if(CellHoverLink !== undefined)
				window.location.href = CellHoverLink
		});

	
	// Enable click on whole cell (Home)
	$("#HomePanes .c25l, #HomePanes .c25r").click(function(e) {
		if($(e.target).parents(".dnnActionMenuBody").size() != 1 && $(e.target).parents(".dnnFormInfo").size() != 1)
		{
			var CellHoverLink = $(".Normal a:first", $(this)).attr("href");
			if(CellHoverLink !== undefined)
				window.location.href = CellHoverLink;
		}
	});
	
	// Don't hide empty subcolumns if there are some subcolumns with content
	if($(".kombiangebote .c25l").filter(function() { return ($(this).find(".DNNEmptyPane").size() == 0); }).size() > 0)
		$(".kombiangebote .c25l .DNNEmptyPane").html("&nbsp;");
});


function EqualizeHeight(group)
{
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.css('min-height', tallest + "px");
	$("img", group).load(function() { EqualizeHeight(group); });
}

function ChangeRegion()
{
	if(RegionAlt != "")
	{
		ContentVisible = false;
		$("#MapContentWrapper").css({"opacity": 1, "display":"block"});
		$("#MapContentWrapper").fadeOut(100, function() {
			Obj = $(".ContainerMapContent h1").filter(function() { return $(this).text().trim() === RegionAlt; }).parent().show();
			$(".ContainerMapContent h1").filter(function() { return $(this).text().trim() != RegionAlt; }).parent().hide();
			/*ObjWrap = $("<div class='MapContentTableWrapper'></div>");
			$(ObjWrap).ap($(Obj));
			$(this).html($(ObjWrap));*/
			$("#MapContentWrapper").fadeIn(100, function() { $("#MapContentWrapper").clearQueue(); if(!(window.Cufon === undefined || Cufon === false)) Cufon.refresh(); ContentVisible = true; });
		});
	}
	
	ActiveRegion = RegionAlt;
}
