/* For Demo Page */

var ClipsFixed = Anon.Structure.$extend({

  __init__ : function($_selectors) {
    this.$super($_selectors);
    this.buildSlides();
    this.defineEvents();
    this.navigateToHash();
    $('.additional_link').click(function(e){
      var id = $(this).attr('href');
      if($(id).is(":visible")) {
        //Fade out if showing
        $(id).fadeOut('fast');
        e.preventDefault();
      } else {
        $(id).fadeIn('fast');
        $('html, body').animate({scrollTop:120});
        e.preventDefault();
      }
    })
    $('.additional_link_hide').click(function(e){
      $($(this).attr('href')).fadeOut('fast');
      e.preventDefault();
    })

  },
  
  navigateToHash : function(hash) {
   // this.SLIDES.jumpToSlide(window.location.hash.replace("/", ""));
    
    var videoId = window.location.hash.replace("/", "");
    var videoIdNoHash = videoId.replace("#", "");
    
    if(videoIdNoHash == 'additional')
    {
      this.showAdditional();
      return;
    }
    if(videoIdNoHash == 'next' || videoIdNoHash == 'prev')
    {
      return;
    }

    $('.videoClip').fadeOut();
 
    if(!videoId) {
      videoIdNoHash = $('.videoClip').first().attr('id');
      videoId = "#" + videoIdNoHash;
    }
    else
    {
      $('html, body').animate({scrollTop:120});
    }
      
      //$('html, body').animate({scrollTop:0});
      $(videoId).fadeIn();
      
      
      if(FlashDetect.installed) {
        var videoMP4Url = $('#vid_' + videoIdNoHash).attr("data-video-url");
      
        var flashVars = { source: videoMP4Url, autoPlay: 'true', autoRewind: 'true', clipId: videoIdNoHash };
        var params = {bgcolor: '#000000', menu: 'false', quality:'high', allowScriptAccess:'always', allowFullScreen:'true', wmode:'opaque' }
        
        var attributes = { id: videoId, name:'VideoPlayer' }; // give an id to the flash object
        
        swfobject.embedSWF('/swf/VideoPlayer.swf?v=2',  'vid_' + videoIdNoHash, "820", "490", '10.1.0', '/swf/expressInstall.swf', flashVars, params, attributes);
      } else {
        var $video_container = $('#vid_' + videoIdNoHash),
        $video = $video_container.find('video'),
        videoMobileUrl = $video_container.attr("data-video-url-iphone");
        $('video').html("");
        if(!$video) { // set src&type attribute for ie9/android3.1 because it does not add the source child-elements
          $video.attr('src', videoMobileUrl ).attr('type','video/mp4');
        } else {
          $video.append('<source src="' + videoMobileUrl + '" type="video/mp4" />');
        }
      }  

    
  },
  showAdditional : function() {
  },
  hideAdditional : function() {
    
  },
  buildSlides : function() {
    var that = this;
    $('.videoClip').hide();

//    $('.videoClip').first().css({'visibility': 'visible'});

    $(window).bind('hashchange', function() {
      that.navigateToHash();
    });  
    
  },
  
  defineEvents : function() {
  
    var $self = this;
    
    $(window).bind({
    });
  }

});





$(document).ready(function(){
  /*var clips = new Clips({
    'logo'      : '#hd_logo',
    'nav'       : '#hd_nav', 
    'sub_nav'   : '#hd_sub_nav',
    'flap'      : '#titleFlap',
    'container' : '#bd_slides',
    'slide'     : '.slide',
    'bd_nav'    : '.bd_nav',
    'bd'        : '#bd',
    'search'    : '#hd_search',
    'related'   : '.clip a',
    'secondary' : '#bd_additional',
    'details'   : {
      'title'   : 'slideTitle',
      'subTitle': 'slideSubTitle'
    },
    'additional' : {
      'overlay'  : '#bd_overlay',
      'link'     : 'a#additional_link',
      'wrapper'  : '.additionalTextWrapper',
      'text'     : '.additionalText'
    }
  });*/
  
  $('#videoGroupContainer').css({'visibility':'visible'});
  
  var clips = new ClipsFixed({
    'slideContainer' : '#videoClips',
    'slide' : '.videoClip',
    'details' : '.videoClipDetails',
    'player' : '.videoClipPlayer'
  });
  
});
