var video;
var dayOfWeek = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var vqstring = window.location.search;
var initVideoId="";
var videoPlaying=false;
var selCat="";
var selDate="";
var selPlay="";
var videoList;
var curVideoList;
var curDay;
var curVideo;
var curCategory="featured";
var curRatingHolder="";
var autoPlayObj;
function getTranslation_rgtv(key) {
var translation;
switch(key+":"+lang) {
// status translations
case "featured:en_FR":
translation="Best Videos";
break;
case "featured:fr_FR":
translation="Les Meilleures vidéos";
break;
case "interviews:en_FR":
translation="Interviews";
break;
case "interviews:fr_FR":
translation="Interviews";
break;
case "highlights:en_FR":
translation="Highlights";
break;
case "highlights:fr_FR":
translation="Temps Forts";
break;
case "behind:en_FR":
translation="Behind the Scenes";
break;
case "behind:fr_FR":
translation="Coulisses";
break;
case "rgworld:en_FR":
translation="RG Around the World";
break;
case "rgworld:fr_FR":
translation="RG &Agrave; Travers Le Monde";
break;
default:
translation=keyValue;
break;
}
return translation;
}
$(document).ready(function(){
/***************************************************************************
function to load video list json file
***************************************************************************/
$.ajax({
url: "/"+lang+"/xml/gen/video/video.json",
dataType: 'json',
cache:true,
error: function(request,error) {
$('.videoListContainer ul').html("<div class='bold blackText' style='margin-top:20px; text-align:center;'>"+eval("noVideo_"+lang)+"</div>");
},
success: function(videoListDoc){
videoList = videoListDoc.video;
curDay = videoListDoc.curDay;
activateDayNav(curDay);
if (hasReqestedFlashVersion) {
if (typeof(autoPlayId)!='undefined') {
pvAutoStart = true;
autoPlayObj = getVideoObjById(autoPlayId);
var autoPlayFile = autoPlayObj.lowlink; 
curVideo = autoPlayObj;
loadVideoList(autoPlayObj.category,autoPlayObj.day);
$('.videoContainer .video').addClass('flash');
writeInlinePlayer('inlinePlayer', latestImageFile, autoPlayFile);
videoPlaying = true;
setVideoData();
} else {
pvAutoStart = false;
loadVideoList(curCategory,curDay);
$('.videoContainer .video').addClass('flash');
writeInlinePlayer('inlinePlayer', latestImageFile, videoList[0].lowlink);
}
} else if (Modernizr.video && Modernizr.video.h264){
if (typeof(autoPlayId)!='undefined') {
pvAutoStart = true;
autoPlayObj = getVideoObjById(autoPlayId);
var autoPlayFile = autoPlayObj.lowlink;
curVideo = autoPlayObj;
loadVideoList(autoPlayObj.category,autoPlayObj.day);
writeHTML5Player('inlinePlayer', latestImageFile, 640,360);
setNewVideo5("html5videoPlayer", autoPlayObj.lowlink);
videoPlaying = true;
setVideoData()
} else {
loadVideoList(curCategory,curDay);
writeHTML5Player('inlinePlayer', latestImageFile, 640,360);
}
} else {
loadVideoList(curCategory,curDay);
//alert('need flash');
}
},
complete: function() {
}
});
// bind clicks to play video
$(".videoListContainer li").live('click',function(){
$(".videoContainer .label").unbind('click');
$(".videoContainer .label").css('cursor','default');
$('.videoContainer .ratingContainer').show();
$(".videoListContainer li").removeClass("active");
$(this).addClass("active");
var videoIndex = parseInt($(this).attr('id').substring(6,$(this).attr('id').length));
curVideo = videoList[videoIndex];
//ratingHtml = $(".rating",this).html();
if (!$(".videoContainer .info").hasClass("active")) {
$(".videoContainer .info").addClass("active");
}		 	
$(".videoContainer .category").html(getTranslation_rgtv(curVideo.category) + "&nbsp;|&nbsp;");
$(".videoContainer .title").html(curVideo.title);
$('.videoContainer .info .date').html(curVideo.date);
setSocialUrls(curVideo);
// play the video
playVideo(curVideo);
});
// bind clicks to category
$(".categoryList .category").live('click',function(){
curCategory = $(this).attr("id");
$(".categoryList .category").removeClass("active");
$(this).addClass("active");
loadVideoList(curCategory, curDay);
measureApp('Video','category',curCategory);
});
// bind clicks to the day nav
$(".dayNavigator .day").bind('click',function(){
if ($(this).hasClass("active")) {
if ($(this).attr("class").indexOf("pre") != -1) {
curDay = "pre";
} else if ( $(this).attr("class").indexOf("post") != -1) {
curDay = "post";
} else {
curDay = $(this).text();
}
$(".dayNavigator .day").removeClass("selected");
$(this).addClass("selected");
//alert($(this).attr("class"));
loadVideoList(curCategory, curDay);
measureApp('Video','day click',curDay)
}
});
// simple hack for making video disappear if user hovers on menu
$("#nav_e ul").hover(
function(){
if ($('.videoContainer .video').hasClass('flash')) {
$("#inlinePlayer").css('visibility','hidden')
}
},
function(){
if ($('.videoContainer .video').hasClass('flash')) {		 
$("#inlinePlayer").css('visibility','visible')
}
}
);
$("#nav_f ul").hover(
function(){
if ($('.videoContainer .video').hasClass('flash')) {
$("#inlinePlayer").css('visibility','hidden')
}
},
function(){
if ($('.videoContainer .video').hasClass('flash')) {		 
$("#inlinePlayer").css('visibility','visible')
}
}
);
});
function setVideoData(){
$('.videoContainer .video').removeClass('active');
$('.videoContainer .video').addClass('active');
$(".videoListContainer li").removeClass("active");
$('.videoListContainer li[ref="'+autoPlayObj.id+'"]').addClass("active");
var videoIndex = parseInt($('.videoListContainer li[ref="'+autoPlayObj.id+'"]').attr('id').substring(6,$('.videoListContainer li[ref="'+autoPlayObj.id+'"]').attr('id').length));
curVideo = videoList[videoIndex];
if (!$(".videoContainer .info").hasClass("active")) {
$(".videoContainer .info").addClass("active");
}
$(".videoContainer .category").html(getTranslation_rgtv(curVideo.category) + "&nbsp;|&nbsp;");
$(".videoContainer .title").html(curVideo.title);
$('.videoContainer .info .date').html(curVideo.date);
$(".videoContainer .label").css('cursor','pointer');
setSocialUrls(autoPlayObj);
// set polldaddy data
$('.videoContainer .rating').html('<div id="pd_rating_holder_'+polldaddy_id+'_'+autoPlayObj.id+'">');
if (eval('typeof PDRTJS_settings_'+polldaddy_id+'_'+autoPlayObj.id +' == "undefined"')) {
eval('PDRTJS_settings_'+polldaddy_id+'_'+autoPlayObj.id+' = {"id" : polldaddy_id,	"unique_id" : polldaddy_id+"_'+autoPlayObj.id+'", "title" : "'+autoPlayObj.title+'", "permalink" : "",	"item_id" : "_'+autoPlayObj.id+'"};');
} else {
eval('delete PDRTJS_settings_'+polldaddy_id+'_'+autoPlayObj.id);
eval('delete PDRTJS_'+polldaddy_id+'_'+autoPlayObj.id);
eval('PDRTJS_settings_'+polldaddy_id+'_'+autoPlayObj.id+' = {"id" : polldaddy_id,	"unique_id" : polldaddy_id+"_'+autoPlayObj.id+'", "title" : "'+autoPlayObj.title+'", "permalink" : "",	"item_id" : "_'+autoPlayObj.id+'"};');
}
// call the polldaddy script to display the star ratings
$.getScript("http://i.polldaddy.com/ratings/rating.js",function(){},false);
}
/*************************************************************************
This returns a video object with the given id
*************************************************************************/
function getVideoObjById(vidId) {
var videoObj;
for (var i=0; i<videoList.length; i++) {
if (videoList[i].id == vidId) {
videoObj = videoList[i];
break;
}
}
return videoObj;
}
/***************************************************************************
This function loads the video html in the video list
***************************************************************************/
function loadVideoList(category,day) {
category = $.trim(category);
day = $.trim(day);
$(".dayNavigator .day").removeClass("selected");
$(".dayNavigator .day_"+day).addClass("selected");
$('.categoryList .category').removeClass("active");
$("#"+category).addClass("active");
var html = "";
for (var i=0; i<videoList.length; i++) {
var t = false;
var vcat = $.trim(videoList[i].category);
var vday = $.trim(videoList[i].day);
if ((category == "featured" && category == vcat) || (category != "featured" && category==vcat && day==vday)) {
html+='<li id="video_'+i+'" ref="'+videoList[i].id+'">';
html+='<div class="thumb"><img src="'+videoList[i].picture+'" width="108" height="60" alt="" border="0" /></div>';
html+='<div class="title">'+videoList[i].title+'</div>';
html+='<div class="caption">'+videoList[i].description+'</div>';
html+='<div class="rating">';
html+='	<div class="stars">';
var starRating=0;
try {
starRating = parseFloat(videoList[i].stars);
}catch(e){
starRating=0;
}
for (j=1; j<=5; j++) {
if (starRating >= j) {
html+='<div class="full"></div>';
} else if (starRating < j && starRating > j-1) {
html+='<div class="half"></div>';
} else {
html+='<div class="none"></div>';
}
}
html+='	</div>';
html+='</div>';
html+='</li>';
}
}
if (html.length > 0) {
$('#multimediaContent .videoListContainer ul').html(html);
} else {
$('#multimediaContent .videoListContainer ul').html("<div class='bold blackText' style='margin-top:20px; text-align:center;'>"+eval("noVideo_"+lang)+"</div>");
}
if (videoPlaying) {
$(".videoListContainer li").removeClass("active");
$('.videoListContainer li[ref="'+ curVideo.id+'"]').addClass("active");
}
}
/***************************************************************************
This function determines whether a day in the day nav should be activated
***************************************************************************/
function activateDayNav(day){
$(".dayNavigator .day").removeClass("active");
if (day=="pre") {
$(".dayNavigator .day_"+day).addClass("active");
} else if (day=="post") {
$(".dayNavigator .day").addClass("active");
} else {
$(".dayNavigator .day_pre").addClass("active");
for (var i=1; i<=parseInt(day);i++){
$(".dayNavigator .day_"+i).addClass("active");
}
}
}
/***************************************************************************
This function gets called when a video is selected for viewing
***************************************************************************/
function playVideo(obj){
videoPlaying=true;
$('.videoContainer .rating').html('<div id="pd_rating_holder_'+polldaddy_id+'_'+obj.id+'">');
if (eval('typeof PDRTJS_settings_'+polldaddy_id+'_'+obj.id +' == "undefined"')) {
eval('PDRTJS_settings_'+polldaddy_id+'_'+obj.id+' = {"id" : polldaddy_id,	"unique_id" : polldaddy_id+"_'+obj.id+'", "title" : "'+obj.title+'", "permalink" : "",	"item_id" : "_'+obj.id+'"};');
} else {
eval('delete PDRTJS_settings_'+polldaddy_id+'_'+obj.id);
eval('delete PDRTJS_'+polldaddy_id+'_'+obj.id);
eval('PDRTJS_settings_'+polldaddy_id+'_'+obj.id+' = {"id" : polldaddy_id,	"unique_id" : polldaddy_id+"_'+obj.id+'", "title" : "'+obj.title+'", "permalink" : "",	"item_id" : "_'+obj.id+'"};');
}
// call the polldaddy script to display the star ratings
$.getScript("http://i.polldaddy.com/ratings/rating.js",function(){},false);
$('.videoContainer .video').removeClass('active');
$('.videoContainer .video').addClass('active');
if(hasReqestedFlashVersion) {
setNewVideo('inlinePlayer', obj.lowlink);
measureApp('Video',obj.category,'Play','Flash', obj.lowlink);
} else if (Modernizr.video && Modernizr.video.h264) {
setNewVideo5("html5videoPlayer", obj.lowlink);
measureApp('Video',obj.category,'Play','Html5', obj.lowlink);
} else {
//location.href="/"+lang+"/flashupgrade.html";
}
}
function setSocialUrls(obj) {
$(".social").hide();
var facebookSrc = "http://www.facebook.com/plugins/like.php?locale="+lang+"&href=MEDIAURL&send=false&layout=button_count&width=100&show_faces=false&action=like&colorscheme=light&font&height=21";
var tweetSrc = '<a id="tweetBtn" href="http://twitter.com/share" class="twitter-share-button" data-url="MEDIAURL" data-text="MEDIATITLE" data-count="horizontal" data-via="rolandgarros">Tweet</a>';
var dateDir = obj.sort_date.substring(0,4)+'-'+obj.sort_date.substring(4,6)+'-'+obj.sort_date.substring(6,8);
var mediaUrl = 'http://www.rolandgarros.com/'+lang+'/multimedia/'+dateDir+'/'+obj.id.toLowerCase()+'.html';
var fbLikeUrl = facebookSrc.replace("MEDIAURL", mediaUrl);
$('#fbLikeBtn').attr("src",fbLikeUrl);
$('#tweetContainer').html(tweetSrc.replace("MEDIAURL", mediaUrl).replace("MEDIATITLE", "Roland Garros 2011 - RG TV - " + obj.title));
$.getScript("http://platform.twitter.com/widgets.js",function(){},false);
$(".social").show();
}
