var debugSCET = true;
var isDimmed = false;
var isUserDimmed = false;
var isLiked = false;

jqN(document).ready(function() {	
	
		   
	jqN('#search-field').focus(function(){searchField();});	
	
	jqN('.dim-screen').live('click', function() {
		isUserDimmed = true;
		dimScreen();
	});
	
	jqN('#trans-overlay').live('click', function() {
		isUserDimmed = false;
	});
	
	jqN('.browse-nav a').click(function(){dumbTabs(this,'.browse-nav a','#more-videos .tab-content');});
	jqN('.share-list a').click(function(){dumbTabs(this,'.share-list a','#nbc-share-comments .tab-content');});
	dumbTabs(this,'.share-list a','#nbc-share-comments .tab-content');

	nbcu.poll.like.getUri({
		content: nbcu.content.object,
		likeStatsSelector: ".scet_usr_like_stats_message"
	});
	
	nbcu.util.common.loadClass("Nbcu.Sn.Comment");
	nbcu.sn.comment.setParam("version", 3);
	nbcu.sn.comment.setParam("maxRecordsPerPage", 3);
	nbcu.sn.comment.setParam("refContent", nbcu.content.object);
	nbcu.sn.comment.setParam("commentSelector", "#comment-content");
	nbcu.sn.comment.setParam("eventHandler", function(status) {
		setTimeout('getCommentsCount();', 1000);
	});
	nbcu.sn.comment.init();
	
/*  VERSION 2
	nbcu.sn.comment.setParam("contentType", nbcu.content.object.getParam("contentType"));
	nbcu.sn.comment.setParam("contentSSUniqueKey", nbcu.content.object.getParam("contentSSUniqueKey"));
	nbcu.sn.comment.setParam("maxRecordsPerPage", 3);
	nbcu.sn.comment.setParam("siteId", nbcu.content.object.getParam("siteId"));
	nbcu.sn.comment.setParam("assetTitle", nbcu.content.object.getParam("title"));
	nbcu.sn.comment.setParam("assetDescription", nbcu.content.object.getParam("description"));
	nbcu.sn.comment.setParam("contentObj", nbcu.content.object);
*/

	jqN("#comment-content").hide();
	jqN('.comments-trigger').addClass('active');
	triggerComments();
//closeTabs();
});



/******** RECOMMENDATIONS **********/
function loadFilterRec(video, type, page){
	var perPage;
	
	if (type == "more") {
		perPage = 7;
	} else {
		type = "less";
		perPage = 3;
	}
	page = page || 1;
	
	if (nbcu.app.scet.video.getParam("abGroup") == "nbceditorial") {
		source = "editorial";	
	} else if (nbcu.app.scet.video.getParam("abGroup") == "thefilter") {
		source = "thefilter";
	}
	jqN.ajax({
		type: "GET",
		url: '/assets/esp/video/feed/getRecommendedVideo/.json',
		data: {perPage: perPage, page: page, videoId: video, source: source},
		dataType: "json",
		beforeSend: function(xhr){xhr.setRequestHeader("X-Framework-JSON-Request", "PLAINJSON");},
		success: function(data){displayFilter(data, type, page, perPage)},
		error: function(XMLHttpRequest, textStatus, errorThrown){},
		cache: false
	});
}

function newNBCPageview()
{
	window.ad728x90.location.reload();
	window.ad300x250.location.reload();
	s.t();
}

function displayFilter(data, type, page, perPage){
	jqN('#filter-recommendations div').remove();
	jqN('#filter-recommendations ul').remove();
	var html = "<ul>";
	var x = 0;
	var uriAppend = "";

	for (x = 0; x <data.pageRecords.length;x++ ) {
		var title = data.pageRecords[x].title;
		var description = data.pageRecords[x].shortDescription;
		var thumbnail = data.pageRecords[x].largeThumbnailUrl;
		var uri = data.pageRecords[x].fullUrl;
			if (nbcu.app.scet.video.getParam("abGroup") == "nbceditorial") {
			uriAppend = "__cid=nbceditorial";	
		} else if (nbcu.app.scet.video.getParam("abGroup") == "thefilter") {
			uriAppend = "__cid=thefilter";	
		}
		
		if (uriAppend) {
			uri = (uri.indexOf('?') >= 0) ? uri + '&' + uriAppend : uri + '?' + uriAppend;
		}
		
		onClick = "nbcu.app.scet.video.logEvent({ event: 'recClick', recId: " + nbcu.app.scet.video.getParam("assetId") + " });"

		html += listTemplate(title, description, uri, getMezzanine('http://video.nbc.com/' + thumbnail,'106','59'), "h5", onClick);
	}
	html += "</ul>";
	if (type == "more") {
		html += '<div style="text-align: center;" class="rec-pagination">';
		html += getPagination(data.totalRecords, page, perPage);
		html += '</div>';
	} else {
		html += '<div class="right"><a class="more" href="javascript:void(0);">MORE</a></div>';
	}
	jqN('#filter-recommendations').append(html);
	
	// bind MORE click
	jqN('#filter-recommendations .more').click(function() {
		var contentId = nbcu.content.object.getParam("contentId");
		loadFilterRec(contentId, "more");
	});
	
	// bind pagination clicks
	jqN('#filter-recommendations .paginatePrev').click(function() {
		var contentId = nbcu.content.object.getParam("contentId");
		loadFilterRec(contentId, "more", page - 1);
	});
	jqN('#filter-recommendations .paginateNext').click(function() {
		var contentId = nbcu.content.object.getParam("contentId");
		loadFilterRec(contentId, "more", page + 1);
	});	
	
	jqN('#filter-recommendations').slideDown();
}
/******** END RECOMMENDATIONS **********/

/******** RELATED VIDEOS **********/
function loadRelatedVideo(cat){
	return;
	var url = '/The_Office/video2/output/json/';
	jqN.getJSON(url+cat+'.json',function(data){	
		displayRelated(data);
	});
}
function displayRelated(data){	
	var output = '<div class="browse-videos-content"><a href="javascript:void(0);" class="back-browse right">Back to Browse</a>';
	output += '<h3>'+data.c+'</h3>';
	output += '<ul>';
	jqN(data.r).each(function(i){
	if(i <= 7)
		output += listTemplate(this.t,this.d,this.p,getMezzanine(this.et,'106','59'));
	});
	output += '</ul></div>';
	
	jqN('.browse-all-nav').hide();
	jqN('#browse-all-video').append(output);
	jqN('#browse-tab').bind('click',closeBrowse);
	jqN('.back-browse').bind('click',closeBrowse);
}

function closeBrowse(){
	jqN('#scet_browse_pager').hide();
	jqN('.browse-videos-content').hide();
	jqN('.browse-all-nav').show();
}
/******** END RELATED VIDEOS **********/

/******** EPISODE GUIDE **********/
function loadEpisodeGuide(video) {
	jqN.ajax({
		type: "GET",
		url: '/assets/esp/episodeguide/episode/feed/.json',
		data: {videoId: video},
		dataType: "json",
		beforeSend: function(xhr){xhr.setRequestHeader("X-Framework-JSON-Request", "PLAINJSON");},
		success: function(data){
			displayEpisodeGuide(data);
			displayExclusiveContent(data);
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){}
	});	
}

function displayEpisodeGuide(data) {
	var html = "";
	var x = 0;
	var episodeTitle = '';
	var episodeAirDate = '';
	var episodeDescription = '';
	var episodeRunningTime = '';
	var episodeHd = '';
	var episodeTvRating = '';
	var videoUri = '';
	var videoThumbnail = '';
	var expireDate = '';
	var isExpired = 'N';
	var videoClip = new Array();
    var arrVideoUrls = new Array();
	var communityUri = '';
	var galleryUri = '';
	var recapUri = '';
	
	jqN('#episode-guide').empty();

	if ((typeof data.episode_info != 'undefined' && typeof data.episode_info[0] != 'undefined') || (typeof data.guest_one != 'undefined' && typeof data.guest_one[0] != 'undefined')) {

		if (data.episode_info[0].video != null && typeof data.episode_info[0].video[0] != 'undefined') {
			episodeTitle = data.episode_info[0].video[0].episode_title;
			episodeAirDate = data.episode_info[0].video[0].original_airdate;
			episodeDescription = data.episode_info[0].video[0].synopsis;
			videoUri = data.episode_info[0].video[0].video_url;
			videoThumbnail = getMezzanine(data.episode_info[0].video[0].large_thumbnail_url,'106','59');
			isExpired = data.episode_info[0].video[0].expired;

			var clipLength = data.episode_info[0].video[0].cliplength.split('.');
			var clipLengthInMin = parseInt(clipLength[0] / 60);
			var clipLengthInSec = clipLength[0] - (clipLengthInMin * 60);
			episodeRunningTime = clipLengthInMin + ':' + clipLengthInSec;
			var expireDateTimeArray = data.episode_info[0].video[0].expire_date.split(' ');
			var expireDateArray = expireDateTimeArray[0].split('-');
			expireDate = expireDateArray[1] + '/' + expireDateArray[2] + '/' + expireDateArray[0];			
        } else if (typeof data.guest_one[0] != 'undefined') {
            if (document.location.href.indexOf('video/preview') != -1) {
			    hideEpisodeGuide();
                return;
            }
            episodeTitle = data.guest_one[0].episode_title;
            var arrStartDateParts = data.guest_one[0].start_date.split(' ');
            var arrMonthParts = arrStartDateParts[0].split('-');
            var monthNumeric = '01';
            switch (arrMonthParts[1]) {
            case 'january':
            case 'January':
                monthNumeric = '01';
                break;
            case 'february':
            case 'February':
                monthNumeric = '02';
                break;
            case 'march':
            case 'March':
                monthNumeric = '03';
                break;
            case 'april':
            case 'April':
                monthNumeric = '04';
                break;
            case 'may':
            case 'May':
                monthNumeric = '05';
                break;
            case 'june':
            case 'June':
                monthNumeric = '06';
                break;
            case 'july':
            case 'July':
                monthNumeric = '07';
                break;
            case 'august':
            case 'August':
                monthNumeric = '08';
                break;
            case 'september':
            case 'September':
                monthNumeric = '10';
                break;
            case 'october':
                monthNumeric = '11';
                break;
            }

            var arrDateAndYearParts = arrStartDateParts[1].split('-');
            episodeAirDate = monthNumeric + '/' + arrDateAndYearParts[0] + '/' + arrDateAndYearParts[1];
            episodeDescription = data.guest_one[0].guest_one_144x81_copy;
            videoUri = '';
            videoThumbnail = '';
            isExpired = true;

            var clipLength = '';
            var clipLengthInMin = '';
            var clipLengthInSec = '';
            episodeRunningTime = '';
            var expireDate = '';


		} else {
			hideEpisodeGuide();
			return;
		}
	
        communityUri = '';
        if (data.episode_info[0].episode_info_community_url) {
		    communityUri = data.episode_info[0].episode_info_community_url;
        }
        galleryUri = '';
        if (data.episode_info[0].gallery && data.episode_info[0].gallery.length > 0) {
            if (data.episode_info[0].gallery[0].gallery_url) {
		        galleryUri = data.episode_info[0].gallery.length > 0 ? data.episode_info[0].gallery[0].gallery_url : '';
            }
        }
        recapUri = '';
        if (data.episode_info[0].recap_url && data.episode_info[0].episode_info_recap_id) {
            if (data.episode_info[0].episode_info_recap_id != '') {
		        recapUri = data.episode_info[0].recap_url;
            }
        }
		
        try {
			// video clips in the episode_info node
			if (data.episode_info[0].shortform_video != null) {
				for (x in data.episode_info[0].shortform_video) {
                    if (jqN.inArray(data.episode_info[0].shortform_video[x][0].video_url, arrVideoUrls) == -1) {
					    var clip = {
						    title: data.episode_info[0].shortform_video[x][0].title,
						    uri : data.episode_info[0].shortform_video[x][0].video_url,
						    thumbnail: getMezzanine(data.episode_info[0].shortform_video[x][0].large_thumbnail_url,'106','59')
					    }
					    videoClip.push(clip);
                        arrVideoUrls.push(data.episode_info[0].shortform_video[x][0].video_url);
                    }
				}			
			}
		} catch(err) {
        }
		try {
			// video clips in the guest_one node
			if (data.guest_one[0].video != null) {
				for (x in data.guest_one[0].video) {
                    if (jqN.inArray(data.guest_one[0].shortform_video[x][0].video_url, arrVideoUrls) == -1) {
					    var clip = {
						    title: data.guest_one[0].video[x][0].title,
						    uri : data.guest_one[0].video[x][0].video_url,
						    thumbnail: getMezzanine(data.guest_one[0].video[x][0].large_thumbnail_url,'106','59')
					    }
					    videoClip.push(clip);
                        arrVideoUrls.push(data.guest_one[0].video[x][0].video_url);
                    }
				}			
			}			
		} catch(err) {
        }
		
	} else {
		hideEpisodeGuide();
		return;
	}

	html = '<h2>Episode Guide</h2>';
	
	html += '<ul class="show-info">';
	html += '<li><h4>' + episodeTitle + '</h4></li>';
	html += '<li class="show-air-date">Original Air Date: ' + episodeAirDate + '</li>';
    if (episodeRunningTime != '') {
	    html += '<li class="show-running-time">Running Time: ' + episodeRunningTime + '</li>';
    }
	html += '<li class="hd">HD</li>';
	html += '<li class="tv-rating">TV-14</li>';
	html += '</ul>';
	
	html += '<div class="guide-wrap">';
	// description
	html += '<div class="guide-show-desc guide-element"><p>' + episodeDescription + '</p></div>';
	// full episodes
	html += '<div class="guide-full-episode guide-element">';
	html += '<h4>Full Episode</h4>';

	if (data.episode_info[0].video != null && typeof data.episode_info[0].video[0] != 'undefined') {
	    html += '<a href="' + videoUri + '" class="border"><img src="' + videoThumbnail + '" /></a>';
	    html += '<ul><li class="episodes-icon show-icon"><a href="' + videoUri + '">' + episodeTitle + '</a></li></ul>';
	    if (isExpired == 'N') {
		    html += '<p>Available Until:<br />' + expireDate + '</p>';
	    } else {
		    html += '<p>Expired</p>';
	    }
    } else {
        html += 'No Full Episode available';
    }
	html += '</div>';
	// clips
	html += '<div class="guide-video-clips guide-element">';
	html += '<h4>Video Clips</h4>';
	if (videoClip.length > 0 ) {
		html += '<a href="' + videoClip[0].uri + '" class="border"><img src="' + videoClip[0].thumbnail + '" /></a>';
		html += '<ul>';
		for (x in videoClip) {
			html += '<li class="clips-icon show-icon"><a href="' + videoClip[x].uri + '">' + videoClip[x].title + '</a></li>';
		}
		html += '</ul>';
	} else {
		html += 'No Video Clips';
	}
	html += '</div>';
	// related content
	html += '<div class="guide-related-content guide-element">';
	html += '<h4>Related Content</h4>';

    if (communityUri || recapUri || galleryUri) {
	    html += '<ul>';
	    if (communityUri) {
		    html += '<li class="community-icon show-icon"><a href="' + communityUri + '">Community</a></li>';
	    }
	    if (recapUri) {
		    html += '<li class="showsite-icon show-icon"><a href="' + recapUri + '">Recap</a></li>';
	    }
	    if (galleryUri) {
		    html += '<li class="photos-icon show-icon"><a href="' + galleryUri + '">Photos</a></li>';
	    }
	    html += '</ul>';
    } else {
        html += 'No Related Content available';
    }
	html += '</div>';
	html += '</div>';
	
	jqN('#episode-guide').html(html);
	jqN('#episode-guide').show();
}

function hideEpisodeGuide() {
	jqN('#episode-guide').hide();
}

function displayExclusiveContent(data) {
	if (typeof data.related != 'undefined') {
		jqN('#favorites-exclusive-content ul').hide().empty();
		jqN('#favorites-exclusive-content').show();
		
		var html = "";
		var x;
		for (x in data.related) {
			if (x > 3) {
				break;
			}
			
			var title = data.related[x].related_content_label;
			var description = '';
			var thumbnail = data.related[x].related_content_thumbnail;
			var uri = data.related[x].related_content_url;
			if(thumbnail)
			{
				html += listTemplate(title, description, uri, thumbnail, 'h4');
			}
		}
		if (html != '') {
			jqN('#favorites-exclusive-content ul').append(html);
			jqN('#favorites-exclusive-content li:last').addClass("last");
			jqN('#favorites-exclusive-content ul').show();				
			return;
		}
	}
	
	jqN('#favorites-exclusive-content').hide();
}
/******** END EPISODE GUIDE **********/

/******** FULL EPISODE **********/
function loadFullEpisodes(video, page, perPage) {
	return; // Turned off temporarily to be populated on server side instead
	page = page || 1;
	perPage = perPage || 4;
	
	jqN.ajax({
		type: "GET",
		url: '/assets/esp/video/feed/getRelatedFullEpisode/.json',
		data: {videoId: video, perPage: perPage, page: page},
		dataType: "json",
		beforeSend: function(xhr){xhr.setRequestHeader("X-Framework-JSON-Request", "PLAINJSON");},
		success: function(data){displayFullEpisodes(data, page, perPage)},
		error: function(XMLHttpRequest, textStatus, errorThrown){}
	});	
}

function displayFullEpisodes(data, page, perPage) {
	try {
		if (data.totalRecords < 1) {
			jqN('#favorites-full-eps').hide();
			return;
		}
	
		jqN('#favorites-full-eps ul').hide().empty();
		jqN('#favorites-full-eps').show();
		
		var html = "";
		var x = 0;
		for (x in data.pageRecords) {
			var title = data.pageRecords[x].title;
			var description = 'Airdate: ' + data.pageRecords[x].original_airdate;
			var thumbnail = data.pageRecords[x].large_thumbnail_url;
			var uri = data.pageRecords[x].video_url;
			html += listTemplate(title, description, uri, getMezzanine(thumbnail,'129','72'), 'h4');
		}
		
		jqN('#favorites-full-eps ul').append(html);
		jqN('#favorites-full-eps ul li:last').addClass("last");
		jqN('#favorites-full-eps ul').show();
	} catch(e) {
		jqN('#favorites-full-eps').hide();
	}
}
/******** END FULL EPISODE **********/

/******** VIDEO CLIPS **********/
function loadVideoClips(video, page, perPage) {
	//return;
	page = page || 1;
	perPage = perPage || 4;

	jqN.ajax({
		type: "GET",
		url: '/assets/esp/video/feedDetail/getRelatedDetail/.json',
		data: {videoId: video, perPage: perPage, page: page},
		dataType: "text",//"json",
		cache: true,
		beforeSend: function(xhr){xhr.setRequestHeader("X-Framework-JSON-Request", "PLAINJSON");},
		success: function(data){
            // XXX - work around
            if (data.substr(0, 2) == '//') {
                data = data.slice(2,data.length);
            }
            data = eval('(' + data + ')');
            displayVideoClips(data, video);
        },
		error: function(XMLHttpRequest, textStatus, errorThrown){}
	});
}

function displayVideoClips(data, videoId) {
	try {
		if (data.pageRecords.length < 1) {
			jqN('#favorites-video-clips').hide();
			return;
		}

		var html = "";
		var x = 0;
		for (x in data.pageRecords) {
			var title = data.pageRecords[x].title;
			var description = '';
			var thumbnail = data.pageRecords[x].mezzanineThumbnailUrl;
			var uri = data.pageRecords[x].video_url;
			if (title && uri) {
                var titleSize = 'h4';
    			var imageWidth = 129;
    			var imageHeight = 72;
    			var onclick = '';
    			var resizedThumb = getLargeVidThumbnail(thumbnail, imageWidth, imageHeight);
    			html += listTemplate(title, description, uri, resizedThumb, titleSize, onclick, imageWidth, imageHeight);
            }
		}

		jqN('#favorites-video-clips').show();
		jqN('#favorites-video-clips ul').hide();
        jqN('#favorites-video-clips ul').empty().append(html);
		jqN('#favorites-video-clips ul li:last').addClass("last");
		jqN('#favorites-video-clips ul').show();

        if (data.page > 1) {
            jqN("#prev-vid-scroller").unbind('click').click(function() {
                loadVideoClips(videoId, (data.page - 1), data.perPage); return false;
            });

            jqN("#vid-scroll-left").attr('src', '/assets/images/scroll-left.gif');
        }
        else {
            jqN("#prev-vid-scroller").unbind('click');
            jqN("#vid-scroll-left").attr('src', '/assets/images/scroll-left-disabled.gif');
        }

        if (data.totalPages > 1 && data.page < data.totalPages) {
            jqN("#next-vid-scroller").unbind('click').click(function() {
                loadVideoClips(videoId, (data.page + 1), data.perPage); return false;
            });
            jqN("#vid-scroll-right").attr('src', '/assets/images/scroll-right.gif');
        }
        else {
            jqN("#next-vid-scroller").unbind('click');
            jqN("#vid-scroll-right").attr('src', '/assets/images/scroll-right-disabled.gif');
        }
	} catch(e) {
		jqN('#favorites-video-clips').hide();
	}
}
/******** END VIDEO CLIPS **********/

/******** PHOTOS **********/
function loadPhotos(video, page, perPage) {
//	return;
	page = page || 1;
	perPage = perPage || 4;
	
	jqN.ajax({
		type: "GET",
		url: '/assets/esp/video/feed/getRelatedGallery/.json',
		data: {videoId: video, perPage: perPage, page: page},
		dataType: "text",
		cache: true,
		beforeSend: function(xhr){xhr.setRequestHeader("X-Framework-JSON-Request", "PLAINJSON");},
		success: function(data){
            // XXX - work around
            if (data.substr(0, 2) == '//') {
                data = data.slice(2,data.length);
            }
            data = eval('(' + data + ')');
            displayPhotos(data, video);
        },
		error: function(XMLHttpRequest, textStatus, errorThrown){}
	});	
}

function displayPhotos(data, videoId) {
	try {
		if (data.totalRecords < 1) {
			jqN('#favorites-photos').hide();
			return;
		}

		var html = "";
		var x = 0;
		for (x in data.pageRecords) {
			var title = data.pageRecords[x].gallery_title;
			var description = '';
			var thumbnail = data.pageRecords[x].gallery_item_thumb;
			var uri = data.pageRecords[x].gallery_item_url;
            if (title && uri) {
    			var titleSize = 'h4';
    			var imageSize = {width: '129', height: '72'};
    			var onclick = '';
    			var resizedThumb = getResizedThumbnail(thumbnail, imageSize.width, imageSize.height);
    			html += listTemplate(title, description, uri, resizedThumb, titleSize, onclick, imageSize.width, imageSize.height);
            }
		}

		jqN('#favorites-photos').show();
		jqN('#favorites-photos ul').hide();
		jqN('#favorites-photos ul').empty();
		jqN('#favorites-photos ul').append(html);
		jqN('#favorites-photos ul li:last').addClass("last");
		jqN('#favorites-photos ul').show();

        if (data.page > 1) {
            jqN("#vid-prev-pic-scroller").unbind('click').click(function() {
                loadPhotos(videoId, (data.page - 1), data.perPage); return false;
            });

            jqN("#pic-scroll-left").attr('src', '/assets/images/scroll-left.gif');
        }
        else {
            jqN("#vid-prev-pic-scroller").unbind('click');
            jqN("#pic-scroll-left").attr('src', '/assets/images/scroll-left-disabled.gif');
        }

        if (data.totalPages > 1 && data.page < data.totalPages) {
            jqN("#vid-next-pic-scroller").unbind('click').click(function() {
                loadPhotos(videoId, (data.page + 1), data.perPage); return false;
            });
            jqN("#pic-scroll-right").attr('src', '/assets/images/scroll-right.gif');
        }
        else {
            jqN("#vid-next-pic-scroller").unbind('click');
            jqN("#pic-scroll-right").attr('src', '/assets/images/scroll-right-disabled.gif');
        }
	} catch(e) {
		jqN('#favorites-photos').hide();
	}
}
/******** END PHOTOS **********/

/******** LIKE IT **********/
function triggerLikeIt() {
	nbcu.util.common.loadClass("Nbcu.Content.Object");
	
	if (jqN("#like-it-content iframe").length > 0) {
		return;
	}
	
	isLiked = true;
	
	jqN("#like-it-content").empty().css("text-align", "center");

/*
	jqN('<iframe></iframe>').attr({
		src: '/app/modules/snas-like/frames/v4-login.php?hasChrome=false',
		frameborder: 0,
		scrolling: 0,
		id: "likeItFrame",
		name: "likeItFrame",
		width: 645,
		height: 280
	}).appendTo(jqN("#like-it-content"));
*/	
	
	jqN("#like-it-content").append('<iframe frameBorder="0" allowtransparency="true" scrolling="0" width="645" height="280" src="/app/modules/snas-like/frames/v4-login.php?hasChrome=false"></iframe>');
	jqN("#like-it-content").append('<a class="close-like-it right" href="javascript:void(0);">Close Like It</a>');
	jqN("#like-it-content .close-like-it").click(function() {
		isLiked = false;
		nbcu.content.object.registerUserAction("like", null, false);
		jqN("#like-it-content iframe").remove();
		closeLeftTabs();
	});
	
	if (jqN.browser.msie6 == true ) {
		jqN("#like-it-content iframe").attr('contentWindow').location.reload(true);
	}
	
	jqN(window).unload(function() {
		if (isLiked) {
			nbcu.content.object.registerUserAction("like", null, false);
		}
	});	
}
/******** END LIKE IT **********/

/******** TAGS **********/
function triggerTags() {
	nbcu.util.common.loadClass("Nbcu.Content.Object");
	
	if (jqN("#tags-content iframe").length > 0) {
		return;
	}
	
	jqN("#tags-content").empty().css("text-align", "center");
	
/*	
	jqN('<iframe></iframe>').attr({
		src: '/app/modules/snas-tag/frames/v4-login.php?hasChrome=false',
		frameborder: 0,
		scrolling: 0,
		id: "tagsFrame",
		name: "tagsFrame",
		width: 645,
		height: 285
	}).appendTo(jqN("#tags-content"));
*/	
	jqN("#tags-content").append('<iframe frameBorder="0" allowtransparency="true" scrolling="0" width="645" height="285" src="/app/modules/snas-tag/frames/v4-login.php?hasChrome=false"></iframe>');
	jqN("#tags-content").append('<a class="close-tags right" href="javascript:void(0);">Close Tags</a>');
	jqN("#tags-content .close-tags").click(function() {
		jqN("#tags-content iframe").remove();
		closeLeftTabs();
	});	
	
	if (jqN.browser.msie6 == true ) {
		jqN("#tags-content iframe").attr('contentWindow').location.reload(true);
	}	
}
/******** END TAGS **********/

/******** COMMENTS **********/
function triggerComments() {
	if (jqN("#comment-content").css('display') != 'none') {
		return;
	}
	
/* VERSION 2	
	if (jqN("#comment-content").children().length < 1) {
		var html = '<h3>User Comments</h3>'
			+ '<a href="javascript:void(0);" class="post-comment right">Post a Comment</a>'
			+ '<div class="clear"></div>'
			+ '<div class="sn_comment_div"></div>'
			+ '<div class="sn_comment_pager_div"></div>'
			+ '<div class="sn_comment_form_div" style="display:none;"></div>'
			+ '<a href="javascript:void(0);" class="close-comments right">Close Comments</a>';
		jqN("#comment-content").append(html);
	}
	
	nbcu.sn.comment.init();
*/
	
	nbcu.sn.comment.renderComments(null, function() {
		getCommentsCount();
		if (jqN("#comment-content .close-comments").length < 1) {
			jqN("#comment-content").append('<a href="javascript:void(0);" class="close-comments right">Close Comments</a>');
			jqN("#comment-content .close-comments").click(function() {
				closeLeftTabs();
				jqN('#comment-content .sn_comment_div').show();
				jqN('#comment-content .sn_comment_pager_div').show();
				jqN('#comment-content .post-comment').show();
				jqN('#comment-content .sn_comment_form_div').hide();		
			});
		}
	});
	
	jqN("#comment-content .sn_comment_form_div").css('width', '634px');	

/* VERSION 2
	jqN("#comment-content .post-comment").click(function() {
		jqN('#comment-content .sn_comment_div').hide();
		jqN('#comment-content .sn_comment_pager_div').hide();
		jqN('#comment-content .post-comment').hide();
		jqN('#comment-content .sn_comment_form_div').show();
	});

	jqN("#comment-content .close-comments").click(function() {
		closeLeftTabs();
		jqN('#comment-content .sn_comment_div').show();
		jqN('#comment-content .sn_comment_pager_div').show();
		jqN('#comment-content .post-comment').show();
		jqN('#comment-content .sn_comment_form_div').hide();		
	});
*/
	
	jqN("#comment-content").show();
}

function getCommentsCount() {
	jqN('.share-list .comments-trigger').text('(' + nbcu.sn.comment.getParam('totalRecords') + ')');
	
	
/*** VERSION 2	
	jqN.ajax({
		cache: false,
		type: "GET",
		url: "/app/api/sn/snas/",
		data: {
			method: 'getContentDetails',
			contentSSUniqueKey: nbcu.content.object.getParam('contentSSUniqueKey'),
			contentType: nbcu.content.object.getParam('contentType'),
			siteName: nbcu.config.getParam("snasSiteName"),
			siteDomainName: nbcu.config.getParam("snasSiteDomainName")
		},
		dataType: "xml",
		success: function(data){
			if (commentCount = jqN(data).find("commentCount").text()) {
				jqN('.share-list .comments-trigger').text('(' + commentCount + ')');
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){}
	});
*/	
}
/******** END COMMENTS **********/

/******** SHARE **********/
function triggerShare() {
	jqN("#share-it-content .share-embed").val(nbcu.content.object.getParam('embedCode'));
	jqN("#share-it-content .share-permalink").val(window.location.href);
	jqN("#share-it-content .close-share").click(function() {
		closeLeftTabs();
	});	
}
/******** END SHARE **********/

/************* UTILITIES *************/
function dimScreen(){
if(jqN.support.opacity == true){
	isDimmed=true;
	jqN(window).bind('resize',dimScreen);
	var stageWidth = document.documentElement.clientWidth;
	var stageHeight = jqN('#nbc-wrapper').height()+jqN('#nbc-footer').height();

	if(jqN('#trans-overlay').length == 0){
				var overlay = jqN('<div/>').attr({id:'trans-overlay'}).css({position:'absolute',left:'0',top:'0',backgroundColor: '#000',opacity:'.85',zIndex: '99999',filter: 'alpha(opacity = 85)'}).width(stageWidth).height(stageHeight);
			


		jqN('body').append(overlay); 
	
		jqN('#video-player').css('zIndex','99999999');
				//jqN('#nbc-728').css('zIndex','99999999');		
				//jqN('#companionAdDiv').css('zIndex','99999999');
//jqN('#ad300x60').css('zIndex','99999999');		

	}else{
		//jqN('#trans-overlay').width(stageWidth).height(stageHeight);
		jqN('#video-player').css('zIndex','99999999');
	//jqN('#nbc-728').css('zIndex','99999999');		
				//jqN('#companionAdDiv').css('zIndex','99999999');
	
//jqN('#ad300x60').css('zIndex','99999999');

	}

	if(activeAd){
		jqN('#user-controls ul').css('zIndex','9999999');
		
	}else{
		jqN('#user-controls ul').css('zIndex','999999');
		
	}


	jqN('#trans-overlay').click(removeDim);
}
}

function removeDim(){

		if(!activeAd){
			isDimmed=false;
		jqN(window).unbind('resize',dimScreen);
		//jqN('#user-controls ul').css('zIndex','inherit');
		

		jqN('#trans-overlay').fadeOut('fast').remove();
		try {
//			jqN('#video-player').css('zIndex','inherit');
			jqN('#video-player').css('zIndex','1');
			jqN('#nbc-728').css('zIndex','10');		
		jqN('#companionAdDiv').css('zIndex','10');
jqN('#ad300x60').css('zIndex','10');

		} catch(e) {}
		
	}

}

function dumbTabs(element,trigger,target){
	if (jqN(element).hasClass('tag-it-trigger')) {
		triggerTags();
	} else if (jqN(element).hasClass('like-it-trigger')) {
		triggerLikeIt();
	} else if (jqN(element).hasClass('comments-trigger')) {
		triggerComments();
	} else if (jqN(element).hasClass('share-it-trigger')) {
		triggerShare();
	}

	if(!jqN(element).hasClass('active')){
		var index = jqN(trigger).index(element);
		jqN(trigger).removeClass('active');
		jqN(element).addClass('active');
		jqN(target).hide();
		jqN(target).eq(index).show();
	}
	
}

function closeLeftTabs() {

	jqN('#comment-content').hide();
	jqN('#share-it-content').hide();
	jqN('#tags-content').hide();

	jqN('#like-it-content').hide();


	jqN('.share-list li a').removeClass('active');
}



function closeTabs() {
	jqN('.tab-content').hide();
	jqN('.share-list li a').removeClass('active');
}

function preloadImage(obj){
	try{
		var alt = obj.alt.replace(/\"/g,"&quot;");
		var img = jqN('<img/>')
		.attr({
			alt:alt,
			title:alt,
			src:obj.src
		});

	return img;
	}catch(e){/*fail*/}
}

function getLargeVidThumbnail(mezzThumbPath, w, h) {
    var pattern = /http:\/\/video-origin.nbcuni.com\/mezzthumb\//;
    return mezzThumbPath.replace(pattern, 'http://video.nbc.com/player/mezzanine/image.php?w=' + w + '&h=' + h + '&trusted=yes&path=');
}

function getResizedThumbnail(uri, w, h) {
	var pattern = /\/app2\/img\/95x88xC\/scet/;
	return uri.replace(pattern, '/app2/img/' + w + 'x' + h + 'xC/scet');
}

function getPagination(recordCount, page, perPage) {
	var html = "";
	
	// prev
	if (recordCount > perPage && page > 1) {
		html += '<a class="paginatePrev" href="javascript:void(0);">PREV</a>';
	} else {
		html += '';
	}

// next
	if (recordCount > page * perPage) {
		html += (html) ? ' | ' : '';
		html += '<a class="paginateNext" href="javascript:void(0);">NEXT</a>';
	} else {
		html += '';
	}
	
	return html;
}
/************* END UTILITIES *************/
