// gallery start

// make gallery visible
$('#gallery').removeClass("hidden");
$('#gallery li:first').removeClass("hidden");
$('.fpPager').removeClass("hidden");


var gallery_size = $(".fpImageText").length;
$("#page_total").html(gallery_size);

$(".fpPager img").click(function(){

    //return current number of item 1,2,...
    var current = parseFloat($("#page_current").html());
    
    if($(this).attr("id") == "next"){
        // if(current != $("#page_total").html() ){
        if(current != gallery_size ){
            //todo: clean this one up as well
            $(".fpImageText").addClass("hidden");
            $("#imageText_" + (current + 1) + ",.image_" + (current + 1)).removeClass("hidden");
            $("#page_current").html(current + 1);
            $("#previous").removeClass("hidden");
        }
        if(current+1 == gallery_size ){
            $("#next").addClass("hidden");
        }
    }
    //previous
    else{
        if(current > 1){
            $(".fpImageText").addClass("hidden");
            $("#imageText_" + (current - 1) + ",.image_" + (current - 1)).removeClass("hidden");
            $("#page_current").html(current - 1);
            
            $("#next").removeClass("hidden");
        }
        if(current-1 == 1){
            $("#previous").addClass("hidden");                    
        }                    
    }
});
//end of gallery




// slide shows start
var body_element = $('body');
if(body_element.length){
    
    //front page
    if(body_element.attr('class') == 'frontPage'){
        $.preload('.frontPage #supersize .activeslide', {            
            enforceCache: true,
            onComplete:complete_front_page_slide
        });
    };
    //campaign
    if(body_element.attr('class') == 'slideShow'){
        $.fn.supersized.options = {  
         startwidth: 1625,  
         startheight: 950,
         minsize: .50,
         slideshow: 1,
         slideinterval: 1250
        };
        $('.slideShow #supersize').supersized();
        $('.slideShow #supersize').addClass('showSlideShow');    
    };
};

function complete_front_page_slide( data ){
    //narrow screens 
    if (getPageSize()[2] < 1024){
        $('body.frontPage').addClass('frontPageScroll');            
    };
    $.fn.supersized.options = {  
     startwidth: 1625,  
     startheight: 950,
     minsize: .50,
     slideshow: 0,
     slideinterval: 1250
    };
    $('.frontPage #supersize').supersized();
    $('.frontPage #supersize').addClass('showSlideShow');
};     
//end of front page slide


// returns something like this:  [1391, 604, 1391, 395] outer width | outer height | inner width | inner height
function getPageSize() {
    var jqueryPageSize = new Array($(document).width(),$(document).height(), $(window).width(), $(window).height());
    return jqueryPageSize;
};


//end of slide shows
      
// light box stuff
var element = $('.lightbox');
if(element.length){    
    $(".lightbox").attr('href', function() {
        return $(this).attr('href')+'/image_large';
    });
    $(".lightbox").lightbox({
        fitToScreen: true,
        imageClickClose: true,
        overlayOpacity : 100,
        borderSize : 0,
        navbarOnTop: false,
        resizeSpeed : 0,
        fileLoadingImage : '/++resource++skinny/lightbox_blank.gif',
        // fileLoadingImage : '/++resource++skinny/loader.gif',
        fileBottomNavCloseImage : '/++resource++skinny/lightbox_closelabel_small.png'
        //this approach dosnt work have eventaully a blank gif ?
        //fileLoadingImage : false
    });
};//end of lightbox


// player
var player = $('.autoFlowPlayer.video');

if(player.length){
    $("body").addClass("playerPage");
    $(".flowPlayerMessage.discreet").addClass("hidden");

    $("body").addClass("playerPage");
    flowplayer("player", "/flowplayer.commercial-3.1.5.swf", {
        "clip": {
            // "scaling": "fit", 
            "autoBuffering": true, 
            "autoPlay": true,
            // show play on start but not play again in the end of the movie
            onStart: function () { 
              // reset opacity when clip is played again 
              this.getPlugin("play").css({opacity: 1}); 
            }, 
            onFinish: function () { 
              // do not show "Play again" 
              this.getPlugin("play").css({opacity: 0}); 
            }
        },
        // log: { level: 'debug' }, 
        //janahlgren.com
        key: '#@59bdc92c6d1ec26ea92',
        //this dint work as expected
        // play: { 
        //     "play": {opacity: 0}
        // }, 
        canvas: { 
            backgroundColor:'#999999', 
            backgroundGradient: 'none'
        }, 
        plugins:  {
            controls:  { 
                "url": "/flowplayer.controls-3.1.5.swf", 
                "backgroundColor": '#ffffff',
                "backgroundGradient": 'none',
                "all":false, 
                "scrubber":true, 
                "mute":true,
                "volume":true,
                "play":true, 
                "height":24,
                "fullscreen":true,
                "autoHide": 'always',
                // "play": {opacity: 0},
                "sliderGradient": 'none',
                // tooltipGradient: 'none',
                "tooltipColor": '#333333',
                "tooltipTextColor": '#ffffff',
                "progressGradient": 'none',
                "progressColor": '#acacac', 
                "bufferGradient": 'none',
                "bufferColor": '#333333',
                "buttonColor": '#acacac', 
                "buttonOverColor": '#6d6d6d'
            }
        }
    });
};//end of player