﻿$(document).ready(function() {
  $('.submenu').show();
  $('.menuvideos, .menuexplore').addClass('current');
  $('.menuvideos img').removeAttr('src').attr({ src: "res/images/videos_.png" });
  $('.menuexplore img').removeAttr('src').attr({ src: "res/images/explore-new.png" });
  $('.header .menucenter').addClass('notwoody');

  //$('#_Marketing .group').jCarouselLite({ btnNext: '#_Marketing .next', btnPrev: '#_Marketing .prev' });
  $('#_Training .group').jCarouselLite({ btnNext: '#_Training .next', btnPrev: '#_Training .prev' });

  $('.group ul li img').click(function() {
    var rel = $(this).attr('rel'),
      data = eval('(' + rel + ')'),
      params = 'playerSettings = <Playlist><AutoLoad>true</AutoLoad><AutoPlay>true</AutoPlay><DisplayTimeCode>false</DisplayTimeCode><EnableOffline>true</EnableOffline><EnablePopOut>true</EnablePopOut><StartMuted>false</StartMuted><Items> \
        <PlaylistItem> \
        <AudioCodec>WmaProfessional</AudioCodec> \
        <Description></Description> \
        <FileSize>' + data.filesize + '</FileSize> \
        <FrameRate>15.000015000015</FrameRate> \
        <Height>' + data.height + '</Height> \
        <IsAdaptiveStreaming>false</IsAdaptiveStreaming> \
        <MediaSource>' + data.file + '</MediaSource> \
        <ThumbSource></ThumbSource> \
        <Title>' + data.title + '</Title> \
        <VideoCodec>VC1</VideoCodec> \
        <Width>' + data.width + '</Width> \
        </PlaylistItem></Items></Playlist>',
      tag = '<object data="data:application/x-silverlight," type="application/x-silverlight" width="100%" height="100%"> \
          <param name="source" value="res/silverlight/MediaPlayerTemplate.xap"/> \
          <param name="onerror" value="onSilverlightError" /> \
          <param name="autoUpgrade" value="true" /> \
          <param name="minRuntimeVersion" value="3.0.40624.0" /> \
          <param name="enableHtmlAccess" value="true" /> \
          <param name="initparams" value="' + params.htmlEncode() + '"/> \
        </object>';

    $('#silverlightControlHost')
      .empty()
      .append($(tag))
      .show();
    $('#greyout').show();
    $('#videodialog').show();
    $('.close').show();

    var windowWidth = document.documentElement.clientWidth,
      popupWidth = $("#videodialog").width(),
      scrolledY = document.documentElement.scrollTop,
      left = (windowWidth - popupWidth) / 2;

    $("#videodialog").css({ 'top': scrolledY, 'left': left, 'margin-top': '112px' });
  });
});