/**
 * @author Ben
 */
$(document).ready(function() {

$.fn.scrollerExtended = function(options) {
  var defaults = {
    parentTitle: 'h3',
    panelItems: '.panel',
    seekFunc: '',
    isApi: true
  };

  var opts = $.extend(defaults, options);
  
  var api = $(this).scrollable({
     size: 1,
     keyboard: true,
     onSeek: opts.seekFunc,
     api: opts.isApi
  });
  
  var thePanels = $('.items', this).children(opts.panelItems);
   
  if(thePanels.length === 1){
    $(this).siblings('.next').addClass('disabled');
  }
  
  $('.items .panel:first ul li:first', this).addClass('first');
  $('.items .panel:first ul li:first div.hrDisguise', this).remove();
  
  if ($('.items', this).children('.panel').children('ul').children('li').children('a.selected').length > 0) {
        for (var i = 0; i <= thePanels.length; i++) {
            if ($('.items', this).children('.panel').eq(i).children('ul').children('li').children('a.selected').length > 0) {
                var activePanel = i;
                api.seekTo(activePanel);
            }
        }
    }
  
};

$('.articleList .scrollable').scrollerExtended();

$('#videoList').scrollerExtended();

$('#gameWidget .scrollable').scrollerExtended({panelItems: 'div', isApi:false});

$('#gamesViewer .scrollable').scrollerExtended();

$('#drawingList .scrollable').scrollerExtended({
    seekFunc: function(){
            var current = this.getIndex(); 
            var currentMonth = $('.panel .month', '#drawingList .scrollable .items').eq(current).text();
            $('#drawingList h3').text(currentMonth);
            }
});

$('#photoList .scrollable').scrollerExtended({
    seekFunc: function(){
            var current = this.getIndex(); 
            var currentMonth = $('.panel .month', '#photoList .scrollable .items').eq(current).text();
            $('#photoList h3').text(currentMonth);
            }
});

$('.yourEmailList .scrollable').scrollerExtended({
    seekFunc: function(){
            var current = this.getIndex(); 
            var currentMonth = $('.panel .month', '.yourEmailList .scrollable .items').eq(current).text();
            $('.yourEmailList h3').text(currentMonth);
            }
}); 

if (document.getElementById('player')) {
        $f("player", "/assets/files/flowplayer-3.1.1.swf", {
            plugins: {
                controls: {
                    // setup auto hide 
                    autoHide: 'always',
                    hideDelay: 1000,
                    durationColor: '#000000',
                    fullscreen: false,
                    timeBgColor: '#555555',
                    sliderGradient: 'none',
                    progressGradient: 'medium',
                    timeColor: '#88cdca',
                    volumeSliderColor: '#000000',
                    bufferGradient: 'none',
                    tooltipColor: '#ffffff',
                    background: 'url(/Assets/images/trans.png) repeat',
                    backgroundGradient: 'none',
                    buttonColor: '#cccccc',
                    volumeSliderGradient: 'none',
                    sliderColor: '#4752a9',
                    progressColor: '#2c4ac3',
                    tooltipTextColor: '#000000',
                    bufferColor: '#757575',
                    height: 30,
                    opacity: 0.5
                }
            }
        });


        if ($('.panel a.selected').length === 0) {
            var videoHref = $('.panel:first a:first').attr('rel');
            var videoTitle = $('.panel:first a:first').attr('title');
            $('.panel:first a:first').addClass('selected');
            $('#videoText p').html('<strong>Now playing:</strong> ' + videoTitle);
            $f().stop();
            $f().play(videoHref);
        }
        
        if ($('.panel:first a:first').hasClass('selected')) {
            $('.newCorner').removeClass('hidden');
            $('.voteCorner').removeClass('hidden');
        }
        
        

    }

    if (document.getElementById('miniVideo')) {
        $f("miniVideo", "/assets/files/flowplayer-3.1.1.swf", {
            plugins: {
                controls: {
                    // setup auto hide 
                    autoHide: 'always',
                    hideDelay: 1000,
                    durationColor: '#000000',
                    fullscreen: false,
                    timeBgColor: '#555555',
                    sliderGradient: 'none',
                    progressGradient: 'medium',
                    timeColor: '#88cdca',
                    volumeSliderColor: '#000000',
                    bufferGradient: 'none',
                    tooltipColor: '#ffffff',
                    background: 'url(/Assets/images/trans.png) repeat',
                    backgroundGradient: 'none',
                    buttonColor: '#cccccc',
                    volumeSliderGradient: 'none',
                    sliderColor: '#4752a9',
                    progressColor: '#2c4ac3',
                    tooltipTextColor: '#000000',
                    bufferColor: '#757575',
                    height: 30,
                    opacity: 0.5
                }
            }
        });
    }
   
});

function reload_parent_page() {
    //document.location.reload();
	document.location.replace(document.location.href);
}


