$(document).ready(function() {
	// Hintergrundbild skalieren
	scaleBGImage();
	$(window).resize(function() { scaleBGImage(); });

	// Galeriebilder in Shadowbox oeffnen
	$('div#content div.gallery ul li a.gallery').click(function() {
		var galleryID = $(this).attr('id').split('gallery-').join('');
		showGallery(galleryID);
		return false;
	});
});

function scaleBGImage() {
	var bgImageContainer = $('#bg-image-container');
	if (bgImageContainer.length > 0) {
		bgImageContainer.css({ height: $.clientCoords().height - 73 +'px' });
		$('#website').css('background-image', 'none');
		$(bgImageContainer.children()[0]).css({
			width: $.clientCoords().width+'px'
		});
		bgImageContainer.show();
		
		$('div#bow').css({
			width: $.clientCoords().width+'px'
		});
		$('#website').css('overflow', 'auto');
		
		$('#footer').css({ marginLeft: ($('#website').offset().left + parseInt($('#website').css('padding-left')) ) + 'px' });
	}
}

function showGallery(galleryID) {
	if($("div#imgdump").length == 0) { $('body').append('<div id="imgdump"></div>'); }
	$("#imgdump").empty();
	
	var content = galleries[galleryID];
	for(var i = 0,o; o = content[i]; i++) {
		$("#imgdump").append('<a class="gal2item" href="'+o.img+'" rel="shadowbox[gal-'+galleryID+']" title="'+o.title+'"></a>');	
	}
	Shadowbox.gallery = [];
	Shadowbox.cache = [];
	
	Shadowbox.setup("a.gal2item", {
		displayNav: true,
		slideshowDelay: 4,
		gallery: 'shadowbox[gal-'+galleryID+']',
		autoPlay: true,
		overlayColor: '#FFFFFF',
		overlayOpacity: 0.95
	});
	Shadowbox.open($("a.gal2item")[0]);
}

$.clientCoords = function() {
	var dimensions = {width: 0, height: 0};
	/*
	if (document.documentElement) {
		dimensions.width = document.documentElement.offsetWidth; // IE6, 4 fuer IE7, 0 fuer FF
		dimensions.height = document.documentElement.offsetHeight;
	}
	else if (window.innerWidth && window.innerHeight) {
		dimensions.width = window.innerWidth;
		dimensions.height = window.innerHeight;
	}
	*/
	// Höhe des sichtbaren Browserbereichs
	dimensions.height = Number(getWinSize(window).height);
	// Breite des sichtbaren Browserbereichs
  dimensions.width = Number(getWinSize(window).width);
	
	
	return dimensions;
}

function getWinSize(win) {
  if(!win) win = window;
  var s = new Object();

  if(typeof win.innerWidth != 'undefined') {
    s.width = win.innerWidth;
    s.height = win.innerHeight;
  }
  else {
    var obj = getBody(win);
    s.width = parseInt(obj.clientWidth);
    s.height = parseInt(obj.clientHeight);
  }
  return s;
}

// Der IE hat 2 verschiedene Objekte für den strict und quirks Mode.
function getBody(w) {
  return (w.document.compatMode && w.document.compatMode == "CSS1Compat") ? w.document.documentElement : w.document.body || null;
}
