// Init recommended video tabs
function video_tabs_init() {
  $('.video_rec_tabs').idTabs({
   event: '!mouseover',
   display: 'fadeIn',
   tab_filter: "li[id^='video_rec']"
  });
}

// Init video play button on the big video image.
function play_layer_init() {
  $('.play_layer').each(function(){
    var $c = $('.cbox_c', $(this).parent());
    var a = $('a', $c)[0];
    if(a) swfobject.embedSWF(a.href, a.id, "608", "480", "9", "", {}, {wmode:'opaque'});
    if($c.get(0))
      $(this).colorbox({inline:true, width:660,height:580,
                        close:'关闭', href: '#'+$c[0].id}, 
                        function(){
                          // workaround: The video object can't display after first time in IE.
                          // It seems a bug of IE browser, including IE8.
                          // Set opacity value to 1 directly doesn't work.
                          $('#colorbox').fadeTo(0, 1);
                          // Try to track the videos played outside the detail page.
                          var $track_pageview = $('.track_pageview', this);
                          if ($track_pageview[0]) {
                            var val = $track_pageview.val().split('_'), content_type = val[0], object_id = val[1];
                            $(this).append('<img src="/pageview/?url=' + escape(document.location) + '&referer=' + escape(document.referrer) + '&content_type=' + content_type + '&object_id=' + object_id + '" width="0" height="0" style="display: none;">');
                          }
                      });
  });
}

$(function() {
  video_tabs_init();
  play_layer_init();
});
