$(document).ready(function(){
    $("a[rel=lightbox]").lightBox();

    if ($("#Slider").length) {
        var wdh = 0;
        var IMGs = $("#Slider").find("img");
        
        if ( IMGs.length > 0 ) {
            for ( var img = 0; img < (IMGs.length); img++ ) {
               wdh += parseInt(IMGs[img].offsetWidth);
            }

            var DIVs = $("#Slider-Container").find("div");
            if ( DIVs.length > 0 ){
                for ( var div = 0; div < (DIVs.length); div++ ){
                    wdh += parseInt(DIVs[div].offsetWidth);
                }
            }
            $("#Slider-Container").css("width", wdh);
        }
        var hashMax = Math.ceil(wdh/900);
        if ( wdh > 900 ) { 
            $("#Next").attr("class", "Enabled");
            $("#Next").attr("href", "#"+(hashMax-1));
            $("#Prev").attr("href", "#"+(hashMax));
        }

        if ( getURLParamHash() != false && getURLParamHash() < hashMax ) {
            var sLeft = wdh-(parseInt(getURLParamHash())*900);
            $("#Slider").scrollLeft(0);
            $("#Slider").animate({"scrollLeft": "+="+sLeft+"px"}, "slow");
        }
    }

    $("#Slider").scroll( function(){
        if ( $("#Slider").scrollLeft() >= wdh-900 ) {
            $("#Prev").attr("class", "Enabled");
            $("#Next").attr("class", "Disabled");
            $("#Next").attr("href", "#1");
            $("#Prev").attr("href", "#"+(parseInt(getURLParamHash())+1).toString());
        } else if ( $("#Slider").scrollLeft() == 0 ) {
            $("#Prev").attr("class", "Disabled");
            $("#Prev").attr("href", "#"+(parseInt(getURLParamHash())).toString());
            $("#Next").attr("class", "Enabled");
        } else {
            $("#Prev").attr("class", "Enabled");
            $("#Next").attr("class", "Enabled");
            $("#Prev").attr("href", "#"+(parseInt(getURLParamHash())+1).toString());
            $("#Next").attr("href", "#"+(parseInt(getURLParamHash())-1).toString());
        }
    });

    $("#Prev").click( function(){$("#Slider").animate({"scrollLeft": "-=900px"}, "slow")});
    $("#Next").click( function(){$("#Slider").animate({"scrollLeft": "+=900px"}, "slow")});

    if ( $("#Intro").length ) {
        $("#Intro object").css("marginTop", Math.floor($(document).height()/2)-100+"px");
    }

    $("#sectionFoot img[alt=PRESSO]").hover( function(){$(this).css('background-position', '0px -15px')}, function(){$(this).css('background-position', '0px 0px')} );
    $("#sectionFoot img[alt=DESIGNALIVE]").hover( function(){$(this).css('background-position', '0px -10px')}, function(){$(this).css('background-position', '0px 0px')} );
});

function getURLParamHash() {
    if ( location.href.lastIndexOf("#") > -1 ) {
        return location.href.substring(location.href.lastIndexOf("#")+1,location.href.length);
    } else return false;
}
