
var driver = driver || "",
handleAddPlaylistItem = handleAddPlaylistItem || function() {},
handleScrubbarEvent = handleScrubbarEvent || function() {},
cvpReady = false,
waitingVideo = "",
navXml = "",
currentVideoId = "",
lastQueuedId = "",
currentVideoObj = new Object(),
currentSceneId = "",
collectionIdHolder = "",
currentSectionMap = new Object(),
currentTeaserMap = new Object(),
currentTodaysTopMap = new Object(),
currentPlaylistMap = new Object(),
currentFavoritesMap = new Object(),
currentFriendsMap = new Object(),
randomnumber=Math.floor(Math.random()*100),
//OptimostCollection1 = "223849",
//OptimostVideo1 = "223869",
OptimostCollection1 = "226204",
OptimostVideo1 = "226250",
//OptimostCollection2 = "224209",
//OptimostVideo2 = "224229",
OptimostCollection2 = "226205",
OptimostVideo2 = "226252",
//OptimostCollection2 = "909999999999999999",
//OptimostVideo2 = "909999999999999999",
currentAlsoLikeMap = new Object(),
currentScenesArray = new Array(),
deepLinkedVideo = deepLinkedVideo || "",
deepLinkedCategory = deepLinkedCategory || "",
friendsFavoritesId = friendsFavoritesId || "",
lastTrackedVideo = new Object();
$(document).ready(function() {
// initialize the page
Dramavision.init();
// show the corners
$('#dramavisionTodaysTopBtn').corner("top");
$('#dramavisionFavoritesBtn').corner("top");
$('.dramavisionNavItem').corner("top");
});
function ellipsis(d,max) {
if (d.length > max) {
getellipsis = '...';
} else {
getellipsis = '';
}
var too = d.substr(0,max+1) + getellipsis;
return too;
}
var Breadcrumbs = {
breadcrumbHome : function() {
$(".breadcrumbHome").click(function(e) {
selectedCollection = $(this).attr('name');
SectionNav.load(selectedCollection);
$("#rightCrumbSection").html('');
$("#rightCrumbTitle").html('');
$(".headersection").html('featured');
$(".headertitle").html('');
$("#rightCrumbShow").html('');
e.preventDefault();
return false;
});
},
rightCrumbSection : function(mycollection) {
$("#rightCrumbSection").click(function(e) {
selectedCollection = $(this).data('name');
SectionNav.load(selectedCollection);
$(".headersection").html('');
$(".headertitle").html('');
$("#rightCrumbTitle").html('');
$("#rightCrumbShow").html('');
e.preventDefault();
return false;
});
},
rightCrumbShow : function() {
$("#rightCrumbShow").livequery("click", function(e){
SectionNav.load(selectedCollection);
var currentNavId = $(this).data('sectionId');
var selectDiv = $("#" + currentNavId);
$("#rightCrumbTitle").html('');
SectionNav.toggle(selectDiv);
e.preventDefault();
return false;
});
},
dramavisionNavItem : function() {
$(".dramavisionNavItem").click(function(e) {
deepLinkedCategory = "";
selectedCollection = $(this).attr('name');
$("#rightCrumbTitle").html('');
$("#rightCrumbShow").html('');
SectionNav.load(selectedCollection);
$(".headersection").html('');
$(".headertitle").html('');
MainNav.highlightSelected();
e.preventDefault();
return false;
});
}
}
var Dramavision = {
MaxVideos : 200,
PageUrl : '/cvp/index.jsp',
NavUrl : '/video/navigation/getCollections.jsp?oid=185669',
CollectionUrl : '/video/navigation/getCollectionById/',
//NavUrl : '/content/services/getCollections.do?id=223890',
//CollectionUrl : '/content/services/getCollectionByContentId.do?offset=0&sort=',
AlsoLikeUrl : '/video/navigation/getRelatedFranchiseCollections/',
VideoJsonUrl : '/exclude/videoplayer/videojson/',
SendToFriendUrl : 'http://tbs.com/processors/dramavision_cvp/sendtoafriend/',
ShareFavsUrl : '/processors/dramavision_cvp/sharefavorites/',
SearchUrl : '/search/dramavisionresults/?offset=0&sort=&limit=50&type=video',
FavoritesUrl : '/video/navigation/getVideoById/',
SharedFavoritesUrl : 'http://tbs.com/dramavision_cvp/getSharedFavorites/',
TodaysTopId : '185673',
RelatedFranchiseDefault : '349405',
FavoritesCookie : 'My-TBS-Favs',
maxFavorites : 25,
init : function() {
$.ajax({
type: "GET",
url : Dramavision.NavUrl,
cache : true,
dataType: "xml",
success : function(data) {
navXml = data;
if (waitingSection !== "") {
// if there was a section waiting for the nav to load, load it now
SectionNav.load(waitingSection);
}
}
});
// check for deeplinked video id
if (deepLinkedVideo !== "") {
currentVideoId = deepLinkedVideo;
$.ajax({
type: "GET",
url : Dramavision.FavoritesUrl + "?id=" + deepLinkedVideo,
cache : true,
dataType: "xml",
success : function(data) {
Dramavision.parseDeepLinkedVideo(data);
}
});
}
// initialize the other components
MainNav.init();
PlaylistArea.init();
TodaysTop.loadVideos();
VideoButtons.init();
Search.init();
Favorites.init();
SectionNav.init();
loadPlayer();
if (friendsFavoritesId != "") {
FriendsFavorites.init();
}
// activate dramatic pause button
$("#dramavisionDramaticPause").bind("click", function(e) {
TURNERPLAYER.pause();
$("#dramavisionDramaticPlay").show();
e.preventDefault();
});
$("#dramavisionDramaticPlay").bind("click", function(e) {
if (confirm("Are you ready to return to the previous screen?")) {
TURNERPLAYER.resume();
$("#dramavisionDramaticPlay").hide();
}
e.preventDefault();
});
Breadcrumbs.rightCrumbShow();
},
playVideo : function(videoId, teaserMap, queue) {
currentVideoId = videoId;
queueVideoId = null;
currentPlaylistMap = teaserMap;
if (teaserMap[videoId] !== null) {
currentVideoObj = teaserMap[videoId];
// check for scenes; if they exist, play the first one; if no scenes, play the video
//currentScenesArray = new Array();
//Scenes.empty();
//Dramavision.playScene(videoId, queue);
if (teaserMap[videoId].segments.length > 0) {
$("#embed").css("visibility", "hidden");
currentScenesArray = teaserMap[videoId].segments;
Scenes.load(teaserMap[videoId].segments);
//alert(currentScenesArray[0].videoId);
//Dramavision.playScene(currentScenesArray[0].videoId, queue);
// for optimost - if the video is an optimost video, the c4o should be 1st in the segment list. If you're not playing optimost, skip that 1st segment
if (currentScenesArray[0].videoId == OptimostCollection1 || currentScenesArray[0].videoId == OptimostCollection2) {
if (getCookie("optiTest") == 'true' || startOptimostTime != 'true') {
$("#showPlaylist_container #sceneSelection").css("visibility","visible");
Dramavision.playScene(currentScenesArray[1].videoId, queue);
} else if (videoId == OptimostCollection2) {
$("#showPlaylist_container #sceneSelection").css("visibility","hidden");
if (cvpReady) {
setCookie("optiTest", "true", 365);
playViaOptimost(OptimostVideo2);
} else {
waitingOptimostVideoId = OptimostVideo2;
}
} else if (videoId == OptimostCollection1) {
$("#showPlaylist_container #sceneSelection").css("visibility","hidden");
if (cvpReady) {
setCookie("optiTest", "true", 365);
playViaOptimost(OptimostVideo1);
} else {
waitingOptimostVideoId = OptimostVideo1;
}
}
} else if (currentScenesArray[0].videoId == OptimostVideo1 || currentScenesArray[0].videoId == OptimostVideo2) {
if (getCookie("optiTest") == 'true' || startOptimostTime != 'true') {
//optimost has already played
$("#showPlaylist_container #sceneSelection").css("visibility","visible");
Dramavision.playScene(currentScenesArray[1].videoId, queue);
} else {
//optimost has not played yet.. do a randomnumber test to determine if we should play
if (randomnumber <= 1) {
//alert('play' + randomnumber);
if (videoId == OptimostVideo1) {
collectionIdHolder = OptimostCollection1;
} else if (videoId == OptimostVideo2) {
collectionIdHolder = OptimostCollection2;
}
if (cvpReady) {
setCookie("optiTest", "true", 365);
$("#showPlaylist_container #sceneSelection").css("visibility","hidden");
playViaOptimost(currentScenesArray[0].videoId);
} else {
waitingOptimostVideoId = currentScenesArray[0].videoId;
}
} else {
setCookie("optiTest", "true", 365);
Dramavision.playScene(currentScenesArray[1].videoId, queue);
}
}
} else {
Dramavision.playScene(currentScenesArray[0].videoId, queue);
$("#showPlaylist_container #sceneSelection").css("visibility","visible");
}
} else {
$("#embed").css("visibility", "visible");
$("#showPlaylist_container #sceneSelection").css("visibility","hidden");
currentScenesArray = new Array();
Scenes.empty();
Dramavision.playScene(videoId, queue);
}
var myvid = teaserMap[videoId];
var myvidurl = "/cvp/index.jsp?oid=" + videoId;
// close video button area
$("#videoButtonArea").slideUp(200);
VideoButtons.reset();
// fill in video info
$('#videoThumb').html('<img width="96" height="72" src="'+myvid.thumb+'">');
$('#videoTitle').html(myvid.heading);
$('#videoAiring').html(myvid.description);
if (myvid.seasonNumber.length > 0 && myvid.episodeNumber.length > 0 && myvid.airDate.length > 0) {
$('#videoBlurb').html(myvid.franchiseName + ' - Season ' + myvid.seasonNumber + ' - Ep. ' + myvid.episodeNumber + ' - Air Date: ' + myvid.airDate);
} else if (myvid.airDate.length == 0) {
$('#videoBlurb').html(myvid.franchiseName + ' - Season ' + myvid.seasonNumber + ' - Ep. ' + myvid.episodeNumber);
}
// populate share, link, embed forms
$("#linkContent textarea")[0].value = "http://www.tbs.com" + myvidurl + "&eref=sharethisUrl";
if (myvid.embeddable === 'N') {
$("#embedContent textarea")[0].value = "";
$("#embedBtn").hide();
} else {
$("#embedContent textarea")[0].value = "<object width='442' height='375' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' id='ep'>"
+ "<param name='allowfullscreen' value='true' />"
+ "<param name='allowscriptaccess' value='always' />"
+ "<param name='movie' value='http://i.cdn.turner.com/tegwebapps/tbs/tbs-www/cvp/tbs_432x243_embed.swf?context=embed&videoId="+ videoId +"' />"
+ "<param name='bgcolor' 'value='#FFFFFF' />"
+ "<embed src='http://i.cdn.turner.com/tegwebapps/tbs/tbs-www/cvp/tbs_432x243_embed.swf?context=embed&videoId="+ videoId +"' type='application/x-shockwave-flash' bgcolor='#FFFFFF' allowfullscreen='true' allowscriptaccess='always' width='442' height='375'>"
+ "</embed>"
+ "</object>";
$("#embedBtn").show();
}
/* set the bookmark values
var bookMarkTitle = "http://www.tbs.com" + myvidurl + " on TBS.com";
if ($("#deliciousForm input[@type='hidden']")[0]) {
$("#deliciousForm input[@type='hidden']")[0].value = myvidurl + "&eref=sharethisDelicious";
$("#deliciousForm input[@type='hidden']")[1].value = bookMarkTitle;
$("#diggForm input[@type='hidden']")[0].value = myvidurl + "&eref=sharethisDigg";
$("#diggForm input[@type='hidden']")[1].value = bookMarkTitle;
$("#facebookForm input[@type='hidden']")[0].value = myvidurl + "&eref=sharethisFacebook";
$("#facebookForm input[@type='hidden']")[1].value = bookMarkTitle;
$("#simpyForm input[@type='hidden']")[0].value = myvidurl + "&eref=sharethisSimpy";
$("#simpyForm input[@type='hidden']")[1].value = bookMarkTitle;
}*/
// highlight the playing video
TeaserArea.highlightPlaying();
} else {
$('#videoTitle').empty();
$('#videoAiring').empty();
$('#videoBlurb').empty();
$("#linkContent textarea")[0].value = "";
$("#embedContent textarea")[0].value = "";
}
// ***Baynote update - dbs **
if (teaserMap[videoId] !== null) {
currVideo = teaserMap[videoId];
currHeader = currVideo.heading;
if(typeof baynote_track_video == 'function') {
baynote_track_video(videoId,currHeader);
}
}
},
queueNext : function() {
// find the next video id for playing one after another
// queue the next video
var videoReached = false;
if (currentPlaylistMap.orderArray != undefined) {
for(var i = 0; i < currentPlaylistMap.orderArray.length; i++) {
if (videoReached) {
Dramavision.playVideo(currentPlaylistMap.orderArray[i], currentPlaylistMap, true);
break;
}
if (currentPlaylistMap.orderArray[i] == currentVideoId) {
videoReached = true;
}
}
}
},
playNext : function() {
// find the next video id for playing one after another
// play the next scene if one exists
var sceneReached = false;
if (currentScenesArray.length > 0) {
for(var i = 0; i < currentScenesArray.length; i++) {
if (sceneReached) {
Dramavision.playScene(currentScenesArray[i].videoId);
return;
}
if (currentScenesArray[i].videoId == currentSceneId) {
sceneReached = true;
}
}
}
// play the next video
var videoReached = false;
if (currentPlaylistMap.orderArray != undefined) {
for(var i = 0; i < currentPlaylistMap.orderArray.length; i++) {
if (videoReached) {
Dramavision.playVideo(currentPlaylistMap.orderArray[i], currentPlaylistMap);
break;
}
if (currentPlaylistMap.orderArray[i] == currentVideoId) {
videoReached = true;
}
}
}
},
playScene : function(videoId, queue) {
// play the selected scene
// play the video
currentSceneId = videoId;
Scenes.highlightPlaying(currentSceneId);
if (cvpReady) {
if (queue && videoId != lastQueuedId) {
TURNERPLAYER.queue(videoId);
lastQueuedId = videoId;
} else if (!queue) {
TURNERPLAYER.play(videoId,'');
lastQueuedId = "";
}
} else {
loadPlayer();
waitingVideo = videoId;
}
},
updateVideoInfo : function(videoId) {
var videoData = $.evalJSON(TURNERPLAYER.getContentEntry(videoId));
var videoTitleContent = ellipsis(videoData.franchise + ': ' + videoData.headline,60);
$('#videoTitle2').html(videoTitleContent);
$('#videoAiring2').html(videoData.tunein);
$('#gigyaFavAdd').attr('href', Dramavision.PageUrl + '?oid=' + videoId);
$('#gigyaShowLink').attr('href', videoData.franchiseLinkUrl);
AlsoLike.loadVideos(videoData.franchiseId,videoData.categoryId);
//used to be for gigya loadContent(videoData.franchise,Dramavision.PageUrl+'?oid='+videoId);
// switch the background skin for just for laughs
if (videoData.franchiseId == '363193') {
// alert('test alert: jfl ' + videoData.franchiseId);
switch_style('stylejfl');
$('#gigyaGotoshowsite').attr('src', 'http://i.tbs.com/v5cache/TBS/Images/Dynamic/i75/btn_gotoshowsite_grn_072120100647.png');
$('#gigyaAddtoplaylist').attr('src', 'http://i.tbs.com/v5cache/TBS/Images/Dynamic/i75/btn_addtoplaylist_grn_072120100647.png');
$('#searchSubmitBtn').attr('src', 'http://i.cdn.turner.com/v5cache/TBS/cvp/images/jfl/btn_go.png');
$('#gigyaInfo').attr('src', 'http://i.tbs.com/v5cache/TBS/Images/Dynamic/i75/btn_info_grn_072120100647.png');
$('#sceneSelectionImage').attr('src', 'http://i.tbs.com/v5cache/TBS/Images/Dynamic/i75/btn_sceneselection_grn_072120100647.png');
$('#embedImage').attr('src', 'http://i.tbs.com/v5cache/TBS/Images/Dynamic/i75/btn_embed_grn_072220101036.png');
$('#linkImage').attr('src', 'http://i.tbs.com/v5cache/TBS/Images/Dynamic/i75/btn_link_grn_072120100647.png');
$('#shareImage').attr('src', 'http://i.tbs.com/v5cache/TBS/Images/Dynamic/i75/btn_share_grn_072120100647.png');
$('#logolink').attr('href', 'http://www.justforlaughschicago.com')
return false;
} else {
// alert('test alert: ' + videoData.franchiseId);
switch_style('stylemain');
$('#gigyaGotoshowsite').attr('src', 'http://i.cdn.turner.com/v5cache/TBS/cvp/images/btn_gotoshowsite.gif');
$('#gigyaAddtoplaylist').attr('src', 'http://i.cdn.turner.com/v5cache/TBS/cvp/images/btn_addtoplaylist.gif');
$('#searchSubmitBtn').attr('src', 'http://i.cdn.turner.com/v5cache/TBS/cvp/images/btn_go.gif');
$('#gigyaInfo').attr('src', 'http://i.cdn.turner.com/v5cache/TBS/cvp/images/btn_info.png');
$('#sceneSelectionImage').attr('src', 'http://i.cdn.turner.com/v5cache/TBS/cvp/images/btn_sceneselection.png');
$('#embedImage').attr('src', 'http://i.cdn.turner.com/v5cache/TBS/cvp/images/btn_embed.png');
$('#linkImage').attr('src', 'http://i.cdn.turner.com/v5cache/TBS/cvp/images/btn_link.png');
$('#shareImage').attr('src', 'http://i.cdn.turner.com/v5cache/TBS/cvp/images/btn_share.png');
$('#logolink').attr('href', 'http://www.tbs.com')
return false;
}
// activate add to favorites button
$("#fulleps .teaserAdd").unbind("click");
$("#fulleps .teaserAdd").bind("click", function(e) {
var videoId = $(this).attr('href');
Favorites.add(currentPlaylistMap[videoId.split("?oid=")[1]]);
e.preventDefault();
return false;
});
if (videoData.parentId == "") {
currentVideoId = videoId;
} else {
currentVideoId = videoData.parentId;
}
// highlight the playing video
TeaserArea.highlightPlaying();
},
parseDeepLinkedVideo : function(data) {
// parse the xml to play the video
var deepLinkedVideoMap = new Object();
var orderArray = new Array();
if ($(data).find('episode').length > 0) {
$(data).find('episode').each(function() {
var newvid = Util.storeVideoNode($(this));
orderArray.push(newvid.videoId);
deepLinkedVideoMap[newvid.videoId] = newvid;
});
// keep up with the order the video objects are stored in the array; used for playing through a list
deepLinkedVideoMap.orderArray = orderArray;
if (deepLinkedVideoMap.orderArray[0] !== undefined && deepLinkedVideoMap.orderArray[0] !== "") {
Dramavision.playVideo(deepLinkedVideoMap.orderArray[0], deepLinkedVideoMap);
} else {
currentVideoId = "";
TodaysTop.playFirstVideo();
}
}
},
Track : function(obj) {
// 'page' tracking; video tracking is handled the player
/* STILL WANT TO TRACK? IF SO, SHOULD UPDATE FOR TBS PROPS AND EVARS
window.s = window.s || {tl : function(){}, t : function(){}};
var tmp = "";
for(var name in obj) {
s[name] = obj[name];
tmp += " **" + name + ":" + obj[name];
}
//alert(tmp);
if (obj.pageName == undefined) {
// track as event
//s.tl('video event', 'o', 'video event');
s.t();
} else {
// track as page
s.t();
}
*/
}
};
// controller for video info buttons
var VideoButtons = {
init : function() {
// activate play info buttons
function hideAllNav(){
$("#videoButtonArea").hide();
$("#theSceneContainer").hide();
$("#theInfoContainer").hide();
$("#embedContentContainer").hide();
$("#linkContentContainer").hide();
$("#socialContentContainer").hide();
}
$("#showPlaylist_container #sceneSelection").bind("click", function(e) {
//VideoButtons.activate(this, $("#sceneContent"));
hideAllNav();
$("#theSceneContainer").show();
$("#videoButtonArea").show();
//checkExTime();
e.preventDefault();
});
$("#showPlaylist_container #info").bind("click", function(e) {
//VideoButtons.activate(this, $("#sceneContent"));
hideAllNav();
$("#theInfoContainer").show();
$("#videoButtonArea").show();
//checkExTime();
e.preventDefault();
});
$("#showPlaylist_container #embed").bind("click", function(e) {
// VideoButtons.activate(this, $("#embedContent"));
hideAllNav();
$("#embedContentContainer").show();
$("#videoButtonArea").show();
//checkExTime();
e.preventDefault();
});
$("#showPlaylist_container #link").bind("click", function(e) {
// VideoButtons.activate(this, $("#embedContent"));
hideAllNav();
$("#linkContentContainer").show();
$("#videoButtonArea").show();
//checkExTime();
e.preventDefault();
});
$("#showPlaylist_container #share").bind("click", function(e) {
// VideoButtons.activate(this, $("#socialContent"));
hideAllNav();
$("#socialContentContainer").show();
$("#videoButtonArea").show();
//checkExTime();
e.preventDefault();
});
$("#videoButtonAreaClose").bind("click", function(e) {
$("#theSceneContainer").slideUp(200);
VideoButtons.reset();
e.preventDefault();
});
$("#videoInfoClose").bind("click", function(e) {
$("#theInfoContainer").slideUp(200);
VideoButtons.reset();
e.preventDefault();
});
$("#embedButtonAreaClose").bind("click", function(e) {
$("#embedContentContainer").slideUp(200);
VideoButtons.reset();
e.preventDefault();
});
$("#linkCopyBtnClose").bind("click", function(e) {
$("#linkContentContainer").slideUp(200);
VideoButtons.reset();
e.preventDefault();
});
$("#shareAreaClose").bind("click", function(e) {
$("#socialContentContainer").slideUp(200);
VideoButtons.reset();
e.preventDefault();
});
$("#embedCopyBtn").bind("click", function(e) {
Util.copyToClipboard($("#embedContent textarea"));
e.preventDefault();
});
$("#linkCopyBtn").bind("click", function(e) {
Util.copyToClipboard($("#linkContent textarea"));
e.preventDefault();
});
$("#shareSendBtn").bind("click", function(e) {
if (Validate.validateEmailForm(document.shareVideo)) {
var inputs = [];
$(':input', '#shareVideo').each(function() {
inputs.push(this.name + '=' + escape(this.value));
});
var pageName = currentVideoObj.heading + ":(" + currentVideoObj.videoId + ")";
Dramavision.Track({eVar2:pageName, eVar3:pageName, events:"event6"});
$.ajax({
url : Dramavision.SendToFriendUrl,
data: inputs.join('&'),
dataType : 'html',
cache : false,
error : function(req) {
var msg = (req.readyState !== 4) ? "incomplete request" : req.statusText;
$("#shareConfirmation").html("There was an error sending your request.<br><br>Please try again later.");
// $("#shareContent").hide();
$("#shareConfirmation").show();
},
success : function(html){
$("#shareConfirmation").html("Your email has been sent.<br><br>Keep watching videos on TBS.com and share often!");
//$("#shareContent").hide();
$("#shareConfirmation").show();
}
});
}
e.preventDefault();
});
},
activate : function(btn, parent) {
// highlight the active button
VideoButtons.reset();
// $(btn).css("background-color", "#0C0C0C");
$(btn).css("cursor", "default");
/* Clear "friend" fields, but leave "your" fields populated */
// for(var i = 2, l = $("#shareContent input[@type='text']").length; i < l; i++) {
// $("#shareContent input[@type='text']")[i].value = "";
// }
// $("#shareContent textarea")[0].value = "";
$("#shareConfirmation").hide();
$(parent).show();
$("#videoButtonArea").fadeIn(200);
},
deactivate : function(btn, parent) {
// remove button highlight
// $(btn).css("background-color", "#0C0C0C");
$(btn).css("cursor", "pointer");
$(parent).hide();
},
reset : function() {
// remove button highlights
VideoButtons.deactivate($("#showPlaylist_container #sceneSelection"), $("#theSceneContainer"));
VideoButtons.deactivate($("#showPlaylist_container #info"), $("#embedContentContainer"));
VideoButtons.deactivate($("#showPlaylist_container #embed"), $("#embedContentContainer"));
VideoButtons.deactivate($("#showPlaylist_container #link"), $("#linkContentContainer"));
VideoButtons.deactivate($("#showPlaylist_container #share"), $("#socialContentContainer"));
}
}
var Scenes = {
numScenes : 0,
numPerPage : 4,
currentPage : 0,
divPad : 15,
init : function() {
// activate next/prev buttons
$("#scenePrevBtn").bind("click", function(e) {
Scenes.slidePrev();
// e.preventDefault();
return false;
});
$("#sceneNextBtn").bind("click", function(e) {
Scenes.slideNext();
// e.preventDefault();
return false;
});
},
activate : function() {
// activate play links
$("#sceneContent .teaserPlay").bind("click", function(e) {
var videoId = $(this).attr('href');
Dramavision.playScene(videoId.split("?oid=")[1]);
//checkExTime();
e.preventDefault();
return false;
});
},
load : function(segments) {
// populate the scenes
$("#sceneContent #sceneTeasers").empty();
$("#sceneContent #sceneTeasers").css("margin-left", Scenes.divPad + "px");
Scenes.numScenes = 0;
Scenes.currentPage = 0;
var sceneHtml = "";
// for optimost - if the video is an optimost video, the c4o should be 1st in the segment list. If you're not playing optimost, skip that 1st segment
if (startOptimostTime == 'true' || (segments[0].videoId == OptimostVideo1 || segments[0].videoId == OptimostVideo2)) {
var startSegments = 1;
} else {
var startSegments = 0;
}
for (var i = startSegments; i < segments.length; i++) {
var segment = segments[i];
sceneHtml = sceneHtml.concat('<div id="sceneTeaserItem_' + segment.videoId + '" class="sceneTeaserItem"><a href="' + Dramavision.PageUrl + '?oid=' + segment.videoId + '" class="teaserPlay" title="play video">');
sceneHtml = sceneHtml.concat('<img src="' + segment.thumb + '" width="96" height="72" border="0" id="sceneImage"></a><br>');
sceneHtml = sceneHtml.concat('<a href="' + Dramavision.PageUrl + '?oid=' + segment.videoId + '" class="teaserPlay" title="play video">' + segment.heading + '</a></div>');
Scenes.numScenes++;
}
$("#sceneContent #sceneTeasers").append(sceneHtml);
Scenes.activate();
Scenes.updateSlideButtons();
if (Scenes.numScenes > 1) {
//$("#videoBotSce").show();
//$("#videoBotGig").hide();
}
else {
// $("#videoBotSce").hide();
$("#theSceneContainer").hide();
//$("#videoBotGig").show();
}
},
slidePrev : function() {
// slide to the previous page
Scenes.currentPage--;
if (Scenes.currentPage < 0) {
Scenes.currentPage = 0;
} else {
Scenes.updateSlideButtons();
}
Scenes.slide();
},
slideNext : function() {
// slide to the next page
var numPages = Math.ceil(Scenes.numScenes / Scenes.numPerPage);
Scenes.currentPage++;
if (Scenes.currentPage >= numPages) {
Scenes.currentPage = (numPages - 1);
} else {
Scenes.updateSlideButtons();
}
Scenes.slide();
},
slide : function() {
var left = -1 * $("#sceneContent #sceneContainer").width() * Scenes.currentPage + Scenes.divPad;
// no need to animate if we're already there
if (left != parseInt($("#sceneContent #sceneTeasers").css("margin-left"))) {
$("#sceneContent #sceneTeasers").animate({ 'marginLeft': left }, 'slow');
}
},
updateSlideButtons : function() {
// decide whether or not to display the pointer cursor
var numPages = Math.ceil(Scenes.numScenes / Scenes.numPerPage);
if (Scenes.currentPage > 0) {
$("#sceneContent #scenePrevBtn").css("display", "block");
$("#sceneContent #scenePrevBtn").css("cursor", "pointer");
} else {
$("#sceneContent #scenePrevBtn").css("cursor", "default");
$("#sceneContent #scenePrevBtn").css("display", "none");
}
if (numPages > 1 && Scenes.currentPage < (numPages - 1)) {
$("#sceneContent #sceneNextBtn").css("cursor", "pointer");
$("#sceneContent #sceneNextBtn").css("display", "block");
} else {
$("#sceneContent #sceneNextBtn").css("cursor", "default");
$("#sceneContent #sceneNextBtn").css("display", "none");
}
},
highlightPlaying : function(videoId) {
// highlight the currently playing scene
// $("#sceneTeasers div").css("background-color", "#7D4E08");
// $("#sceneTeaserItem_" + videoId).css("background-color", "#7e7f81");
}, empty : function() {
// remove the scenes and hide the scene selection button
$("#sceneContent #sceneTeasers").empty();
//$("#videoBotSce").hide();
//$("#videoBotGig").show();
}
}
// controller for the teaser area
var TeaserArea = {
init : function() {
// activate teaser play links
$("#fulleps .teaserPlay").bind("click", function(e) {
var videoId = $(this).attr('href');
$('.paginatePlease').removeClass("paginatePleaseActive");
$(this).parent("div").parent("div").addClass("paginatePleaseActive");
Dramavision.playVideo(videoId.split("?oid=")[1], currentTeaserMap);
e.preventDefault();
return false;
});
// activate add to favorites button
$(".teaserAdd").unbind("click");
$(".teaserAdd").bind("click", function(e) {
var videoId = $(this).attr('href');
Favorites.add(currentTeaserMap[videoId.split("?oid=")[1]]);
e.preventDefault();
return false;
});
TeaserArea.highlightPlaying();
},
loadVideos : function(collection) {
// get the teaser xml file
$('#fulleps').html('<br><br><br><br> &nbsp; &nbsp; &nbsp; loading...');
$.ajax({
type: "GET",
url : Dramavision.CollectionUrl + "?oid=" + collection,
//url : Dramavision.CollectionUrl + "&limit=" + Dramavision.MaxVideos + "&id=" + collection,
cache : true,
dataType: "xml",
success : function(data) {
TeaserArea.populate(data);
}
});
},
populate : function(data) {
if ($(data).find('episode').length == 0) {
TeaserArea.error();
} else {
// parse the xml and display the teasers
currentTeaserMap = new Object();
var videoCount = 0;
var orderArray = new Array();
var teaserHtml = '<div id="vidResultsList">';
var altText = '';
var mainText = '';
var name1 = '';
teaserHtml = teaserHtml.concat('<div style="height: 50px;"><div id="scriptspaginate" class="paginationstyle" style="width: 370px; text-align: right"><a href="#" rel="first"><< first &nbsp; | </a> <a href="#" rel="previous">< prev</a> <span class="paginateinfo" style="margin: 0 8px; font-weight: bold"></span> <a href="#" rel="next">next ></a> <a href="#" rel="last"> | &nbsp; last >></a></div></div>');
$(data).find('episode').each(function() {
var newvid = Util.storeVideoNode($(this));
orderArray.push(newvid.videoId);
currentTeaserMap[newvid.videoId] = newvid;
teaserHtml = teaserHtml.concat('<div id="scriptspaginate" class="paginatePlease teaser_' + newvid.videoId + '"><div name="' + newvid.tveMode + '" style="float: left; width: 105px; padding-top: 7px;">');
teaserHtml = teaserHtml.concat('<a href="' + Dramavision.PageUrl + '?oid=' + newvid.videoId + '" class="teaserPlay" title="play video">');
if (newvid.thumb.length > 0) {
teaserHtml = teaserHtml.concat('<img src="' + newvid.thumb + '" width="96" height="72" border="0" style="border: 1px solid #000;">');
} else {
teaserHtml = teaserHtml.concat('<img src="http://i.tbs.com/v5cache/TBS/images/static/2007/spacer.gif" width="96" height="72" border="0" style="border: 1px solid #000;">');
}
teaserHtml = teaserHtml.concat('</a>');
teaserHtml = teaserHtml.concat('</div>');
teaserHtml = teaserHtml.concat('<div id="rightText" style="float: left; width: 240px; padding-top: 7px;">');
teaserHtml = teaserHtml.concat('<a href="' + Dramavision.PageUrl + '?oid=' + newvid.videoId + '" class="teaserPlay" title="play video">');
teaserHtml = teaserHtml.concat(ellipsis(newvid.heading,33) + '</a><br>');
teaserHtml = teaserHtml.concat('<div id="textToggle1">');
if (newvid.collectionName.length > 0) {
name1 = newvid.collectionName;
} else if (newvid.franchiseName.length > 0) {
name1 = newvid.franchiseName;
} else {
name1 = '';
}
if (newvid.franchiseName.length > 0) {teaserHtml = teaserHtml.concat(newvid.franchiseName);}
if (newvid.seasonNumber.length > 0) {teaserHtml = teaserHtml.concat('; Season ' + newvid.seasonNumber + ', ');}
if (newvid.episodeNumber.length > 0) {teaserHtml = teaserHtml.concat(' Episode ' + newvid.episodeNumber + '<br>');}
if (newvid.airDate.length > 0) {teaserHtml = teaserHtml.concat('Air Date ' + newvid.airDate + ', ');}
if (newvid.duration.length > 0) {teaserHtml = teaserHtml.concat('Length ' + newvid.duration);}
if (newvid.expiration.length > 0) {teaserHtml = teaserHtml.concat('Available Until ' + newvid.expiration);}
// $("#getAccess").css("display","none");
//disableEmbed();
teaserHtml = teaserHtml.concat('<br><a href="' + Dramavision.PageUrl + '?oid=' + newvid.videoId + '" title="add to favorites" class="teaserAdd"><img id="imageAddToPlaylist" src="http://i.cdn.turner.com/v5cache/TBS/cvp/images/addtoplaylist.png" vspace="5" hspace="0" border="0"></a>');
teaserHtml = teaserHtml.concat('</div>');
teaserHtml = teaserHtml.concat('<div id="textToggle2" style="display:none;">');
teaserHtml = teaserHtml.concat(ellipsis(newvid.blurb,100));
//disableEmbed();
teaserHtml = teaserHtml.concat('<br><a href="' + Dramavision.PageUrl + '?oid=' + newvid.videoId + '" title="add to favorites" class="teaserAdd"><img id="imageAddToPlaylist2" src="http://i.cdn.turner.com/v5cache/TBS/cvp/images/addtoplaylist2.png" vspace="5" hspace="0" border="0"></a>');
teaserHtml = teaserHtml.concat('</div>');
teaserHtml = teaserHtml.concat('</div><br clear="all"></div>');
videoCount++;
});
teaserHtml = teaserHtml.concat('</div>');
$('#fulleps').empty();
document.getElementById('bodytitle').style.display = "block";
$('#fulleps').append(teaserHtml);
$(".paginatePlease").hover(function(){
$(this).addClass("paginatePleaseHover");
$(this).children('#rightText').children('#textToggle1').css("display","none");
$(this).children('#rightText').children('#textToggle2').css("display","block");
//$(this).children('#rightText').children('#textToggle').html(altText);
}, function(){
$(this).removeClass("paginatePleaseHover");
$(this).children('#rightText').children('#textToggle1').css("display","block");
$(this).children('#rightText').children('#textToggle2').css("display","none");
//$(this).children('#rightText').children('#textToggle').html();
});
// keep up with the order the video objects are stored in the array; used for playing through a list
currentTeaserMap.orderArray = orderArray;
TeaserArea.init();
if (deepLinkedCategory !== "" && currentVideoId === "" && waitingVideo === "") {
// if we just loaded a deeplinked category, play the first video if there isn't a deeplinked video
deepLinkedCategory = "";
$('.headersection').html(name1);
$('.headertitle').html('');
Dramavision.playVideo(currentTeaserMap.orderArray[0], currentTeaserMap);
}
}
var newscripts=new virtualpaginate({
piececlass: "paginatePlease",
piececontainer: 'div',
pieces_per_page: 6,
defaultpage: 0,
wraparound: false,
persist: false
})
newscripts.buildpagination(["scriptspaginate"])
},
resize : function() {
/*
var sectionDiff = $("#fulleps").height() - 300;
var teaserHeight = 248;
if (sectionDiff > 0) {
var teaserHeight = 248 + sectionDiff;
}
$("#fulleps").css("height", teaserHeight + "px");
*/
$("#teaserArea").css("height", $("#fulleps").height());
},
error : function() {
// handle error retrieving videos or an empty video list
$('#fulleps').empty();
$('.headersection').html('search');
$('.headertitle').html('');
$('#rightCrumbTitle').html('');
$('#rightCrumbSection').html('');
$('#rightCrumbShow').html('');
$('#fulleps').html('<div id="scriptspaginate" ></div><br><br><br><br/> &nbsp; &nbsp; There are no videos for your selection.');
},
highlightPlaying : function() {
// highlight the currently playing video
$('#fulleps td').removeClass("teaserActive");
$('.paginatePlease').removeClass("paginatePleaseActive");
$('.teaser_' + currentVideoId).addClass("paginatePleaseActive");
}
}
// controller for main horizontal nav
var MainNav = {
init : function() {
// highlight the selected main nav item now
MainNav.highlightSelected();
// set the rollover effect for each nav item
$(".dramavisionNavItem").hover(function(){
$(this).addClass("dramavisionNavItemHover");
}, function() {
if (selectedCollection != $(this).attr('name')) {
$(this).removeClass("dramavisionNavItemHover");
}
});
Breadcrumbs.dramavisionNavItem();
Breadcrumbs.breadcrumbHome();
Breadcrumbs.rightCrumbSection();
},
highlightSelected : function() {
// highlight the selected nav item, and remove the highlight from the rest
$(".dramavisionNavItem").each(function() {
if (selectedCollection != $(this).attr('name')) {
$(this).removeClass("dramavisionNavItemHover");
} else {
$(this).addClass("dramavisionNavItemHover");
}
});
},
removeHighlight : function() {
selectedCollection = '';
MainNav.highlightSelected();
},
findSection : function(categoryId, myxml) {
// traverse through the xml file to find the parent section of a category,
// and decide if this category has videos or not; if not, find a child who does
var newSection = "";
var foundSection = "";
$(myxml).find('collection').each(function() {
newSection = $(this).children('name').text();
if ($(this).attr('id') == categoryId) {
foundSection = newSection;
if ($(this).children('subcollection').length > 0) {
var subcat = $(this).children('subcollection');
if ($(subcat).children('subcollection').length > 0) {
var subsubcat = $(this).children('subcollection');
if ($(subsubcat).children('subcollection').length > 0) {
deepLinkedCategory = $(subsubcat).children('subcollection').attr('id');
} else {
deepLinkedCategory = $(subcat).children('subcollection').attr('id');
}
} else {
deepLinkedCategory = $(this).children('subcollection').attr('id');
}
}
return;
} else {
if ($(this).children('subcollection').length > 0) {
$(this).children('subcollection').each(function() {
if ($(this).attr('id') == categoryId) {
foundSection = newSection;
if ($(this).children('subcollection').length > 0) {
var subcat = $(this).children('subcollection');
if ($(subcat).children('subcollection').length > 0) {
deepLinkedCategory = $(subcat).children('subcollection').attr('id');
} else {
deepLinkedCategory = $(this).children('subcollection').attr('id');
}
}
return;
} else {
if ($(this).children('subcollection').length > 0) {
$(this).children('subcollection').each(function() {
if ($(this).attr('id') == categoryId) {
foundSection = newSection;
if ($(this).children('subcollection').length > 0) {
deepLinkedCategory = $(this).children('subcollection').attr('id');
}
return;
} else {
if ($(this).children('subcollection').length > 0) {
$(this).children('subcollection').each(function() {
if ($(this).attr('id') == categoryId) {
foundSection = newSection;
return;
}
});
}
}
});
}
}
});
}
}
});
return foundSection;
}
}
// controller for the section navigation
var SectionNav = {
init : function() {
$('.sectionNavCell')
.livequery(function(){
$(this)
.hover(function() {
$(this).addClass('sectionNavCellHover');
}, function() {
$(this).removeClass('sectionNavCellHover');
});
});
// activate the div clicks
$(".sectionNavCell").livequery("click", function(e){
//$(".sectionNavCell").click(function(e) {
SectionNav.toggle(this);
if ($(this).next(".sectionNavSubGroup").length == 0) {
// get the collection id from the div name attribute
TeaserArea.loadVideos($(this).attr('id'));
collectionIdHolder = $(this).attr('id');
}
$('#rightCrumbTitle').html('');
$('#rightCrumbShow').data("sectionId",$(this).attr('id'));
$('#rightCrumbShow').html('<span style="text-transform: lowercase;">&nbsp; > ' + ellipsis($(this).children(0).text(),17) + '</span>');
$('.headersection').html($(this).children(0).text());
$('.headertitle').html('');
e.preventDefault();
return false;
});
$('.sectionNavCellActive')
.livequery(function(){
$(this)
.click(function() {
SectionNav.toggle(this);
$('.headertitle').html($(this).children(0).text());
e.preventDefault();
return false;
});
});
/*
$(".sectionNavCellActive").click(function(e) {
SectionNav.toggle(this);
$('.headertitle').html($(this).children(0).text());
e.preventDefault();
return false;
}); */
$(".sectionNavSubCell").livequery("click", function(e){
SectionNav.toggle(this);
$('#rightCrumbTitle').html('<span style="text-transform: lowercase;">&nbsp; > ' + ellipsis($(this).children(0).text(),18) + '</span>');
$('.headertitle').html(' - ' + $(this).children(0).text());
if ($(this).next(".sectionNavSubGroup").length == 0) {
// get the collection id from the div name attribute
TeaserArea.loadVideos($(this).attr('id'));
collectionIdHolder = $(this).attr('id');
}
e.preventDefault();
return false;
});
$('.sectionNavSubCell')
.livequery(function(){
$(this)
.hover(function() {
$(this).addClass('sectionNavSubCellHover');
}, function() {
$(this).removeClass('sectionNavSubCellHover');
});
});
$(".sectionNavSubSubCell").click(function(e) {
SectionNav.resetSubSubNavCells();
$(this).removeClass("sectionNavSubSubCell").addClass("sectionNavSubSubCellActive");
// get the collection id from the div name attribute
TeaserArea.loadVideos($(this).attr('id'));
e.preventDefault();
return false;
});
// resize the teaser area to match the height of the section nav
TeaserArea.resize();
},
toggle : function(div) {
// open or close the divs
if ($(div).hasClass("sectionNavCell")) {
SectionNav.resetNavCells();
$(div).next(".sectionNavSubGroup").show("slow", TeaserArea.resize);
$(div).removeClass("sectionNavCell").addClass("sectionNavCellActive");
} else if ($(div).hasClass("sectionNavSubCell")) {
SectionNav.resetSubNavCells();
$(div).next(".sectionNavSubGroup").show("slow", TeaserArea.resize);
$(div).removeClass("sectionNavSubCell").addClass("sectionNavSubCellActive");
} else if ($(div).hasClass("sectionNavCellActive")) {
$(div).next(".sectionNavSubGroup").hide("slow");
$(div).removeClass("sectionNavCellActive").addClass("sectionNavCell");
}
},
resetNavCells : function() {
// close all the divs
$(".sectionNavCellActive").each(function() {
$(this).next(".sectionNavSubGroup").hide("slow", TeaserArea.resize);
$(this).removeClass("sectionNavCellActive").addClass("sectionNavCell");
});
SectionNav.resetSubNavCells();
},
resetSubNavCells : function() {
// close all the subnav divs
$(".sectionNavSubCellActive").each(function() {
$(this).next(".sectionNavSubGroup").hide("slow", TeaserArea.resize);
$(this).removeClass("sectionNavSubCellActive").addClass("sectionNavSubCell");
});
SectionNav.resetSubSubNavCells();
},
resetSubSubNavCells : function() {
// close all the subnav divs
$(".sectionNavSubSubCellActive").each(function() {
$(this).removeClass("sectionNavSubSubCellActive").addClass("sectionNavSubSubCell");
});
},
load : function(section) {
// load the selected collection
$("#fulleps").html("<br><br><br><br> &nbsp; &nbsp; &nbsp; loading...");
if (navXml === "") {
// if nav is still loading, store the section
waitingSection = section;
// should only happen when a user clicks so we can remove the deep linked category
deepLinkedCategory = "";
} else {
// traverse xml to find section belonging to deepLinkedCategory; if none remove deeplinked status
if (deepLinkedCategory !== "") {
var foundSelectedSection = MainNav.findSection(deepLinkedCategory, navXml);
// once we find the section set it as selectedSection and run main nav highlight; also set section
if (foundSelectedSection !== "") {
selectedCollection = foundSelectedSection.toUpperCase();
section = foundSelectedSection;
MainNav.highlightSelected();
} else {
// if we don't find it set deepLinkedCategory = "";
deepLinkedCategory = "";
// didn't find the deeplinked category so play the default video from today's top
TodaysTop.playFirstVideo();
}
}
// find the collection in the xml create the nav display
var firstcollectionid = "";
currentSectionMap = new Object();
$(navXml).find('collection').each(function() {
var mycollection = $(this).children('name').text();
if (mycollection.toUpperCase() == section.toUpperCase()) {
var mycollectionid = $(this).attr('id');
firstcollectionid = mycollectionid;
$("#fulleps").empty();
if ($(this).children('subcollection').length < 1) {
var newsection = new Object();
newsection.name = $(this).children('name').text();
newsection.airing = $(this).children('airing').text();
currentSectionMap[$(this).attr('id')] = newsection;
TeaserArea.loadVideos(mycollectionid);
} else {
var navhtml = '<!--div id="sectionNavTitle">' + mycollection + '</div--><div id="sectionNav" class="scroll">';
var numcollections = 0;
document.getElementById('bodytitle').style.display = "none";
$("#rightCrumbSection").data("name",mycollection);
$("#rightCrumbSection").html('<span style="text-transform: lowercase;"> > ' + mycollection + '</span>');
$(this).children('subcollection').each(function() {
if (numcollections === 0) {
firstcollectionid = $(this).attr('id');
}
var newsection = new Object();
newsection.name = $(this).children('name').text();
newsection.airing = $(this).children('airing').text();
currentSectionMap[$(this).attr('id')] = newsection;
var mysubcollectionname = $(this).children('name').text();
var thiscollectionname = $(this).children('name').text();
navhtml = navhtml.concat('<div class="sectionNavCell" id="' + $(this).attr('id') + '"><b>' + $(this).children('name').text() + '</b></div>');
if ($(this).children('subcollection').length > 0) {
var subgroup = '<div id="sub_' + $(this).attr('id') + '" class="sectionNavSubGroup">';
var numsubcollections = 0;
$(this).children('subcollection').each(function() {
if (numcollections === 0 && numsubcollections === 0) {
firstcollectionid = $(this).attr('id');
}
subgroup = subgroup.concat('<div class="sectionNavSubCell" id="' + $(this).attr('id') + '"><img src="http://i.cdn.turner.com/v5cache/TBS/cvp/images/bullet.gif" border="0" align="left"><b>' + $(this).children('name').text() + '</b></div>');
var newsection = new Object();
newsection.name = mysubcollectionname + ": " + $(this).children('name').text();
newsection.airing = $(this).children('airing').text();
currentSectionMap[$(this).attr('id')] = newsection;
var mysubsubcollectionname = $(this).children('name').text();
if ($(this).children('subcollection').length > 0) {
var subsubgroup = '<div class="sectionNavSubGroup">';
var numsubsubcollections = 0;
$(this).children('subcollection').each(function() {
if (numcollections === 0 && numsubcollections === 0 && numsubsubcollections === 0) {
firstcollectionid = $(this).attr('id');
}
subsubgroup = subsubgroup.concat('<div class="sectionNavSubSubCell" id="' + $(this).attr('id') + '"><b>' + $(this).children('name').text() + '</b></div>');
var newsection = new Object();
newsection.name = mysubcollectionname + ": " + mysubsubcollectionname + ": " + $(this).children('name').text();
newsection.airing = $(this).children('airing').text();
currentSectionMap[$(this).attr('id')] = newsection;
numsubsubcollections++;
});
subsubgroup = subsubgroup.concat('</div>');
subgroup = subgroup.concat(subsubgroup);
}
numsubcollections++;
});
subgroup = subgroup.concat('</div>');
navhtml = navhtml.concat(subgroup);
}
numcollections++;
});
navhtml = navhtml.concat('</div>');
$("#fulleps").append(navhtml);
}
}
});
//SectionNav.init();
// if currentTeaserMap is empty, load the deeplinked category or the first collection with videos
if (Util.isEmptyObject(currentTeaserMap)) {
if (deepLinkedCategory !== "") {
// load the videos for the deeplinked category
TeaserArea.loadVideos(deepLinkedCategory);
// open up the category in the left nav
var div = $("#" + deepLinkedCategory);
if ($(div).hasClass("sectionNavCell")) {
$(div).removeClass("sectionNavCell").addClass("sectionNavCellActive");
} else if ($(div).hasClass("sectionNavSubCell")) {
$(div).parent(".sectionNavSubGroup").show("slow", TeaserArea.resize);
$(div).parent(".sectionNavSubGroup").prev(".sectionNavCell").removeClass("sectionNavCell").addClass("sectionNavCellActive");
$(div).removeClass("sectionNavSubCell").addClass("sectionNavSubCellActive");
} else if ($(div).hasClass("sectionNavSubSubCell")) {
$(div).parent(".sectionNavSubGroup").prev(".sectionNavSubCell").parent(".sectionNavSubGroup").show("slow", TeaserArea.resize);
$(div).parent(".sectionNavSubGroup").prev(".sectionNavSubCell").parent(".sectionNavSubGroup").prev(".sectionNavCell").removeClass("sectionNavCell").addClass("sectionNavCellActive");
$(div).parent(".sectionNavSubGroup").show("slow", TeaserArea.resize);
$(div).parent(".sectionNavSubGroup").prev(".sectionNavSubCell").removeClass("sectionNavSubCell").addClass("sectionNavSubCellActive");
$(div).removeClass("sectionNavSubSubCell").addClass("sectionNavSubSubCellActive");
}
} else {
TeaserArea.loadVideos(firstcollectionid);
}
}
}
}
}
// controller for playlist area
var PlaylistArea = {
init : function() {
// activate playlist tabs
$("#dramavisionTodaysTopBtn").bind("click", function(e) {
PlaylistArea.togglePlaylist('todaysTop');
e.preventDefault();
});
$("#rramavisionFavoritesBtn").bind("click", function(e) {
PlaylistArea.togglePlaylist('favorites');
e.preventDefault();
});
},
togglePlaylist : function(playlistType) {
// toggle the displayed playlist depending on the chosen type
if (playlistType === 'favorites') {
Dramavision.Track({prop16:"Dramavision:My Favorites", eVar16:"Dramavision:My Favorites"});
$("#dramavisionFavorites").show();
$("#dramavisionFavoritesBtn").removeClass('dramavisionPlayListTab').addClass('dramavisionPlayListTabActive');
$("#dramavisionTodaysTop").hide();
$("#dramavisionTodaysTopBtn").removeClass('dramavisionPlayListTabActive').addClass('dramavisionPlayListTab');
} else {
Dramavision.Track({prop16:"Dramavision:Todays Top", eVar16:"Dramavision:Todays Top"});
$("#dramavisionTodaysTop").show();
$("#dramavisionTodaysTopBtn").removeClass('dramavisionPlayListTab').addClass('dramavisionPlayListTabActive');
$("#dramavisionFavorites").hide();
$("#dramavisionFavoritesBtn").removeClass('dramavisionPlayListTabActive').addClass('dramavisionPlayListTab');
}
}
}
// controller for Today's Top Videos
var TodaysTop = {
init : function() {
// activate teaser play links
$("#dramavisionTodaysTop .teaserPlay").bind("click", function(e) {
var videoId = $(this).attr('href');
Dramavision.playVideo(videoId.split("?oid=")[1], currentTodaysTopMap);
e.preventDefault();
return false;
});
},
loadVideos : function() {
// get the xml for today's top videos
$.ajax({
type: "GET",
url : Dramavision.CollectionUrl + "?oid=" + Dramavision.TodaysTopId,
//url : Dramavision.CollectionUrl + "&limit=" + Dramavision.MaxVideos + "&id=" + Dramavision.TodaysTopId,
cache : true,
dataType: "xml",
success : function(data) {
TodaysTop.populate(data);
}
});
},
loadVideosCookie : function(insideCookie) {
//alert('loadVideosCookie= ' + insideCookie);
// get the xml for today's top videos
$.ajax({
type: "GET",
url : Dramavision.CollectionUrl + "&limit=" + Dramavision.MaxVideos + insideCookie,
cache : true,
dataType: "xml",
success : function(data) {
TodaysTop.populate(data);
}
});
},
populate : function(data) {
// parse the xml and display the today's top video links
currentTodaysTopMap = new Object();
var orderArray = new Array();
var videoCount = 0;
var teaserHtml = '';
$(data).find('episode').each(function() {
var newvid = Util.storeVideoNode($(this));
orderArray.push(newvid.videoId);
currentTodaysTopMap[newvid.videoId] = newvid;
if (videoCount % 2 === 0) {
teaserHtml = teaserHtml.concat('<div class="dramavisionPlayListItem" id="' + newvid.videoId + '">');
} else {
teaserHtml = teaserHtml.concat('<div class="dramavisionPlayListItemAlt" id="' + newvid.videoId + '">');
}
teaserHtml = teaserHtml.concat('<a href="' + Dramavision.PageUrl + '?oid=' + newvid.videoId + '" class="teaserPlay" title="play video">');
teaserHtml = teaserHtml.concat(newvid.heading + '</a></div>');
videoCount++;
});
$('#dramavisionTodaysTop').empty();
$('#dramavisionTodaysTop').append(teaserHtml);
// keep up with the order the video objects are stored in the array; used for playing through a list
currentTodaysTopMap.orderArray = orderArray;
TodaysTop.playFirstVideo();
TodaysTop.init();
},
playFirstVideo : function() {
var firstVideo = $('#dramavisionTodaysTop').children('.dramavisionPlayListItem').children('a').attr('href');
if (currentVideoId === "" && waitingVideo === "" && deepLinkedCategory === "" && firstVideo != undefined) {
Dramavision.playVideo(firstVideo.split("?oid=")[1], currentTodaysTopMap);
}
}
}
//you may also like
// controller for Today's Top Videos
var AlsoLike = {
init : function() {
// activate teaser play links
$("#youmayalsolikebody .teaserPlay").bind("click", function(e) {
var videoId = $(this).attr('href');
deepLinkedCategory = collectionId;
currentVideoId = "";
waitingVideo = "";
var collectionId = videoId.split("?cid=")[1];
TeaserArea.loadVideos(collectionId);
$("#rightCrumbTitle").html('');
$("#rightCrumbShow").html('');
$("#rightCrumbSection").html('');
$('.sectionheader').html(currentAlsoLikeMap[collectionId]);
$('#myplaylist').css("display","none");
$('#fulleps').css("display","block");
$('.dramavisionNavItem').removeClass('dramavisionNavItemHover');
e.preventDefault();
return false;
});
},
loadVideos : function(franchiseId,categoryId) {
// get the xml for you may also like
if (categoryId == '25') {
var returnType = 161;
} else {
var returnType = categoryId;
}
$.ajax({
type: "GET",
url : Dramavision.AlsoLikeUrl + "?oid=|" + franchiseId + "&collectionCategoryId=" + returnType,
cache : true,
dataType: "xml",
success : function(data) {
AlsoLike.populate(data);
}
});
},
populate : function(data) {
var html = "";
if ($(data).find('franchise').length > 0) {
currentAlsoLikeMap = new Object();
var videoCount = 0;
//grabs all of the franchise and loops through them
$(data).find('franchise').each(function(){
//var newvid = Util.storeVideoNode($(this).find('video')); // find the first video in the franchise
var collection = $(this).find('collection');
var collectionName = "";
if (collection.attr('id') != undefined) {
//gets the collection name
html = html.concat('<div id="item">');
html = html.concat('<a href="' + Dramavision.PageUrl + '?cid=' + collection.attr('id') + '" class="teaserPlay" title="play video">');
$(collection).each(function() {
html = html.concat('<img src="' + $(this).children('image').text() + '" border="0" align="left" valign="middle">');
currentAlsoLikeMap[collection.attr('id')] = $(this).children('name').text();
collectionName = $(this).children('name').text()
return false;
})
html = html.concat('</a>');
html = html.concat('<div style="padding: 3px 10px 0px 0px;"><a style="font-style: bold; color: #000" href="' + Dramavision.PageUrl + '?cid=' + collection.attr('id') + '" class="teaserPlay" title="play video">' + ellipsis($(this).attr('franchise_name') + ': ' + collectionName,80) + '</a><br>');
html = html.concat(ellipsis($(this).find('description').text(),62));
html = html.concat('</div></div>');
} else {videoCount--;}
videoCount++;
if (videoCount > 2) {
return false;
}
});
$('#youmayalsolikebody').html(html);
} else {
AlsoLike.loadVideos('362390','1');
}
AlsoLike.init();
}
}
// controller for My Favorites
var Favorites = {
inRearrange : false,
init : function() {
// load my favorites
var orderArray = new Array();
currentFavoritesMap.orderArray = orderArray;
var storedFavorites = CookieJar.getCookie(Dramavision.FavoritesCookie);
if (storedFavorites === null || storedFavorites === "") {
$('#myplaylist').empty();
$('#myplaylist').html('<div style="padding:65px 10px 0px 10px;">Your playlist is empty.<br><br>Click "add to playlist" next to any video thumbnail to save that video to your personal playlist.</div>');
} else {
// get the xml for my favorites
$.ajax({
type: "GET",
url : Dramavision.FavoritesUrl + "?id=" + storedFavorites,
cache : true,
dataType: "xml",
success : function(data) {
Favorites.populate(data);
}
});
}
// activate the links
$("#dramavisionFavorites .favoritesClearList").bind("click", function(e) {
var conf = confirm("Are you sure you want to clear your favorites?");
if (conf) {
Favorites.clear();
}
e.preventDefault();
return false;
});
$("#dramavisionFavorites .favoritesRearrangeList").bind("click", function(e) {
if (currentFavoritesMap.orderArray.length > 0) {
Favorites.rearrange();
} else {
alert("You do not have any favorites to rearrange.");
}
e.preventDefault();
return false;
});
$("#dramavisionFavorites .favoritesSaveArrangement").bind("click", function(e) {
Favorites.save();
e.preventDefault();
return false;
});
$("#dramavisionFavorites .favoritesShareList").bind("click", function(e) {
if (currentFavoritesMap.orderArray.length > 0) {
Favorites.share();
} else {
alert("You do not have any favorites to share.");
}
e.preventDefault();
return false;
});
$('#dramavisionFavoritesShare #shareFavSendBtn').bind("click", function(e) {
Favorites.send();
e.preventDefault();
return false;
});
Favorites.setCancelAction();
},
populate : function(data) {
// parse the xml and display the favorites
currentFavoritesMap = new Object();
var orderArray = new Array();
var videoCount = 0;
var teaserHtml = '';
$(data).find('episode').each(function() {
var newvid = Util.storeVideoNode($(this));
orderArray.push(newvid.videoId);
currentFavoritesMap[newvid.videoId] = newvid;
if (videoCount % 2 === 0) {
teaserHtml = teaserHtml.concat('<div id="favorite_' + newvid.videoId + '" class="dramavisionPlayListItem">');
} else {
teaserHtml = teaserHtml.concat('<div id="favorite_' + newvid.videoId + '" class="dramavisionPlayListItemAlt">');
}
teaserHtml = teaserHtml.concat('<div class="dramavisionFavoritesText"><a href="' + Dramavision.PageUrl + '?oid=' + newvid.videoId + '" class="teaserPlay" title="play video">');
teaserHtml = teaserHtml.concat(newvid.heading + '</a></div>');
teaserHtml = teaserHtml.concat('<div class="dramavisionFavoritesRemove" id="' + newvid.videoId + '" title="remove from favorites">[-]</div><br clear="all"/></div>');
videoCount++;
});
$('#myplaylist').empty();
$('#myplaylist').append(teaserHtml);
// keep up with the order the video objects are stored in the array; used for playing through a list
currentFavoritesMap.orderArray = orderArray;
Favorites.activate();
},
setNumber : function() {
// set number of favorites
var tabTextArray = $("#listtabsPL").html().split("[");
$("#listtabsPL").empty();
$("#listtabsPL").html(tabTextArray[0] + "[" + currentFavoritesMap.orderArray.length + "]");
if (currentFavoritesMap.orderArray.length === 0) {
$('#myplaylist').empty();
$('#myplaylist').html('<div style="padding:5px 10px 0px 10px;">Your playlist is empty.<br><br>Click "add to playlist" next to any video thumbnail to save that video to your personal playlist.</div>');
}
},
updateCookie : function() {
var favoritesList = "";
for (var i = 0; i < currentFavoritesMap.orderArray.length; i++) {
var videoId = currentFavoritesMap.orderArray[i];
if (favoritesList === "") {
favoritesList = favoritesList.concat(videoId);
} else {
favoritesList = favoritesList.concat("|" + videoId);
}
}
CookieJar.setCookie(Dramavision.FavoritesCookie, favoritesList, 365);
},
activate : function() {
// activate teaser play links (unbind previous first so we don't compound them)
$("#myplaylist .teaserPlay").unbind("click");
$("#myplaylist .teaserPlay").bind("click", function(e) {
var videoId = $(this).attr('href');
Dramavision.playVideo(videoId.split("?oid=")[1], currentFavoritesMap);
e.preventDefault();
return false;
});
// activate remove favorite links (unbind previous first so we don't compound them)
$("#myplaylist .dramavisionFavoritesRemove").unbind("click");
$("#myplaylist .dramavisionFavoritesRemove").bind("click", function(e) {
if (confirm("Are you sure you want to remove this item from your favorites?")) {
Favorites.remove($(this).attr("id"));
}
e.preventDefault();
return false;
});
Favorites.setNumber();
// if we're in rearrange mode, refresh the sortable list to pick up new items
if (Favorites.inRearrange) {
$("#myplaylist").sortable("refresh");
}
},
add : function(video) {
if (video != undefined && currentFavoritesMap.orderArray.length < Dramavision.maxFavorites) {
// check for existence
if (currentFavoritesMap[video.videoId]) {
alert("This video is already stored in your favorites.");
} else {
// add the video to the favorites cookie and add the div
if (currentFavoritesMap.orderArray.length === 0) {
$("#myplaylist").empty();
}
currentFavoritesMap.orderArray.push(video.videoId);
currentFavoritesMap[video.videoId] = video;
var favoriteHtml = "";
if (Favorites.inRearrange) {
favoriteHtml = favoriteHtml.concat('<div id="favorite_' + video.videoId + '" class="dramavisionPlayListItemMoveable">');
} else if (currentFavoritesMap.orderArray.length % 2 === 0) {
favoriteHtml = favoriteHtml.concat('<div id="favorite_' + video.videoId + '" class="dramavisionPlayListItemAlt">');
} else {
favoriteHtml = favoriteHtml.concat('<div id="favorite_' + video.videoId + '" class="dramavisionPlayListItem">');
}
favoriteHtml = favoriteHtml.concat('<div class="dramavisionFavoritesText"><a href="' + Dramavision.PageUrl + '?oid=' + video.videoId + '" class="teaserPlay" title="play video">');
favoriteHtml = favoriteHtml.concat(video.heading + '</a></div>');
favoriteHtml = favoriteHtml.concat('<div class="dramavisionFavoritesRemove" id="' + video.videoId + '" title="remove from favorites">[-]</div><br clear="all"/></div>');
$('#myplaylist').append(favoriteHtml);
Favorites.activate();
Favorites.updateCookie();
// switch to the playlist tab
PlaylistArea.togglePlaylist('favorites');
var pageName = video.heading + ":(" + video.videoId + ")";
Dramavision.Track({eVar2:pageName, eVar3:pageName, events:"event8"});
}
} else {
alert("Sorry, you have reached your max of " + Dramavision.maxFavorites + " favorites.");
}
},
remove : function(videoId) {
var pageName = currentFavoritesMap[videoId].heading + ":(" + videoId + ")";
Dramavision.Track({eVar2:pageName, eVar3:pageName, events:"event9"});
$("#favorite_" + videoId).remove();
delete currentFavoritesMap[videoId];
// update the div colors and cookie
var videoCount = 0;
currentFavoritesMap.orderArray = new Array();
$("#myplaylist .teaserPlay").each(function() {
var videoId = $(this).attr('href');
currentFavoritesMap.orderArray.push(videoId.split("?oid=")[1]);
var parent = $(this).parent("div").parent("div");
$(parent).removeClass('dramavisionPlayListItem');
$(parent).removeClass('dramavisionPlayListItemAlt');
if (videoCount % 2 === 0) {
$(parent).addClass('dramavisionPlayListItem');
} else {
$(parent).addClass('dramavisionPlayListItemAlt');
}
videoCount++;
});
Favorites.setNumber();
Favorites.updateCookie();
},
clear : function() {
// clear the favorites cookie and clear the div
$('#myplaylist').show();
$('#dramavisionFavoritesShare').hide();
$('#dramavisionFavoritesShareConfirmation').hide();
currentFavoritesMap = new Object();
var orderArray = new Array();
currentFavoritesMap.orderArray = orderArray;
Favorites.activate();
Favorites.updateCookie();
Dramavision.Track({prop16:"Dramavision:Clear Playlist", eVar16:"Dramavision:Clear Playlist"});
},
rearrange : function() {
// set the list in rearrange mode (change the style and activate jquery sorting)
Favorites.inRearrange = true;
$('#myplaylist').show();
$('#dramavisionFavoritesShare').hide();
$('#dramavisionFriendsList').hide();
$('#dramavisionFavorites #dramavisionFriendsNav').hide();
$("#dramavisionFavorites #dramavisionFavoritesNav").hide();
$("#dramavisionFavorites #dramavisionArrangeFavoritesNav").show();
$('#dramavisionFavoritesShareConfirmation').hide();
$('#myplaylist .dramavisionPlayListItem').removeClass('dramavisionPlayListItem').addClass('dramavisionPlayListItemMoveable');
$('#myplaylist .dramavisionPlayListItemAlt').removeClass('dramavisionPlayListItemAlt').addClass('dramavisionPlayListItemMoveable');
// activate sorting
$("#myplaylist").sortable({});
},
save : function() {
// save the new arrangement (update the cookie, kill the jquery sorting, and update the divs)
Favorites.inRearrange = false;
$("#dramavisionFavorites #dramavisionFavoritesNav").show();
$("#dramavisionFavorites #dramavisionArrangeFavoritesNav").hide();
// kill the sorting
$("#myplaylist").sortable("destroy");
// update the video order and the div colors
var videoCount = 0;
currentFavoritesMap.orderArray = new Array();
$('#myplaylist .dramavisionPlayListItemMoveable').each(function() {
var videoId = $(this).children("div").children("a").attr('href');
currentFavoritesMap.orderArray.push(videoId.split("?oid=")[1]);
$(this).removeClass('dramavisionPlayListItemMoveable');
if (videoCount % 2 === 0) {
$(this).addClass('dramavisionPlayListItem');
} else {
$(this).addClass('dramavisionPlayListItemAlt');
}
videoCount++;
});
Favorites.updateCookie();
},
share : function() {
// show the share favorites form
$('#myplaylist').hide();
$('#dramavisionFavoritesShare').show();
$('#dramavisionFavoritesShareConfirmation').hide();
$('#dramavisionFriendsList').hide();
/* Clear "friend" fields, but leave "your" fields populated */
for(var i = 2, l = $("#dramavisionFavoritesShare input[@type='text']").length; i < l; i++) {
$("#dramavisionFavoritesShare input[@type='text']")[i].value = "";
}
},
send : function() {
// send the share favorites email
if (Validate.validateEmailForm(document.shareFavs)) {
var inputs = [];
$(':input', '#shareFavs').each(function() {
inputs.push(this.name + '=' + escape(this.value));
});
Dramavision.Track({prop16:"Dramavision:Share Playlist", eVar16:"Dramavision:Share Playlist"});
$.ajax({
url : Dramavision.ShareFavsUrl,
data: inputs.join('&'),
dataType : 'html',
cache : false,
error : function(req) {
var msg = (req.readyState !== 4) ? "incomplete request" : req.statusText;
$('#dramavisionFavoritesShareConfirmation').empty();
$("#dramavisionFavoritesShareConfirmation").html('<h1>Share your favorites</h1><br><br>There was an error sending your request.<br><br>Please try again later.<br><br><div id="cancelFavSendBtn">Close</div>');
$("#dramavisionFavoritesShare").hide();
$("#dramavisionFavoritesShareConfirmation").show();
Favorites.setCancelAction();
},
success : function(html){
$('#dramavisionFavoritesShareConfirmation').empty();
$("#dramavisionFavoritesShareConfirmation").html(html);
$("#dramavisionFavoritesShare").hide();
$("#dramavisionFavoritesShareConfirmation").show();
Favorites.setCancelAction();
}
});
}
},
setCancelAction : function() {
// set cancel/close action for share favorites form and confirmation
$('#cancelFavSendBtn').bind("click", function(e) {
$('#myplaylist').show();
$('#dramavisionFavoritesShare').hide();
$('#dramavisionFavoritesShareConfirmation').hide();
e.preventDefault();
return false;
});
}
}
var FriendsFavorites = {
init : function() {
$.ajax({
type: "GET",
url : Dramavision.SharedFavoritesUrl + "?eid=" + friendsFavoritesId,
cache : true,
dataType: "xml",
success : function(data) {
FriendsFavorites.populate(data);
}
});
$('#dramavisionFavorites .favoritesFriendsList').bind("click", function(e) {
FriendsFavorites.show();
e.preventDefault();
return false;
});
$('#dramavisionFriendsNav .return').bind("click", function(e) {
FriendsFavorites.hide();
e.preventDefault();
return false;
});
PlaylistArea.togglePlaylist('favorites');
FriendsFavorites.show();
},
activate : function() {
// activate teaser play links (unbind previous first so we don't compound them)
$("#dramavisionFriendsList .teaserPlay").unbind("click");
$("#dramavisionFriendsList .teaserPlay").bind("click", function(e) {
var videoId = $(this).attr('href');
Dramavision.playVideo(videoId.split("?oid=")[1], currentFriendsMap);
e.preventDefault();
return false;
});
// activate remove favorite links (unbind previous first so we don't compound them)
$("#dramavisionFriendsList .dramavisionFavoritesAdd").unbind("click");
$("#dramavisionFriendsList .dramavisionFavoritesAdd").bind("click", function(e) {
var videoId = $(this).attr("id");
Favorites.add(currentFriendsMap[videoId]);
e.preventDefault();
return false;
});
},
populate : function(data) {
// parse the xml and display the friend's favorites
currentFriendsMap = new Object();
var orderArray = new Array();
var videoCount = 0;
var teaserHtml = '';
$(data).find('episode').each(function() {
var newvid = Util.storeVideoNode($(this));
orderArray.push(newvid.videoId);
currentFriendsMap[newvid.videoId] = newvid;
if (videoCount % 2 === 0) {
teaserHtml = teaserHtml.concat('<div id="friends_' + newvid.videoId + '" class="dramavisionPlayListItem">');
} else {
teaserHtml = teaserHtml.concat('<div id="friends_' + newvid.videoId + '" class="dramavisionPlayListItemAlt">');
}
teaserHtml = teaserHtml.concat('<div class="dramavisionFavoritesText"><a href="' + Dramavision.PageUrl + '?oid=' + newvid.videoId + '" class="teaserPlay" title="play video">');
teaserHtml = teaserHtml.concat(newvid.heading + '</a></div>');
teaserHtml = teaserHtml.concat('<div class="dramavisionFavoritesAdd" id="' + newvid.videoId + '" title="add to my favorites">[+]</div><br clear="all"/></div>');
videoCount++;
});
$('#dramavisionFriendsList').empty();
$('#dramavisionFriendsList').append(teaserHtml);
// keep up with the order the video objects are stored in the array; used for playing through a list
currentFriendsMap.orderArray = orderArray;
FriendsFavorites.activate();
},
show : function() {
$('#dramavisionFavorites #dramavisionFriendsList').show();
$('#dramavisionFavorites #dramavisionFriendsNav').show();
$('#dramavisionFavorites #myplaylist').hide();
$('#dramavisionFavorites #dramavisionFavoritesNav').hide();
$('#dramavisionFavorites #dramavisionFavoritesShare').hide();
$('#dramavisionFavorites #dramavisionFavoritesShareConfirmation').hide();
},
hide : function() {
$('#dramavisionFavorites #dramavisionFriendsList').hide();
$('#dramavisionFavorites #dramavisionFriendsNav').hide();
$('#dramavisionFavorites #myplaylist').show();
$('#dramavisionFavorites #dramavisionFavoritesNav').show();
}
}
// Add trim test for user's search entry
function leftTrim(sString) {
while (sString.substring(0,1) == ' ') {
sString = sString.substring(1, sString.length);
}
return sString;
}
// controller for search
var Search = {
init : function() {
// set the action for the submit button
$("#searchForm").bind("submit", function(e) {
Search.submit();
$(".headersection").html('search');
$(".headertitle").html('');
$('#rightCrumbShow').html('');
$('#rightCrumbTitle').html('');
$('#rightCrumbSection').html(' > search');
$('#myplaylist').css("display","none");
$('#fulleps').css("display","block");
e.preventDefault();
}).bind("keypress", function(e) {
var key = e.charCode ? e.carChode : e.keyCode ? e.keyCode : 0;
if (key === 13) {
Search.submit();
e.preventDefault();
}
});
},
submit : function() {
// send and load the search request - add test for empty string and </ and ;
if (document.searchForm.query.value == 'Search TBS.com video'
|| leftTrim(document.searchForm.query.value).length == 0
|| document.searchForm.query.value.indexOf("</") >= 0
|| document.searchForm.query.value.indexOf(";") >= 0) {
alert('Please insert a search keyword');
} else {
$("#fulleps").empty();
$('#fulleps').html('<br><br><br><br> &nbsp; &nbsp; &nbsp; loading...');
$('#teaserAreaTitle').html('Search: ' + document.searchForm.query.value);
$('#teaserAreaSubTitle').empty();
MainNav.removeHighlight();
var inputs = [];
$(':input', '#searchForm').each(function() {
inputs.push(this.name + '=' + escape(this.value));
});
$.ajax({
type: "GET",
url : Dramavision.SearchUrl,
data: inputs.join('&'),
cache : true,
dataType: "xml",
error : function(req) {
TeaserArea.error();
},
success : function(data) {
var pageName = document.searchForm.query.value;
var omnitureObj = {prop14:pageName, prop15:"Dramavision", prop16:"Dramavision:Search", eVar14:pageName, eVar15:"Dramavision", eVar16:"Dramavision:Search"};
if ($(data).find('episodes').attr("totalItems") === "0") {
omnitureObj.prop13 = pageName;
}
Dramavision.Track(omnitureObj);
TeaserArea.populate(data);
}
});
}
}
}
// cookie functions
var CookieJar = {
getCookie : function(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1, c.length);
}
if (c.indexOf(nameEQ) == 0) {
return c.substring(nameEQ.length, c.length);
}
}
return null;
},
setCookie : function(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
} else {
var expires = "";
}
document.cookie = name + "=" + value + expires + "; path=/";
}
}
// basic utility functions
var Util = {
storeVideoNode : function(node) {
var newvid = new Object();
newvid.videoId = $(node).attr("id");
newvid.collectionId = $(node).attr("collectionId");
newvid.thumb = $(node).children("thumbnailUrl").text();
newvid.heading = $(node).children("title").text();
newvid.optimostCheck = $(node).children("heading").text();
newvid.blurb = $(node).children("shortBlurb").text();
newvid.duration = $(node).children("duration").text();
newvid.expiration = $(node).children("expiration").text();
newvid.airDate = $(node).children("lastAirDate").text();
newvid.description = $(node).children("description").text();
newvid.airing = $(node).children("airing").text();
newvid.embeddable = $(node).children("embeddable").text();
newvid.mavenExternalId = $(node).children("mavenExternalId").text();
newvid.franchiseName = $(node).children("franchiseName").text();
newvid.collectionName = $(node).children("collectionName").text();
newvid.seasonNumber = $(node).children("seasonNumber").text();
newvid.episodeNumber = $(node).children("episodeNumber").text();
newvid.airingInfo = $(node).children("dateCreated").text();
newvid.availableUntil = $(node).children("availableUntil").text();
newvid.playlistId = $(node).children("mavenPlaylistId").text();
//newvid.tveMode = $(node).children("segments").children("segment").attr("tveMode");
newvid.tveMode = $(node).children("tveMode").text();
//newvid.authType = $(node).children("authType").text();
newvid.franchiseLinkUrl = $(node).children("franchiseLinkUrl").text();
var segments = new Array();
$(node).find('segment').each(function() {
//alert("hello");
var segment = new Object();
segment.videoId = $(this).attr("id");
segment.thumb = $(this).children("thumbnailUrl").text();
segment.heading = $(this).children("name").text();
segment.blurb = $(this).children("shortBlurb").text();
segment.description = $(this).children("description").text();
segment.airing = $(this).children("airing").text();
segment.tveMode = $(this).children("tveMode").text();
segment.franchiseLinkUrl = $(node).children("franchiseLinkUrl").text();
segments.push(segment);
});
newvid.segments = segments;
return newvid;
},
isEmptyObject : function(obj) {
// check if an object is empty
for(var i in obj) {
return false;
}
return true;
},
copyToClipboard : function(textarea) {
// copy text from a textarea to the clipboard
$(textarea).css("background-color","#0A3256");
window.setTimeout(function(){
$(textarea).css("background-color","#FFF");
},60);
var txt = $(textarea)[0].value;
if (txt.createTextRange) {
range = txt.createTextRange();
if (range && (BodyLoaded == 1)) {
range.execCommand("Copy");
}
} else {
$('#clipboardProxy').html('<embed id=clipboardFlash" src="/flash/clipboardProxy.swf" FlashVars="clipboard=' + encodeURIComponent(txt) + '" width="0" height="0" type="application/x-shockwave-flash"></embed>');
}
}
}
// form validation functions
var Validate = {
isEmpty : function(fieldValue) {
if ((fieldValue.length == 0) || (fieldValue == null)) {
return true;
}
else {
return false;
}
},
isEmptyRadio : function(field) {
for (i = 0; i < field.length; i++) {
if (field[i].checked) {
return false;
}
}
return true;
},
isNumeric : function(fieldValue) {
var ValidChars = "0123456789.";
var IsNumber=true;
var Char;
for (i = 0; i < fieldValue.length && IsNumber == true; i++) {
Char = fieldValue.charAt(i);
if (ValidChars.indexOf(Char) == -1) {
IsNumber = false;
}
}
return IsNumber;
},
isEmail : function(fieldvalue) {
var i = 1;
var sLength = fieldvalue.length;
// look for @
while ((i < sLength) && (fieldvalue.charAt(i) != "@")) {
i++
}
if ((i >= sLength) || (fieldvalue.charAt(i) != "@")) {
return false;
} else {
i += 2;
}
// look for .
while ((i < sLength) && (fieldvalue.charAt(i) != ".")) {
i++
}
// there must be at least one character after the .
if ((i >= sLength - 1) || (fieldvalue.charAt(i) != ".")) {
return false;
} else {
return true;
}
},
validateEmailForm : function(form) {
var valid = true;
var msg = "Please correct the following information - \n\n";
if (Validate.isEmpty(form.fp_sender.value)) {
msg += "- Your name is required \n";
valid = false;
}
if (Validate.isEmpty(form.fp_sender_email.value)) {
msg += "- Your email is required \n";
valid = false;
} else if (!Validate.isEmail(form.fp_sender_email.value)) {
msg += "- Your email is not a valid email address \n";
valid = false;
}
if (Validate.isEmpty(form.fp_friend.value)) {
msg += "- Friend's name is required \n";
valid = false;
}
if (Validate.isEmpty(form.fp_friend_email.value)) {
msg += "- Friend's email is required \n";
valid = false;
} else if (!Validate.isEmail(form.fp_friend_email.value)) {
msg += "- Friend's email is not a valid email address \n";
valid = false;
}
if (!valid) {
alert(msg);
}
return valid;
}
}
