var bgIndex = 0;

function resizeBg() {
    var theWindow = $(window);
    var bg = $("#bg");
    var aspectRatio = bg.width() / bg.height();
    bg.removeClass('bgheight');
    bg.removeClass('bgwidth');
    if ((theWindow.width() / theWindow.height()) < aspectRatio ) {
        bg.addClass('bgheight');
    } else {
        bg.addClass('bgwidth');
    }
    var contentBlockHeight = $("#content-block").height();
    var sidebarBlockHeight = $("#sidebar-block").height();
    var biggest = contentBlockHeight >= sidebarBlockHeight?contentBlockHeight:sidebarBlockHeight;
    var newHeight = theWindow.height() - 80;
    if(biggest>theWindow.height()){
        newHeight = biggest;
    }
    
    $("#content-block").height(newHeight);
    $("#sidebar-block").height(newHeight);
    $(".arrow-wrapper").height(newHeight);
}            
function movePhoto(bgs, amount){
    bgIndex += amount;
    if(bgIndex == bgs.length){
        bgIndex = bgIndex - bgs.length;
    }else if(bgIndex<0){
        bgIndex = bgs.length - 1;
    }
    setPhoto(bgs[bgIndex]); 
}   
function setPhoto(photo){
    $("#bg").attr("src",photo);
}
function getCurrentBackgroundIndex(bgs){
    var fndIndex = 0;
    var src = $("#bg").attr("src");
    for (var current in  bgs) {
        if(src == bgs[current]) {
            fndIndex = eval(current);
            break;
        }
    }
    return fndIndex;
};    
function showPhotos(){
    $("#content-block").hide();
    $(".arrow").animate({
       "opacity": "show"
     }, "slow", "easein");
}
