$(function ()
{
/* tabs */
  var tabContainers = $('div.mainBoxContent > div');
  $('div.mainBoxContent ul.videoTab a').click(function ()
  {
      tabContainers.hide().filter(this.hash).show();

      $('div.mainBoxContent ul.videoTab li').removeClass('selected');
      $(this).parent('li').addClass('selected');

      return false;
  }).filter(':first').click();
/* End of tabs */

/* Scroller */
  $("div.scrollableArea").scrollable
  ({
    size: 3,
    clickable: false,
    items: ".videoItem"
  });
/* End of Scroller */

  /* AJax */
  var onRequestVideo = function()
  {
    $.ajax
    ({
      type: 'get',
      url: this.href,
      success: onRequestVideoSuccess
    });
    return false;
  };

  var onRequestVideoSuccess = function(result)
  {
    var toggleVideo = function(videoLink)
    {
      $('#videoReviewInner li').removeClass('current');

      $(videoLink).parent('p').parent('li').addClass("current");
      var swfUrl = 'http://www.youtube.com/v/' + $(videoLink).attr('id') + '&hl=en&fs=1&color1=0x102541&color2=0x35547a';
      swfobject.embedSWF(swfUrl, "playerShell", "360", "310", "9","/media/flash/expressInstall.swf");

      var sponsored = $(videoLink).parent('p').parent('li').find('.sponsored').text();
      var sponsoredText= "";
      if (sponsored.length > 1 )
      {
        sponsoredText = 'Sponsored by ' + sponsored;
      }
      $('#videoReviewInner #videoBar').text(sponsoredText);
    }

    /* Video panel */
    $('#videoReview').css('display', 'block');
    $('#videoReviewInner').html($(result).find("#ajaxContent"));
    $(".navBar a").click(
        function()
        {
          $('#videoReview').css('display', 'none')
        }
      );

     var videoList = $('#videoReviewInner li a');
     if (videoList.length > 0) toggleVideo(videoList[0]);

    $("#videoReviewInner li a").click(
      function()
      {
        toggleVideo(this);
        return false;
      });
  };

  $(".videoItem a:not('.init-gallery)").click(onRequestVideo);
  /* End of AJax */

  /* pretty photo */
  $("a[rel^='prettyPhoto']").prettyPhoto(
	{
		counter_separator_label: ' / ',
		theme : "light_square" 
	});
  $("a.init-gallery.text-link").click(function() {
    $(this).parent().find("a:first").click();
    return false;
  });

  /* Blog video */
  var blogList = $('#blogVideo li');
  var blogUrl = "http://media.vmixcore.com/core-flash/UnifiedVideoPlayer/UnifiedVideoPlayer.swf";

  if ( blogList.length > 0 )
  {
   blogList.each(
      function(i)
      {
        var theID = $(this).find("p").attr('id');
        var flashvars = {};
        var params =
        {
          flashvars: theID
        };
        var attributes =  {};
        swfobject.embedSWF(blogUrl, theID, "400", "332", "9","/media/flash/expressInstall.swf", flashvars, params, attributes);
      }
    )
  }


  /* End of Blog video */
});