var imagePaths = [
		"css/images/chair1-active.png",
		"css/images/chair2-active.png",
		"css/images/chair3-active.png",
		"css/images/chair4-active.png",
		"css/images/scrollpane/scrollpane-bg.png",
		"css/images/scrollpane/scrollpane-up.png",
		"css/images/scrollpane/scrollpane-up-active.png",
		"css/images/scrollpane/scrollpane-handle.png",
		"css/images/scrollpane/scrollpane-handle-active.png",
		"css/images/scrollpane/scrollpane-down.png",
		"css/images/scrollpane/scrollpane-down-active.png",
		"css/images/home-active.png",
		"css/images/impressum-active.png"
	];
var images = new Array();
for (var i=0; i < imagePaths.length; i++) {
	var image = new Image();
	image.src = imagePaths[i];
	images.push(image);
};

$(document).ready(function() {
	$("a").each(function() {
		if ($(this).attr("href").substr(0, 7) == "http://") {
			$(this).attr("target", "_blank");
		}
	});
	
	$("#distance").remove();
	$("#distance-2").remove();
	
	var mainDiv = $("#main");
	var curtainDiv = $("#curtain");
	var headlineDiv = $("#headline");
	var portraitDiv = $("#portrait");
	var menuDiv = $("#menu");
	var submenuDiv = $("#submenu");
	var contentDiv = $("#content");
	
	var contentUsertextDiv = $("#content-usertext");
	
	var gbAuthor = $("#gb-author");
	var gbSubject = $("#gb-subject");
	var gbExtra = $("#gb-extra, #ex-logo");
	
	var menuItem1Div = $("#menu-item-1");
	var menuItem2Div = $("#menu-item-2");
	var menuItem3Div = $("#menu-item-3");
	var menuItem4Div = $("#menu-item-4");
	
	menuItem1Div.click(function(e) {
		window.location.href = "?path=gaestebuch";
		return false;
	});
	menuItem2Div.click(function(e) {
		window.location.href = "?path=film-und-tv";
		return false;
	});
	menuItem3Div.click(function(e) {
		window.location.href = "?path=musik";
		return false;
	});
	menuItem4Div.click(function(e) {
		window.location.href = "?path=klaussner";
		return false;
	});
	
	mainDiv.css("position", "absolute");
	
	$(window).resize(function(e) {
		var width = $("html").width();
		var height = $("html").height();

		var newWidth, newHeight;

		if (width < 900) {
			newWidth = 900;
		} else if (width > 1500) {
			newWidth = 1500;
		} else {
			newWidth = width;
		}

		if (height < 469) {
			newHeight = 469;
		} else if (height > 781) {
			newHeight = 781;
		} else {
			newHeight = height;
		}

		var newX = (width - newWidth) / 2;
		var newY = (height - newHeight) / 2;

		if (newX < 0) { newX = 0; }
		if (newY < 0) { newY = 0; }


		mainDiv
			.css("width", newWidth + "px")
			.css("height", newHeight + "px")
			.css("left", newX + "px")
			.css("top", newY + "px");
		
		var widthMultiplier = (newWidth-900) / 600;
		var heightMultiplier = (newHeight-469) / 312;

		curtainDiv.css("left", Math.round((widthMultiplier * 70) - 70) + "px");
		
		headlineDiv.css("right", Math.round((widthMultiplier * 180) + 30) + "px")
			.css("top", Math.round((heightMultiplier * 94) + 7) + "px");
		
		portraitDiv.css("right", Math.round((widthMultiplier * 180) + 30) + "px")
			.css("top", Math.round((heightMultiplier * 140) + 63) + "px");
		
		menuDiv.css("width", Math.round((widthMultiplier * 180) + 478) + "px");
		
		menuItem2Div.css("left", Math.round((widthMultiplier * 25) + 108) + "px");
		menuItem3Div.css("left", Math.round((widthMultiplier * 52) + 232) + "px");
		menuItem4Div.css("left", Math.round((widthMultiplier * 60) + 364) + "px");
		
		submenuDiv.css("left", Math.round((widthMultiplier * 342) + 429) + "px")
			.css("top", Math.round((heightMultiplier * 252) + 115) + "px");
		
		contentDiv
			.css("width", Math.round((widthMultiplier * 218) + 277) + "px")
			.css("left", Math.round((widthMultiplier * 85) + 135) + "px");
		
		contentUsertextDiv
			.css("top", Math.round((heightMultiplier * 118) + 90) + "px")
			.css("height",Math.round((heightMultiplier * 129) + 314) + "px");
		
		gbAuthor
			.css("top", Math.round((heightMultiplier * 63) + 9) + "px")
			.css("height", Math.round((heightMultiplier * 27) + 40) + "px");
		gbSubject
			.css("top", Math.round((heightMultiplier * 90) + 49) + "px")
			.css("height", Math.round((heightMultiplier * 28) + 40) + "px");
		gbExtra
			.css("top", Math.round((heightMultiplier * 247) + 404) + "px")
			.css("height", Math.round((heightMultiplier * 53) + 47) + "px");
	}).resize();
	
	contentUsertextDiv.scrollpane();
});

