$(function() {
	initPage();
});


function initPage() {
	// load background
	var $screenWidth = parseInt($(document).width());
	var $bg = "";
	if($screenWidth<1100) {
		$bg = "1300";
	} else if($screenWidth>1100&&$screenWidth<1300) {
		$bg = "1300";
	} else if($screenWidth>1300&&$screenWidth<1450) {
		$bg = "1440";
	} else if($screenWidth>1450&&$screenWidth<1950) {
		$bg = "1900";
	}
	$("body").css('background','url(gfx/' + $bg + '.jpg) 50% bottom no-repeat #000');
	
	// logo placement
	$("#logo").css({
		'top' : '10px',
		'left' : Math.floor(($screenWidth-$("#logo").width())/2) + 'px',
		'display' : 'block'
	});
	
	// menu preparation
	jQuery.each($("ul#menu li a"), function() {
		var $menuSrc = "";
		switch($(this).html()) {
			case 'TV-serier':
				$menuSrc = "tv-serier";
			break;
			case 'Musik':
				$menuSrc = "musik";
			break;
			case 'Om Matchoyer Sound':
				$menuSrc = "om-matchoyer";
			break;
			case 'Kontakt Matchoyer Sound':
				$menuSrc = "kontakt-matchoyer";
			break;			
		}		
		$(this).html('');
		var $menuImg = $("<img />").attr('src','gfx/' + $menuSrc + '.png');
		$(this).append($menuImg);
	});


	$("ul#menu li a").colorbox({width:"400px", height:"450px", iframe:true, opacity: 0.5, onClosed: function() { location.hash = ""; }});
	$("ul#menu li a").click(function() {
		location.hash = $(this).parent('li').attr('class');
	});
	
	$("ul#menu").show();
	
	// ref placement
	$("#specialklassen").css({
		'top' : $("#logo").offset().top + 180 + 'px',
		'left' : $("#logo").offset().left + 50 + 'px',	
		'display' : 'block'	
	});
	$("#rommen").css({
		'top' : $("#logo").offset().top + 180 + 'px',
		'left' : $("#logo").offset().left + 250 + 'px',	
		'display' : 'block'	
	});	
	$("#skraaplan").css({
		'top' : $("#logo").offset().top + 360 + 'px',
		'left' : $("#logo").offset().left + 220 + 'px',	
		'display' : 'block'	
	});	
	$("#krysters").css({
		'top' : $("#logo").offset().top + 360 + 'px',
		'left' : $("#logo").offset().left + 420 + 'px',	
		'display' : 'block'	
	});		
	$("#julie").css({
		'top' : $("#logo").offset().top + 120 + 'px',
		'left' : $("#logo").offset().left + 600 + 'px',	
		'display' : 'block'	
	});	
	$("div.pigerpp").css({
		'top' : $("#logo").offset().top + 150 + 'px',
		'left' : $("#logo").offset().left + 450 + 'px',	
		'display' : 'block'	
	});
	$("div.pigerpp div").css({
		'opacity' : 0.8	
	});	
	$("div.pigerpp").hover(
		function() {
			$("div.pigerpp div").css('display','block');
		},
		function() {
			$("div.pigerpp div").css('display','none');
		}		
	);

	$("a.video").colorbox({iframe:true, innerWidth:570, innerHeight:344, opacity: 0.5});

	// david placement
	$("#david-matchoyer").css({
		'bottom' : '0px',
		'left' : '170px',	
		'display' : 'block'	
	});		

	// hash detection	
	var $hash = location.hash;
	if($hash.length>0) {
		$hash = $hash.replace("#","");
		if($("ul#menu li." + $hash).length>0) {
			$("ul#menu li." + $hash).find('a:first').colorbox({open: true});
		}
	}	
}



function real() {
	return true;
}
