// Template wide Initializer, Salzburger Kunstverein, sensomatic.com

$(document).ready(function() {
						   
	LeftOverlayPosition = new Array();
	TopOverlayPosition = new Array();
    
	// Pfeil bei Subnavigation wird automatisch für den ersten Menüpunkt eingeblendet
	$('.submenue > a:first').append("<img src='/images/base/nav_pfeil.gif' />");
	
	// Pfeile für Subnavigation einblenden bei Klick
	$('.submenue > a').click(function() { 
        $('.submenue > a > img').remove(); 
		$(this).append("<img src='/images/base/nav_pfeil.gif' />");
        return false; 
    });	
	
	//Positionierung der 3 Hauptspalten - links:#submenue, mitte:#right
	var container_width = $('#start_container').css("width");
	var PosP_container_width = container_width.indexOf("p");
	container_width = container_width.slice(0,PosP_container_width);
	container_width = parseInt(container_width);
	
	function resize_wide(){
		//alert('Hallo');
		$('#ausgabe').html(WindowWidth());
		$('.wrapper').each(function (){
			var what = $(this);
			position = what.position();
			TopOverlayPosition.push(Math.round(position.top));
			LeftOverlayPosition.push(Math.round(position.left));
		})
		
		if (WindowWidth() < 1125 && WindowWidth() > 964){
			$('#start_container').css({'width' : WindowWidth() + 'px'});
			$('#start_right').css({'width' : '800px'});
		}else{
			if (WindowWidth() >965){
				$('#start_right').css({'width' : '955px'});
			}else{
				$('#start_container').css({'width' : '965px'});
				$('#start_right').css({'width' : '800px'});
			}
		}
		
		if (WindowWidth() >= 1130 && WindowWidth() < 1351){
			var space = WindowWidth() - 1120;
			$('#start_right').css({'marginLeft' : space/2});
			$('#start_container').css({'width' : container_width + space/2});
			$('.overlay').each(function () {
				$(this).css({'position' : 'static'});							 
			})
		}else{
			if (WindowWidth() <= 1130){
				if (WindowWidth() > 964){
					$('#start_right').css({'marginLeft' : '5px'});
					leftPosition = WindowWidth() - 1130;
					leftPosition = 951 + leftPosition;
					$('.overlay').each(function (i) {
						if ($(this).css('position') != 'absolute'){
							$(this).css({'position' : 'absolute'});
							$(this).css({'left' : LeftOverlayPosition[i] + 'px'});
							if (TopOverlayPosition[0] < 160){		//Darstellungsfehler in Safari wird mit Addition von 46px korrigiert
								var corr = 26;
							}else{
								var corr = 0;	
							}
							$(this).css({'top' : TopOverlayPosition[i] + corr + 'px'});
						}
						$(this).css({'position' : 'absolute'});
						$(this).css({'left' : WindowWidth()-175});
						$(this).css({'z-index' : '99999'});						 
					})
				}else{
					$('.overlay').each(function (i) {
						if ($(this).css('position') != 'absolute'){
							$(this).css({'position' : 'absolute'});
							$(this).css({'left' : '790px'});
							if (TopOverlayPosition[0] < 160){		//Darstellungsfehler in Safari wird mit Addition von 46px korrigiert
								var corr = 26;
							}else{
								var corr = 0;	
							}
							$(this).css({'top' : TopOverlayPosition[i] + corr + 'px'});
						}
						$(this).css({'position' : 'absolute'});
						$(this).css({'left' : '790px'});						
						$(this).css({'z-index' : '99999'});						 
					})
				}
			}else{
				$('#start_right').css({'marginLeft' : '115px'});
				$('#start_container').css({'width' : '1235px'});
				$('.overlay').each(function (i) {
					$(this).css({'left' : TopOverlayPosition[i]});
					$(this).css({'top' : TopOverlayPosition[i]});						 
					$(this).css({'position' : 'static'});							 
				})
			}	
		}
	
	}
	
	resize_wide();
	
	
	
	$(window).resize(function(){
		resize_wide();
		
	});
	
});
