// initialize full background image
$(document).ready(function(){
initBackground();
});


/**********************************************************************
These functions manipulate the background image when resizing the
browser window
**********************************************************************/
function initBackground() {
$(window).resize(backgroundResizeHandler);
$(window).trigger('resize');
};
var backgroundResizeHandler = function() {
// add the background if it does not exists (typically this is only for the home page)
if(browser.isIPad || browser.isIPhone) {
if($('#background').length == 0 && latestImageFile != "") {
//alert("no background found " + $('#background').length + "<");
// create background div
var bg = document.createElement("div");
bg.setAttribute("id","background");
bg.setAttribute("class", "vertical");
// create image
var bgImg = document.createElement("img");
bgImg.setAttribute("src", latestImageFile);
bg.appendChild(bgImg);
document.body.insertBefore(bg, document.getElementById("footer"));
}
}
// If the inital image isn't cached, it'll report 0 dimensions.
if ($('#background img').height() == 0 || $('#background img').width() == 0) {
setTimeout(function() { $(window).trigger('resize'); }, 100);
return;
}
// ipad
var landscape = false;
if(browser.isIPad || browser.isIPhone) {

$('#background').addClass('vertical').removeClass('horizontal');

}
// everything else
else {
if ($('#background').hasClass('horizontal')) {
if ($('#background img').height() < $('#background').height()) {
$('#background').addClass('vertical').removeClass('horizontal');

}
} else {
if ($('#background img').width() < $('#background').width()) {
$('#background').addClass('horizontal').removeClass('vertical');
$('#background img').css('marginLeft', 0);
}
}
}
};

