Ka.playPage = {
	mediaSets: {
		init: function() {
			// setup meta bubble
			this.metaBubble = new bubbleClass();
		},
		templates: {
			listItem: '<a {7} href="/_{0}/{8}/{3}/{4}.html?setId={5}{6}"><img src="{1}" alt="{2}"/></a>'
		},
				
		loadSet: function(setContents, currentIndex, visibleItems, setId) {
			this.currentSet = {
				contents: setContents,
				visibleItems: visibleItems,
				index: currentIndex,
				setId: setId
			}

			this.setupCarousel();
		},
		setupCarousel: function() {
			if (Ka.playPage.mediaSets.currentSet.contents.mediaSetItems.length <= 5) { return; }
			$j('#ka_mediaSetCarousel ul').removeClass('pending').empty().jcarousel({
		        //wrap: 'both',
		        itemVisibleInCallback: {
					onBeforeAnimation: Ka.playPage.mediaSets.carouselVisibleInCallbackBefore,
					onAfterAnimation: Ka.playPage.mediaSets.carouselVisibleInCallbackAfter
				},
		        itemVisibleOutCallback: {
					onAfterAnimation: Ka.playPage.mediaSets.carouselVisibleOutCallback
				},
		        offset: 1,
		        scroll: 5,
		        size: this.currentSet.contents.mediaSetItems.length,
		        start: Ka.playPage.mediaSets.currentSet.index - 1 //- 1
		    });
		},
		
		carouselVisibleInCallbackBefore: function(carousel, item, i, state, evt)
		{
			var mediaSets =  Ka.playPage.mediaSets,
				mediaSetItems = mediaSets.currentSet.contents.mediaSetItems,
				idx = carousel.index(i, mediaSetItems.length);
			
		    carousel.add(i, mediaSets.carouselGetItem(mediaSetItems[idx - 1]));
		},
		
		carouselVisibleInCallbackAfter: function () {
			$j('#ka_mediaSetCarousel ul li.jcarousel-item a.current-item').parents('li').addClass('current-item');
			
		},

		carouselVisibleOutCallback: function(carousel, item, i, state, evt)
		{
		    carousel.remove(i);
		},
		
		carouselGetItem: function(item)
		{
			var enlarge = Ka.Util.getLocationParam("enlarge") == "true" ? "&enlarge=true" : "",
				cssClass = '';
				
			if (item.position == Ka.playPage.mediaSets.currentSet.index) {
				cssClass = " class='current-item' ";
			}
			
		    var x = this.templates.listItem.format(
			    		Ka.String.cleanUpRestUrl(item.mediaName),
			    		Ka.Info.AUDIOPHOTOSERVERPATH + item.pathToPreview100X75, 
			    		item.mediaName, 
			    		item.mediaId, 
			    		Ka.Info.AFFILIATESITEID,
			    		Ka.playPage.mediaSets.currentSet.setId,
			    		enlarge,
						cssClass,
						Ka.playPage.mediaSets.getMediaType(item.mediaTypeId)
	    			);
			return x;
		},
		
		gotoPrevious: function() {
			var currentPosition = Ka.playPage.mediaSets.currentSet.index,
				items = this.currentSet.contents.mediaSetItems,
				previousPosition = currentPosition - 1;
			
			if (previousPosition < 0) {
				previousPosition = items.length - 1;
			}
			
			this.gotoMediaItem(items[previousPosition]);
		},
		
		gotoNext: function() {
			var currentPosition = Ka.playPage.mediaSets.currentSet.index,
				items = this.currentSet.contents.mediaSetItems,
				nextPosition = currentPosition + 1;
			
			if (nextPosition > items.length - 1) {
				nextPosition = 0;
			}
			
			this.gotoMediaItem(items[nextPosition]);
		},
		
		getMediaType: function(id) {
			switch (id) {
				case 1: return "audio";
				case 2: return "blog";
				case 4: return "photo";
				case 5: return "video";
			}			
		},
		
		gotoMediaItem: function(item) {
			
			var name = Ka.String.cleanUpRestUrl(item.mediaName),
				mediaType = this.getMediaType(item.mediaTypeId),
				enlarge = Ka.Util.getLocationParam("enlarge") == "true" ? "&enlarge=true" : "",
				url = "/_" + name + "/" + mediaType + "/" + item.mediaId + "/" + Ka.Info.AFFILIATESITEID + ".html?setId=" + Ka.playPage.mediaSets.currentSet.setId + enlarge;
			location.href = url;
		},
		
		showMeta: function(el) {
    		var $this = $j(el);
    			$details = $this.find('.ka_mediaDetails');
    		
    		this.metaBubble.show($details, el);
    	},
    	
    	hideMeta: function(el) {
    		this.metaBubble.hide(el);
    	}
	}
}
Ka.playPage.mediaSets.init();

if($j.browser.msie && $j.browser.version == '6.0') {
	Ka.Compatibility.IE.fixOversizedEmbed('#ka_leftColumn');
}

function getUserRating(){
	// DWR call to get the rating details (if exists)
	KickAppsBizComponent.getRatedMediaForUser(Ka.Info.MEDIAID,Ka.Info.USERID,Ka.Info.MEDIATYPE,Ka.Info.AFFILIATESITEID,function(ratingObject){
		// create a new star system object
		mediaRatingSystem = new kap_starSystem(ratingObject!==null ? 'view' : 'rate','L',{avg:Math.round(Ka.Info.AVERAGERATING),numRatings:Ka.Info.VOTES});
		// show the rating system
		mediaRatingSystem.show('currentRatingArea');
	});
}

$j(function(){
	//if not logged in
	if(Ka.Info.USERID===''){
		// create a new star system object
		var mediaRatingSystem = new kap_starSystem('view','L',{avg:Math.round(Ka.Info.AVERAGERATING),numRatings:Ka.Info.VOTES});
		// show the rating system
		mediaRatingSystem.show('currentRatingArea');
	}else{
		// get the user's rating
		getUserRating();
	}
	if (!Ka.events.dispatchEvent('play-page-load')) {return false;}
});

function kap_rateMedia(rating){
	// DWR call to insert the rating
    KickAppsBizComponent.rateMedia(Ka.Info.USERID,Ka.Info.MEDIAID,Ka.Info.MEDIATYPE,rating,Ka.Info.AFFILIATEID,Ka.Info.AFFILIATESITEID, function(result){
    	Ka.events.dispatchEvent('play-page-after-rating', result);
    });
}


function getAnswer(flag) {
	var favoriteText = "";
	if (flag === true) {
		favoriteText = getRemoveText();
	} else {
		favoriteText = "<a href='javascript:addFavoriteMedia();'>"+Ka.Messages.PlayPage.ADDTOFAV+"</a>";
	}
	DWRUtil.setValue("favoriteArea", favoriteText);
}

function sendMessage() {
	if (tinymce.EditorManager.editors.text) tinymce.EditorManager.editors.text.save();
	
	var text = $("text").value;
	if (text === "") {return;}
	if (text.indexOf('\n') !==-1){
		text = text.replace(/\n/g,'<br />');
	}	
	DWRUtil.setValue("text", "");

	if (!Ka.events.dispatchEvent('play-page-before-add-comment', {commentText: text})) {return false;}

	KickAppsBizComponent.addMessage(text, Ka.Info.MEDIAID, Ka.Info.MEDIATYPE, Ka.Info.USERID, 1024, Ka.Info.AFFILIATESITEID, function (bool) {
		if (tinymce.EditorManager.editors.text) tinymce.EditorManager.editors.text.setContent('');
		if (bool) {
			if (!Ka.events.dispatchEvent('play-page-after-add-comment', {success:  true})) {return false;}
			// if comment contains a flash object or embed refresh the page
			if (text.indexOf('<object') !== -1 || text.indexOf('<embed') !== -1){
				window.location.reload();
				return;
			}
			
			var thisOddEven;
			var comList = "ka_commentList";
			var userPhoto = Ka.Info.AUDIOPHOTOSERVERPATH + Ka.Info.USERPHOTO;
			if ($("ka_noComments")) {
				$j("#ka_noComments").remove();
				thisOddEven = "even";
			} else {
				var lastMessageOdd = $j("#" + comList + " > li:first")[0].className.indexOf("odd") !== -1;
				thisOddEven = (lastMessageOdd) ? "even" : "odd";
			}
			//Replaced with code follwing for internatiolization purpose
			//var toInsert = "<li class=\"" + thisOddEven + "\"><div class=\"ka_bubble\"><blockquote class=\"ka_contentBody\"><a href=\"/service/displayKickPlace.kickAction?u=" + Ka.Info.USERID + "&amp;as=" + Ka.Info.AFFILIATESITEID + "\"> <span style=\"background: rgb(0, 0, 0) url(" + userPhoto + ") no-repeat scroll center;\" class=\"ka_letterboxComment\"/></a><div class=\"ka_bubbleComment\">" + text + "</div></blockquote><cite><a class=\"ka_contributorName\" href=\"/service/displayKickPlace.kickAction?u=" + Ka.Info.USERID + "&amp;as=" + Ka.Info.AFFILIATESITEID + "\">" + Ka.Info.USERNAME + "</a>, <span class=\"ka_commentDate\">0 seconds ago</span> <span>| <span class=\"ka_flag ka_flag_comment\"><a onclick='javascript :ka_displayInappro(\"ka_inappropriateCommentDiv\"); ka_putCommentDetails(\"" + Ka.Info.USERNAME + "\",\"" + text + "\",\"" + Ka.Info.MEDIAID + "\"); ' href=\"JavaScript: ;\">Flag as Inappropriate</a></span></span></cite></div></li>";
			var uName = '<a class="ka_contributorName" href="/service/displayKickPlace.kickAction?u='+Ka.Info.USERID+'&amp;as='+Ka.Info.AFFILIATESITEID+'">'+Ka.Info.USERNAME+'</a>';
			var dateStamp = '<span class="ka_commentDate">'+Ka.Messages.Common.SECONDS.replace('($count)','0')+'</span>';
			var toInsert=
				'<li class="'
					+thisOddEven
					+'"><div class="ka_bubble"><blockquote class="ka_contentBody"><a href="/service/displayKickPlace.kickAction?u='
					+Ka.Info.USERID
					+'&amp;as='
					+Ka.Info.AFFILIATESITEID
					+'"> <span style="background: rgb(0, 0, 0) url('
					+userPhoto
					+') no-repeat scroll center;" class="ka_letterboxComment"/></a><div class="ka_bubbleComment">'
					+((Ka.Info.AUTOAPPROVALCOMMENTS=="false" && Ka.Info.AUTOAPPROVECONTENT != "T")?Ka.Messages.TinyMceEditor.COMMENTPENDINGAWAITINGAPPROVAL:text)
					+'</div></blockquote><cite>'
					+Ka.Messages.PlayPage.COMMENTADDEDON.replace('($userName)',uName).replace('($dateStamp)',dateStamp)
					//+' | <span class="ka_flag ka_flag_comment"><a onclick=\'javascript :ka_displayInappro("ka_inappropriateCommentDiv"); ka_putCommentDetails("'+Ka.Info.USERNAME+'","'+ Ka.String.addSlashDoubleQuote(text).replace(/'/g,"") +'"); \' href="JavaScript: ;">'+Ka.Messages.PlayPage.INAPPFLAG+'</a></span>'
					//+' | <span class="ka_flag ka_flag_comment ka_sprite_misc"><a href="#" onclick=\'ka_displayInappro("ka_inappropriateCommentDiv"); ka_putCommentDetails("'+Ka.Info.MEDIAID+'","'+Ka.Info.USERNAME+'",$j(this).parents(".ka_bubble").find(".ka_bubbleComment").text()); return false;\'>'+Ka.Messages.PlayPage.INAPPFLAG+'</a></span> '
					+'</cite></div></li>';
			$j("#ka_commentList").prepend($j(toInsert));
			$("text").value = "";
			if ($j("#ka_commentList li").length > 5) {
				$j("#ka_commentList li:gt(4)").remove();
				if ($j("#ka_shoutBoxViewAll").length === 0) {
					$j("<div id=\"ka_shoutBoxViewAll\"><a href=\"/service/displayShoutBox.kickAction?as=" + Ka.Info.AFFILIATESITEID + "&u=" + Ka.Info.USERID + "&mediaId=" + Ka.Info.MEDIAID + "&mediaType=" + Ka.Info.MEDIATYPE + "\">[ "+Ka.Messages.PlayPage.VIEWALLPP+" ]</a></div>").appendTo("#ka_shoutBoxContainer");
				}
				
			}
		} else {
			Ka.popup(Ka.Messages.Common.ajaxError);
			if (!Ka.events.dispatchEvent('play-page-after-add-comment', {success:  false})) {return false;}
		}
	});
	
	
}

// delete media item
function MKP_deleteObject(media, id) {
	
	if (!Ka.events.dispatchEvent('play-page-before-delete', {mediaType: media, mediaId: id})) {return false;}	
	Ka.confirm(Ka.Messages.PlayPage.DELETECONFIRMMESSAGE, function(){
		if (Ka.Info.MEDIATYPE == 'SET' && Ka.Info.ROLENAME == "WEBMASTER") {
			KickAppsBizComponent.deleteMediaSet(id, function(success){
				if(success == true) {
					alert("This set has been deleted.  It take a few minutes before these changes appear on " + Ka.Info.SITENAME);
					location.href = '/affiliate/displayHome.kickAction?WHOAMI=Affiliate&as=' + Ka.Info.AFFILAITESITEID;
				}
			}); 
		} else {
			location.href = "/update/" + media.toLowerCase() + "DeleteConfirm.kickAction?mediaType=" + media.toUpperCase() + "&mediaId=" + id;
		}
	});
	return false;
}

initClear = false;
function clearField(obj) {
	if (initClear === false) {
		obj.value = "";
		initClear = true;
	}
}

addCommentFlag = false;
function enableAddCommentButton() {
	if (Ka.Info.USERID === "") {
		Ka.popup("form#ka_loginPopup", function () {
			$("username").focus();
		});
	}
	if (!addCommentFlag) {
		addCommentFlag = true;
		var addCommentBtn = $("ka_sendButton");
		addCommentBtn.disabled = "";
		var shoutBoxInput = ka_findObj("text");
		shoutBoxInput.value = "";
	}
}
function addFavoriteMedia() {
	if (!Ka.events.dispatchEvent('play-page-before-add-favorite')) {return false;}
	KickAppsBizComponent.addFavoriteMedia(Ka.Info.USERID, Ka.Info.MEDIAID, Ka.Info.MEDIATYPE, Ka.Info.AFFILIATESITEID, function (flag) {
		if (flag === true) {
			$("favoriteArea").innerHTML = "<a href='javascript:removeFavoriteMedia();'>"+Ka.Messages.PlayPage.REMOVEFROMFAV+"</a>";
			(function(){if (!Ka.events.dispatchEvent('play-page-after-add-favorite', {success: flag})) {return false;}}());
		}
	});
}
function removeFavoriteMedia() {
	if (!Ka.events.dispatchEvent('play-page-before-remove-favorite')) {return false;}
	KickAppsBizComponent.deleteFavoriteMedia(Ka.Info.USERID, Ka.Info.MEDIAID, Ka.Info.MEDIATYPE, Ka.Info.AFFILIATESITEID, function (flag) {
		if (flag === true) {
			$("favoriteArea").innerHTML = "<a href='javascript:addFavoriteMedia();'>"+Ka.Messages.PlayPage.ADDTOFAV+"</a>";
			if (!Ka.events.dispatchEvent('play-page-after-remove-favorite', {success: flag})) {return false;}
		}
	});
}
var descMaxLimit;
if (Ka.Info.MEDIATYPE != "BLOG") {
	descMaxLimit = 100;
} else {
	if (Ka.Info.PATHTOMEDIA !== "") {
		descMaxLimit = 1500;
	} else {
		descMaxLimit = 2000;
	}
}
function ka_replaceText(id, text) {
	obj = ka_findObj(id);
	obj.innerHTML = text;
}
function initUrlInput() {
	obj = ka_findObj("ka_playerTools_URL");
	obj.value = window.location.href;
}


function ka_putCommentDetails(commentId,commentUserName, commentText){
	$('commentId').value = commentId;
	$('commentUserName').value = commentUserName;
	$('commentText').value = commentText;
	
	ka_LastCommentFlagged = commentId;
}

//reccomended list
function toggleRecommnededList(link){
	if (!Ka.events.dispatchEvent('play-page-before-display-related-media', {listElement: $j(link).parent()})) {return false;}
	var thisTabPage=link.id.substr(0,link.id.length-6);
	
	//if this is an ajax link
	if(link!==$('ka_playerVideoList_mostRelated_title')){
	
		//if ajax hasn't been called yet
		if($j('#ka_playerVideoList_newMedia > div').html()===''){
			if (!Ka.events.dispatchEvent('play-page-before-load-related-media')) {return false;}
			//add preloader image
			$j('#ka_playerVideoList_newMedia > div,#ka_playerVideoList_mostRated > div,#ka_playerVideoList_mostPopular > div').html('<image alt="loading..." src="'+Ka.Info.AUDIOPHOTOSERVERPATH+'/loading-barber.gif" style="display:block; margin:0 auto;" />');
			
			//get tab contents via ajax
			KickAppsBizComponent.getAllRelatedMediaForPlayPage(Ka.Info.AFFILIATESITEID,Ka.Info.MEDIATYPE,Ka.Info.MEDIAID,function(a){
			    $j('#ka_playerVideoList_newMedia > div,#ka_playerVideoList_mostRated > div,#ka_playerVideoList_mostPopular > div').html('<div class="ka_playerMediaList_table"><ul id="ka_relatedList"></ul></div>');
			    $j.each(a.NEWMEDIALIST,function(i,n){
			     	var kpHref='/service/displayKickPlace.kickAction?u='+n.userId+'&as='+Ka.Info.AFFILIATESITEID+'&b=';
			     	var uploadedByNEWMEDIALIST = "";
			       	if(n.isDisabled === 'true'){
			    		uploadedByNEWMEDIALIST = Ka.Messages.InappFlag.BYAFORMERMEMBER;
			    	}
			    	else{
			    		uploadedByNEWMEDIALIST = Ka.Messages.PlayPage.LATESTBY.replace('($kpHref)',kpHref).replace('($userName)',n.uploadedBy);
			    	}
			       	$j('#ka_playerVideoList_newMedia > div > div > ul').append('<li><a title="'+n['name']+'" href="/_'+n['name'].replace(' ','_')+'/'+n.entityType.toLowerCase()+'/'+n.id+'/'+Ka.Info.AFFILIATESITEID+'.html?b="><span style="background: rgb(0, 0, 0) url('+Ka.Info.AUDIOPHOTOSERVERPATH+n.pathToPreview100X75+') no-repeat scroll center;" id="ka_letterboxRelated"></span></a><div class="ka_thumbdetails"><a title="'+n['name']+'" href="/_'+n['name'].replace(' ','_')+'/'+n.entityType.toLowerCase()+'/'+n.id+'/'+Ka.Info.AFFILIATESITEID+'.html?b=">'+Ka.Util.wbr(n.name,7)+'</a><br />'+uploadedByNEWMEDIALIST+'<br/>'+n.formattedDate+'</div></li>');
			    });
				
			    $j.each(a.MOSTRATEDLIST,function(i,n){
			    	var kpHrefRated='/service/displayKickPlace.kickAction?u='+n.userId+'&as='+Ka.Info.AFFILIATESITEID+'&b=';
			    	var uploadedByMOSTRATEDLIST = "";
					if(n.isDisabled === 'true'){
			    		uploadedByMOSTRATEDLIST = Ka.Messages.InappFlag.BYAFORMERMEMBER;
			    	}
			    	else{
			    		uploadedByMOSTRATEDLIST = Ka.Messages.PlayPage.LATESTBY.replace('($kpHref)',kpHrefRated).replace('($userName)',n.uploadedBy);
			    	}
			    
			    	$j('#ka_playerVideoList_mostRated > div > div > ul').append('<li><a title="'+n['name']+'" href="/_'+n['name'].replace(' ','_')+'/'+n.entityType.toLowerCase()+'/'+n.id+'/'+Ka.Info.AFFILIATESITEID+'.html?b="><span style="background: rgb(0, 0, 0) url('+Ka.Info.AUDIOPHOTOSERVERPATH+n.pathToPreview100X75+') no-repeat scroll center;" id="ka_letterboxRelated"></span></a><div class="ka_thumbdetails"><a title="'+n['name']+'" href="/_'+n['name'].replace(' ','_')+'/'+n.entityType.toLowerCase()+'/'+n.id+'/'+Ka.Info.AFFILIATESITEID+'.html?b=">'+Ka.Util.wbr(n.name,7)+'</a><br />'+uploadedByMOSTRATEDLIST+'<br/>'+Ka.Messages.PlayPage.MEDIASTARS.replace('($count)',n.averageRating)+'</div></li>');	
			    	//$j('#ka_playerVideoList_mostRated > div > div > ul').append('<li><a title="'+n[2]+'" href="/kickapps/'+n[2].replace(' ','_')+'/'+n[3].toLowerCase()+'/'+n[0]+'/'+Ka.Info.AFFILIATESITEID+'.html?b="><span style="background: rgb(0, 0, 0) url('+Ka.Info.AUDIOPHOTOSERVERPATH+'/'+(n[7].replace('.jpg','_100X75.jpg'))+') no-repeat scroll center;" id="ka_letterboxRelated"></span></a><div class="ka_thumbdetails"><a href="/kickapps/'+n[2].replace(' ','_')+'/'+n[3].toLowerCase()+'/'+n[0]+'/'+Ka.Info.AFFILIATESITEID+'.html?b=">'+n[2]+'</a><br />By <a href="/service/displayKickPlace.kickAction?u='+n[1]+'&as='+Ka.Info.AFFILIATESITEID+'&b=">'+n[11]+'</a><br/>'+n[4]+' stars</div></li>');			    	
			    });
				
			    $j.each(a.MOSTPOPULARLIST,function(i,n){
			    	var kpHrefPop='/service/displayKickPlace.kickAction?u='+n.userId+'&as='+Ka.Info.AFFILIATESITEID+'&b=';
			    	var uploadedByMOSTPOPULARLIST = "";
					if(n.isDisabled === 'true'){
					    uploadedByMOSTPOPULARLIST = Ka.Messages.InappFlag.BYAFORMERMEMBER;
			    	}
			    	else{
			    		uploadedByMOSTPOPULARLIST = Ka.Messages.PlayPage.LATESTBY.replace('($kpHref)',kpHrefPop).replace('($userName)',n.uploadedBy);
			    	}
			    	$j('#ka_playerVideoList_mostPopular > div > div > ul').append('<li><a title="'+n['name']+'" href="/_'+n['name'].replace(' ','_')+'/'+n.entityType.toLowerCase()+'/'+n.id+'/'+Ka.Info.AFFILIATESITEID+'.html?b="><span style="background: rgb(0, 0, 0) url('+Ka.Info.AUDIOPHOTOSERVERPATH+n.pathToPreview100X75+') no-repeat scroll center;" id="ka_letterboxRelated"></span></a><div class="ka_thumbdetails"><a title="'+n['name']+'" href="/_'+n['name'].replace(' ','_')+'/'+n.entityType.toLowerCase()+'/'+n.id+'/'+Ka.Info.AFFILIATESITEID+'.html?b=">'+Ka.Util.wbr(n.name,7)+'</a><br />'+uploadedByMOSTPOPULARLIST+'<br/>'+Ka.Messages.PlayPage.MEDIAVIEWS.replace('($count)',n.views)+'</div></li>');			
			    	//$j('#ka_playerVideoList_mostPopular > div > div > ul').append('<li><a title="'+n[2]+'" href="/kickapps/'+n[2].replace(' ','_')+'/'+n[3].toLowerCase()+'/'+n[0]+'/'+Ka.Info.AFFILIATESITEID+'.html?b="><span style="background: rgb(0, 0, 0) url('+Ka.Info.AUDIOPHOTOSERVERPATH+'/'+(n[7].replace('.jpg','_100X75.jpg'))+') no-repeat scroll center;" id="ka_letterboxRelated"></span></a><div class="ka_thumbdetails"><a href="/kickapps/'+n[2].replace(' ','_')+'/'+n[3].toLowerCase()+'/'+n[0]+'/'+Ka.Info.AFFILIATESITEID+'.html?b=">'+n[2]+'</a><br />By <a href="/service/displayKickPlace.kickAction?u='+n[1]+'&as='+Ka.Info.AFFILIATESITEID+'&b=">'+n[11]+'</a><br/>'+n[8]+' views</div></li>');			
			    });		
			    
			    if (!Ka.events.dispatchEvent('play-page-after-load-related-media')) {return false;}
			});
		}
	}

	//adjust tab pages
	$j('#ka_relatedWrap div.ka_related').hide();
	$j('#'+thisTabPage).show();
	
	//adjust tabs
	$j('#ka_relatedTabs > li > a')
		.css({
			'textDecoration':'underline'
		})
		.removeClass('active');
	
	$j(link)
		.css({
			'textDecoration':'none',
			'className':'active'
		})
		.addClass('active');
	if (!Ka.events.dispatchEvent('play-page-after-display-related-media')) {return false;}
}


function inappropriateMediaflagged(inappropriateflag) {
	if (inappropriateflag === true || Ka.Info.USERID === '') {
		obj = ka_findObj("flagArea");
		if (obj) {
			var flagText =  Ka.Messages.PlayPage.AFTERFLAGGING;
			obj.innerHTML = flagText;
		}
		obj1 = ka_findObj("ka_flagSuccess");
		if (obj1) {
			obj1.innerHTML = Ka.Messages.PlayPage.MEDIAFLAGGINGTHANKSFORHELP.replace('($siteName)',Ka.Info.SITENAME).replace('($siteName)',Ka.Info.SITENAME);
			obj1.style.display = "";
		}
	}
}
function flagInappropriateMedia() {
	KickAppsBizComponent.inAppropriateFlaggingConfirm(Ka.Info.IP, DWRUtil.getValue("flagMsg"), Ka.Info.B, Ka.Info.MEDIANAME, Ka.Info.AFFILIATESITEID, Ka.Info.USERID, Ka.Info.USERID, Ka.Info.MEDIAID, Ka.Info.MEDIATYPE, Ka.Info.MEDIATYPE, inappropriateMediaflagged);
}
// called when a comment is flagged
var ka_LastCommentFlagged;
function inappropriateCommentflagged(bool) {
	if (bool){
		$j('#ka_commentItem_' + ka_LastCommentFlagged).find('.ka_flag_comment').empty().html(Ka.Messages.InappFlag.PLAYPAGECOMMENTSFLAGGED).addClass('ka_flagged').removeClass('ka_flag');
	}
}

function inAppropriateCommentFlaggingConfirm(thisLink) {
	KickAppsBizComponent.inAppropriateCommentFlaggingConfirm(DWRUtil.getValue("commentUserName"), DWRUtil.getValue("commentText"), DWRUtil.getValue("commentFlagMsg"), DWRUtil.getValue("CommentInappropate_B"), Ka.Info.MEDIANAME, DWRUtil.getValue("AffiliateSiteId_CommentInappropate"), DWRUtil.getValue("UserID_CommentInappropate"), Ka.Info.MEDIAID, Ka.Info.MEDIATYPE,DWRUtil.getValue("commentId"),Ka.Info.IP,  inappropriateCommentflagged);
	var commentFlagId = $('commentId').value;
	$j('#ka_commentItem_' + commentFlagId).find('.ka_flag_comment').empty().html(Ka.Messages.InappFlag.PLAYPAGECOMMENTSFLAGGED).addClass('ka_flagged').removeClass('ka_flag');
}
var displayInappro = false;

var onTOS;
var curId = "none";
function ka_toogleInappro(id, display) {
	ka_positionCenter(id);
	obj = ka_findObj(id);
	obj.style.display = display;
}
function ka_displayInappro(id) {
	toggleFlashVideoOff();
	curId = id;
	ka_toogleInappro(id, "block");
	if (displayInappro === false) {
		ka_shadeOn();
	} else {
	}
	displayInappro = true;
}
function ka_updateInappro() {
	if (displayInappro) {
		if (curId == "ka_inappropriateDiv") {
			ka_displayInappro("ka_inappropriateDiv");
		} else {
			ka_displayInappro("ka_inappropriateCommentDiv");
		}
	}
}
ka_addEvent(window, "resize", ka_updateInappro);
ka_addEvent(window, "scroll", ka_updateInappro);

function ka_hideInappro(id) {
    // if site styler isn't open
    if(!$('ka_le') || ($('ka_le') && Ka.LE.$('ka_le').style.display!=='block')) {
	    toggleFlashVideoOn();
	}
	displayInappro = false;
	ka_toogleInappro(id, "none");
	ka_shadeOff();
}
