$(document).ready(function(){
    init();
});

function init(){
     init_resize();
     init_background();
     set_site_by();
 }

function init_resize() {

      $(window).resize(set_size);
}

function set_size() {

      size_background();
      size_overlay();
      set_site_by();
}

function set_site_by() {
    $('#footer').css('top', ($(window).height() - 49));
    $('#footer').css('left', ($(window).width() - 161));
}

function size_background(){

    var myImage = $("#background-image");
    full_size_image(myImage);
    $("#site-background").css("height",Math.max(610,$(window).height()));
}

function size_overlay(){

    $("#overlay").css("width",$(window).width()+25);
    $("#overlay").css("height",$(window).height()+25);

}

function init_background(){

    var image_alt = $(document).attr('title');
    var image_src = $('#background-image').attr('src');
    $("#image-container").html('<img src="'+image_src+'" alt="'+image_alt+'" id="background-image"/>');

if ( $.browser.webkit ) {
  	$("#background-image").load(background_loaded);
}
else if ( $.browser.msie ) {

	 $(window).load(function () {
		$("#site-background").css("display","inline");
    		size_background();
		
	});
	
}
else {
	$("#site-background").css("display","inline");
    	size_background();
}

 
	$("#background-image").bind('load', background_loaded)

}

function background_loaded(){
    $("#site-background").css("display","inline");
    size_background();
}

function full_size_image(thisImage){

    //alert(thisImage);
    var myWidthImage = thisImage.width();
    var myHeightImage = thisImage.height();
    var myWidthWindow = $(window).width()+25;
    //alert($(window).height()+" | "+$("body")[0].scrollHeight);
    var myHeightWindow = $(window).height();
    /*if( $("#lightbox").length > 0 ){
        myHeightWindow = Math.max($(window).height(),$("#lightbox").height());
        //alert($(window).height()+" | "+$("#lightbox").height());
    }*/

    var myScale = Math.max((myWidthWindow / myWidthImage),  (myHeightWindow / myHeightImage));
    thisImage.css("width",myWidthImage * (myScale));
    thisImage.css("height",myHeightImage * (myScale));
}




