var playerconf = {
  key: '#$c7a574d582e8b5c1581',
  onFullscreen: function() { ga_track_clip(this.getClip(), 'Fullscreen'); },
  onFullscreenExit: function() { ga_track_clip(this.getClip(), 'FullscreenExit'); },
	play: {
		url: '/contents/video/images/ra_flowplayer_play.png',
		width: 64,
		height: 64
	},
  logo: {
		url: '/contents/video/images/ra_flowplayer_logo.png',
		fullscreenOnly: false,
		displayTime: 0,
    opacity: 0.5,
    top: 10,
    right: 10
	},
  canvas: {
    backgroundColor: '#000000',
    backgroundGradient: 'none'
  },
	plugins: {
    controls: {
      volumeColor: '#ff6600',
      backgroundGradient: 'none',
      backgroundColor: 'transparent',
      progressColor: '#ff6600',
      opacity: 1.0
    }
	},
	clip: {
		autoPlay: true,
		autoBuffering: true,
		baseUrl: '/contents/video/sources',
	  scaling: 'fit',
    onStart: function(clip) {
      ga_track_clip(clip, 'Start');
      $('.thumb.current').removeClass('current');
    },
    onPause: function(clip) { ga_track_clip(clip, 'Pause'); },
    onResume: function(clip) { ga_track_clip(clip, 'Resume'); },
    onStop: function(clip) { ga_track_clip(clip, 'Stop'); },
    onFinish: function(clip) { ga_track_clip(clip, 'Finish'); }
	}
}

function ga_track_clip(clip, action) {
  _gaq.push(['_trackEvent', 'Video', action, clip.url]);
}

$(function() {

  $('.player-playlist a.thumb').click(function(obj) {
    if ($('#player-wrap').is(":hidden")) {
      $('#player-wrap').slideDown('fast');
    }
  });

  if ($.fn.cycle) {

    $('.video-tab').click(function() {
      var id = $(this).attr('href');
      var index = $(id).index();
      $('#video-cycle').cycle(index);
      $('.video-tab').removeClass('current');
      $(this).addClass('current');
      return false;
    });

    $.fn.cycle.updateActivePagerLink = function(pager, idx) {
      $('.video-tab').removeClass('current');
      var i = 1;
      for (i = 1; i < 4; i++) {
        var activeclass = 'video-group-' + i;
        if ($('#video-cycle .page').eq(idx).hasClass(activeclass)) {
          $('.video-tab.' + activeclass).addClass('current');
        }
      }
    };

    $('#video-cycle').cycle({
      speed: 0, timeout: 0, prev: '#video-prev', next: '#video-next',
      pager: '#player-tabs',
      startingSlide: $('.thumb.current').parent().index(),
      pagerAnchorBuilder: function(idx, slide) { return false; }
    });
  }
});

