jQuery.noConflict();
		
function bindHistoryClick()
{
	// set onlick event for buttons		
	jQuery("a[rel='history']").click(function(){
		// 
		var hash = this.href;
		hash = hash.replace(/^.*#/, '');		
		// moves to a new page. 
		// pageload is called at once. 
		jQuery.historyLoad(hash);
		window.scrollTo(0,0);
		return false;
	});
}

function pageload(hash)
{
	
	if(freshPageLoaded == false)
		if(hash == '') return false;
		
	if(hash == '' || hash == 'public' || hash == 'popdby' || hash == 'mainContent' )
	{
		var size = '';
		if(playerSize == 'wide')
			size = '&size=widescreen';
		geo = '&geo='+geoLocation;
		inter = '&inter='+interst;
		var pageName = AJAX_PATH+'makerequest.php';
		var parameters = 'pname=video_detail_related&action=relatedVideoDetail&oldCvid='+curViden+size+geo+inter;
	}
	else
	{
		var pageName = AJAX_PATH+'makerequest.php';
		var parameters = 'pname=video_detail_related&action=relatedVideoDetail&hashvid='+hash+'&oldCvid='+curViden;
	}
	jQuery.ajax({
		type: "POST",
		url: pageName,
		data: parameters,
		success: function(msg)
		{	
			jQuery('#newVideoDetail').animate({'opacity':'1'});
			freshPageLoaded = false;
			jQuery('#newVideoDetail').html(msg);
			if(hash == 'public')
			{
				var timeInt = setInterval(
										  function(){
												clearInterval(timeInt);
												showComments('public',curVid);
												scrollToId('commentsSortby');
										  },100);
			}
			else if(hash == 'popdby')
			{
				var timeInt = setInterval(
										  function(){
												clearInterval(timeInt);
												showMainCommentsPopd('popd_by');
												scrollToId('commentsSortby');
										  },100);
			}
			FB.XFBML.parse();
		},
		beforeSend:function()
		{
			jQuery('#newVideoDetail').animate({'opacity':'0.2'});
			jQuery("#related-videos ul li a").unbind('click');
		}
	});
}


function goToPage(cvid,vtitle,oldCvid,slideId)
{
	if(jQuery('#refreshListStatus').attr('checked')==false)
	{
		var oldVid= '';		
		window.location=POP_HOME+videoType+'/'+cvid+'/'+vtitle;
	}
	else
	{
		if(jQuery.browser.safari || jQuery.browser.msie)
		{
			pageload('rel/'+cvid+'/'+slideId);
		}
		else
		{
			window.location='#rel/'+cvid+'/'+slideId;
		}
	}
	
}



jQuery(document).ready(function(){
	//jQuery('#mainPageContainerContent').show();
	/*window.scrollTo(166,166);*/
	jQuery.historyInit(pageload);
	bindHistoryClick();		
	
	commentScroll();
	
			
	jQuery('#postNewComment p p').hide();
	
	/* SORTING DIV */
	jQuery('#playlistSortBtn').mouseover(function()
	{
		jQuery('#playlistSortBtn').removeClass('sortbybtn');
		jQuery('#playlistSortBtn').addClass('sortbybtnhover');
	});
	
	jQuery('#playlistSortBtn').mouseout(function()
	{
		if(jQuery('#playlistSortBox').css('display')=='none')
		{
			jQuery('#playlistSortBtn').removeClass('sortbybtnhover');
			jQuery('#playlistSortBtn').addClass('sortbybtn');
		}
	});
			
	/*CLOSE SORTING BOX WHEN CLICK ANYWHERE IN BODY */

	jQuery(document).click(function(event)
	{						
		//alert('X:'+event.pageX+' Y:'+event.pageY);
		if( document.getElementById('playlistProcess').style.display == 'block'){
			if(	jQuery(event.target).attr("class") != 'top-arrow' && 
				event.target.id != 'playlistProcess' && 
				event.target.id != 'yes_playlist' && 
				event.target.tagName != 'SELECT' && 
				event.target.tagName != 'OPTION' && 
				jQuery(event.target).attr("class") != 'log_in_acton-add-playlist' && 
				jQuery(event.target).attr("class") != 'playlist-category' &&  
				jQuery(event.target).attr("class") != 'button-add-to-playlist' && 
				jQuery(event.target).attr("class") != 'create-playlist' && 
				event.target.id != 'title' && 
				event.target.id != 'description' && 
				jQuery(event.target).attr("class") != 'tabs' && 
				jQuery(event.target).attr("class") != 'selected' && 
				jQuery(event.target).attr("class") != 'shaded-wrapper' && 
				event.target.id != 'pl_create_playlist_video' && 
				event.target.id != 'pl_link')
			{
				jQuery('#playlistProcess').css({'display':'none'});
			}
			/*else if(jQuery(event.target).attr("class") != 'top-arrow' && event.target.id != 'playlistProcess_widescreen' && event.target.id != 'yes_playlist' && event.target.tagName != 'SELECT' && event.target.tagName != 'OPTION' && jQuery(event.target).attr("class") != 'log_in_acton-add-playlist' && jQuery(event.target).attr("class") != 'playlist-category' &&  jQuery(event.target).attr("class") != 'button-add-to-playlist' && event.target.tagName != 'SPAN')
			{
				
			}*/
			else
			{
				jQuery('#playlistProcess').css({'display':'block'});
			}
			/*if(jQuery(event.target).attr('class') == 'log_in_acton-add-playlist' || jQuery(event.target).attr('id') == 'playlistProcess' || jQuery(event.target).attr('id') == 'yes_playlist' || jQuery(event.target).attr('id') == 'yes_playlist' || jQuery(event.target).attr('name') == 'select_playlist' || jQuery(event.target).attr('class') == 'button-add-to-playlist' || jQuery(event.target).attr('id') == 'already_in' || jQuery(event.target).attr('id').match('pl_') == 'pl_')
			{
				jQuery('#playlistProcess').css({'display':'block'});
			}
			else
			{
				jQuery('#playlistProcess').css({'display':'none'});
			}
			*/
	
		}	
			if(jQuery('#playlistSortBox').css('display')=='none')
			{
				varToggle = true;
			}
			jQuery('#playlistSortBox').hide();
		
	});
	
	/*END OF SORTING */


	jQuery('.clearfix p a.create-playlist').live('click',function(){
		video_id_arr = jQuery(this).attr('id').split('_');
		video_id = video_id_arr[2];
		addvideotoplaylist = video_id;
		showCreatePlaylist();
	});	
	
	
	jQuery('.add-playlist-popup a.button-add-to-playlist').live('click',function(){	
		video_id_arr = jQuery(this).attr('id').split("_");
		video_id = video_id_arr[2];
		add_to_playlist(video_id,jQuery('#modalbox_pl_'+video_id).val());
		return false;
	});
	
	jQuery('.add-playlist-popup p a.playlist-category').live('click',function(){																		   
		video_id_arr = jQuery(this).parent().parent().attr('id').split("_");
		video_id = video_id_arr[2];
		//alert(video_id);
		list_id_arr = jQuery(this).attr('id').split("_");
		list_id = list_id_arr[1];
		//alert(list_id);
		remove_from_playlist(video_id,list_id);
	});
	
	

								
});


/*	FUNCTION TO POP-IT VIDEO	*/
function makePopIt(videoId,userId,fb_publish,tw_publish)
{	
	/*	SET PARAMETER THAT WILL BE SENT TO AJAX	*/	
	//var pageName = AJAX_PATH+'makerequest.php';
	//var parameters = 'pname=video_detail&action=popit&value='+escape(videoId)+'';
	var resultDiv = 'divPopit';	
	jQuery('#makePopit_pop').fadeOut();
	/*	MAKE AJAX CALL */
/*	jQuery.ajax({
		   type: "POST",
		   url: pageName,
		   data: parameters,
		  // beforeSend: function(){jQuery("#"+resultDiv).html('<img align="absbottom" src="'+IMAGE_PATH+'global/loaders/spinner18x18.gif" />');},
		   success: function(msg){*/
		var requestURL=AJAX_PATH+'makerequest.php?pname=video_detail&action=popit&value='+escape(videoId)+'&fb_publish='+fb_publish+'&tw_publish='+tw_publish+'&i=?';  
		   jQuery.getJSON(requestURL,
		function(msg){
			setTimeout(function(){
									jQuery('#'+resultDiv).fadeIn();
									jQuery("#"+resultDiv).html(msg['success']);
									if(msg['source']=='Justin.tv' || msg['source']=='uStream')
									{
										jQuery('#divPopit_enable_chat').fadeIn();
										jQuery('#divPopit_enable_chat').html(msg['success']);
									}
									else
									{
										jQuery('#divPopit_widescreen').fadeIn();
										jQuery('#divPopit_widescreen').html(msg['success']);
									}
								 },
								 600);
								if(msg['source']=='Justin.tv' || msg['sourde']=='uStream')
								{
								document.getElementById('stared').innerHTML="";											
								document.getElementById('stared').innerHTML="<li id='star-this'><a class='log_in_acton-star-this' href='javascript:;' onClick='libraryStarThis(\""+videoId+"\",\"1\")'>Star this</a></li><li id='add_playlist_standard'><a class='log_in_acton-add-playlist' onclick='addPlaylistProcess(\"standard\")' href='javascript:;'>Add to playlist</a></li><li><a class='action-enable_chat' href='javascript:;' onclick='update_embedChat(\""+userId+"\",\"enable\")'>Enable chat</a></li>";
								
								jQuery('#stared_widescreen').html('');
								jQuery('#stared_widescreen').html('<li id="star-this_widescreen"><a class="log_in_acton-star-this" href="javascript:;" onclick="libraryStarThis(\''+videoId+'\',\'1\')">Star this</a></li><li id="add_playlist_widescreen"><a class="log_in_acton-add-playlist" onclick="addPlaylistProcess(\'widescreen\')" href="javascript:;">Add to playlist</a></li><li><a class="action-disable_chat" href="javascript:;" onclick="update_embedChat('+userId+',\'disable\')">Disable chat</a></li>');
								}
								else
								{
								document.getElementById('stared').innerHTML="";											
								document.getElementById('stared').innerHTML="<li id='star-this'><a class='log_in_acton-star-this' href='javascript:;' onClick='libraryStarThis(\""+videoId+"\",\"1\")'>Star this</a></li><li id='add_playlist_standard'><a class='log_in_acton-add-playlist' onclick='addPlaylistProcess(\"standard\")' href='javascript:;'>Add to playlist</a></li><li><a class='action-widescreen' href='javascript:;' onclick='update_size_popplayer(\""+userId+"\",\"widescreen\")'>WideScreen</a></li>";
								
								jQuery('#stared_widescreen').html('');
								jQuery('#stared_widescreen').html('<li id="star-this_widescreen"><a class="log_in_acton-star-this" href="javascript:;" onclick="libraryStarThis(\''+videoId+'\',\'1\')">Star this</a></li><li id="add_playlist_widescreen"><a class="log_in_acton-add-playlist" onclick="addPlaylistProcess(\'widescreen\')" href="javascript:;">Add to playlist</a></li><li><a class="action-widescreen4-3" href="javascript:;" onclick="update_size_popplayer(\''+userId+'\',\'standard\')">Standard</a></li>');
								}
		   });	
}

function requestSubComments(pageName,parameters,resultDiv){
	jQuery.ajax({
	   type: "POST",
	   url: pageName,
	   data: parameters,
	   beforeSend: function(){jQuery("#"+resultDiv).html('<img align="absbottom" src="'+IMAGE_PATH+'global/loaders/loader_blue.gif" />');},
	   success: function(msg){		   
	   jQuery("#"+resultDiv).html(msg);
	   },
		error: function(){ //so, if data is retrieved, store it in html 
			//jQuery("#"+resultDiv).html('Error Loading Script'); //show the html inside .content div 
		}
	 });

}
	
	
function requestComments(pageName,parameters,resultDiv){
	
	jQuery.ajax({
	   type: "POST",
	   url: pageName,
	   data: parameters,
	   beforeSend: function(){jQuery("#"+resultDiv).html('<center><img align="absbottom" src="'+IMAGE_PATH+'global/loaders/loader_blue.gif" /></center>');
	   jQuery('a[href*=#]').unbind('click');
	   },
	   success: function(msg){		   			
			jQuery("#"+resultDiv).html(msg);
			commentScroll();
		},
		error: function(){ //so, if data is retrieved, store it in html 
			//jQuery("#"+resultDiv).html('Error Loading Script'); //show the html inside .content div 
		}
	 });
}

function requestAddNewComment(pageName,parameters,resultDiv){
	
	jQuery.ajax({
	   type: "POST",
	   url: pageName,
	   data: parameters,
	   beforeSend: function(){jQuery("#"+resultDiv).html('<center><img align="absbottom" src="'+IMAGE_PATH+'global/loaders/loader_blue.gif" /></center>');},
	   success: function(msg){		   
	   jQuery("#"+resultDiv).html(msg);
	   },
		error: function(){ //so, if data is retrieved, store it in html 
			//jQuery("#"+resultDiv).html('Error Loading Script'); //show the html inside .content div 
		}
	 });

}



/*	FUNCTION TO SHOW SUB COMMENTS	*/
function showCommentReplies(replyId)
{
	var subContentId = "replyCommentsContent_"+replyId;
	var linkId = "showReply_"+replyId;
	
	if(jQuery("#"+subContentId).css("display") == "none")
	{
		/*	CHANGE THE ARROW CLASS	*/
		jQuery("#"+linkId).removeClass("closerely");
		jQuery("#"+linkId).addClass("openreply");
		/*	DISPLAY SUB COMMENTS DIV	*/
		jQuery("#"+subContentId).show();
	}
	else
	{
		/*	CHANGE THE ARROW CLASS	*/
		jQuery("#"+linkId).removeClass("openreply");
		jQuery("#"+linkId).addClass("closerely");		
		
		/*	DISPLAY SUB COMMENTS DIV	*/
		jQuery("#"+subContentId).hide();
	}
}

/*	FUNCTION TO SHOW SUB-CHILD COMMENTS	*/
function showSubCommentReplies(replyId)
{
	var subContentId = "replyResponceContentLevelTwo_"+replyId;
	var linkId = "showReplyChild_"+replyId;
	
	if(jQuery("#"+subContentId).css("display") == "none")
	{
		/*	CHANGE THE ARROW CLASS	*/
		jQuery("#"+linkId).removeClass("closerely");
		jQuery("#"+linkId).addClass("openreply");
		/*	DISPLAY SUB COMMENTS DIV	*/
		jQuery("#"+subContentId).show();
		
		/*	CALL AJAX AND SHOW SUB COMMENTS	*/
		requestSubComments(AJAX_PATH+'makerequest.php','pname=video_detail_comments&action=show_replies&cid='+escape(replyId)+'',subContentId);
	}
	else
	{
		/*	CHANGE THE ARROW CLASS	*/
		jQuery("#"+linkId).removeClass("openreply");
		jQuery("#"+linkId).addClass("closerely");
		
		/*	DISPLAY SUB COMMENTS DIV	*/
		jQuery("#"+subContentId).hide();
	}	
	
}
/*	FUNCTION TO SHOW COMMENTS WHEN USER CLICKS ON PARTICULAR SECTION	*/
function showComments(commSection,videoId,pageName)
{ 
	var mainCommentSectionId = 'comments';
	
	
	/*	GET SELECTED SORT OPTION, FROM HIDDEN FIELD	*/
	var sortByOption = jQuery("input#sortByOption").val();
	
	//jQuery('#'+mainCommentSectionId).html();	
	
	/*	REMOVE SELECTED CLASS FROM REST	*/
	
	jQuery("#publiccommentsSelected").attr({'id':'publiccomments'});
	jQuery("#friendpostsSelected").attr({'id':'friendposts'});
	jQuery("#userpostsSelected").attr({'id':'userposts'});
	
	jQuery("#privatecommentsSelected").attr({'id':'privatecomments'});
	jQuery("#directedcommentSelected").attr({'id':'directedcomment'});
	
	/*jQuery("#friendposts").removeClass("selected");
		
	jQuery("#userposts").removeClass("selected");
		
	jQuery("#privatecomments").removeClass("selected");
		
	jQuery("#directedcomment").removeClass("selected");
	*/	
	if(commSection == 'public')
	{
		/*	ADD CLASS TO BE SELECTED	*/
		jQuery("#publiccomments").attr({'id':'publiccommentsSelected'});
		
		/*	DISPLAY PUBLIC ADD NEW COMMENT BOX	*/
		jQuery("#addNewCommentPrivate").hide();
		jQuery("#addNewCommentPublic").show();
		
		/*	SET THE SELECTED COMMENTS SECTIION HIDDEN FIELD VALUE , THAT WILL B USED TO GET COMMENTS	*/
		document.getElementById('commentsCurrentSection').value = 'public';
	}
	else if(commSection == 'friends')
	{
		/*	ADD CLASS TO BE SELECTED	*/
		jQuery("#friendposts").attr({'id':'friendpostsSelected'});
		
		/*	DISPLAY PUBLIC ADD NEW COMMENT BOX	*/
		jQuery("#addNewCommentPrivate").hide();
		jQuery("#addNewCommentPublic").show();
		
		/*	SET THE SELECTED COMMENTS SECTIION HIDDEN FIELD VALUE , THAT WILL B USED TO GET COMMENTS	*/
		document.getElementById('commentsCurrentSection').value = 'friends';
	}
	else if(commSection == 'post_by_u')
	{ 
		/*	ADD CLASS TO BE SELECTED	*/
		jQuery("#userposts").attr({'id':'userpostsSelected'});
		
		/*	DISPLAY PUBLIC ADD NEW COMMENT BOX	*/
		jQuery("#addNewCommentPrivate").hide();
		jQuery("#addNewCommentPublic").show();
		
		/*	SET THE SELECTED COMMENTS SECTIION HIDDEN FIELD VALUE , THAT WILL B USED TO GET COMMENTS	*/
		document.getElementById('commentsCurrentSection').value = 'post_by_u';
	}
	/*else if(commSection == 'private')
	{
		/*	ADD CLASS TO BE SELECTED	*/
		//jQuery("#privatecomments").attr({'id':'privatecommentsSelected'});
		
		/*	DISPLAY PRIVATE ADD NEW COMMENT BOX	*/
		//jQuery("#addNewCommentPublic").hide();
		//jQuery("#addNewCommentPrivate").show();
		
		/*	SET THE SELECTED COMMENTS SECTIION HIDDEN FIELD VALUE , THAT WILL B USED TO GET COMMENTS	*/
		//document.getElementById('commentsCurrentSection').value = 'private';
	//}
	else if(commSection == 'direct_to_u')
	{
		/*	ADD CLASS TO BE SELECTED	*/
		jQuery("#directedcomment").attr({'id':'directedcommentSelected'});
		
		/*	DISPLAY PRIVATE ADD NEW COMMENT BOX	*/
		jQuery("#addNewCommentPublic").hide();
		jQuery("#addNewCommentPrivate").show();
		
		/*	SET THE SELECTED COMMENTS SECTIION HIDDEN FIELD VALUE , THAT WILL B USED TO GET COMMENTS	*/
		document.getElementById('commentsCurrentSection').value = 'direct_to_u';
	}
	//alert(commSection);
	/*	CALL AJAX AND SHOW SELECTED COMMENTS	*/
	
	if(pageName=='video_detail'){
	requestComments(AJAX_PATH+'makerequest.php','pname=video_detail_comments&action=show_comments&section='+escape(commSection)+'&vid='+escape(videoId)+'&sort_by='+escape(sortByOption)+'',mainCommentSectionId);
	}
	else
	{
		requestComments(AJAX_PATH+'makerequest.php','pname=video_detail_comments&action=show_comments&section='+escape(commSection)+'&vid='+escape(videoId)+'&sort_by='+escape(sortByOption)+'',mainCommentSectionId);
	}

}

/*	FUNCTION TO ADD NEW COMMENT	*/
function addNewComment(status,videoId,type,frm_id)
{
	
	/*	GENERATE UNIQUE ID	*/
	var dateObject = new Date();
	var newDivId = dateObject.getTime();
	
	jQuery("#addNewCommentContent").append('<div id="'+newDivId+'"></div>');
			
	if(status == 'public')
	{
		/*	DISABLE PUBLIC NEW COMMENT BUTTON	*/
		var btnNewCommId = 'btpublicPostComment';
				
		/*	GET COMMENT TEXT ENTERED	*/
		var commentText = jQuery("#publicCommentText").val();
		
		/*	EMPTY TEXT AREA VALUE	*/
		jQuery("#publicCommentText").val('');
		/*	DISABLE BUTTON AFTER, NEW COMMENT IS POSTED	*/
		jQuery('#'+btnNewCommId).addClass("transparent_class");
		jQuery('#'+btnNewCommId).removeClass("button-black_green_whitebg");
		jQuery('#'+btnNewCommId).attr({'onClick':''});
		jQuery("#"+frm_id).attr({"onSubmit":""});
	}
	else
	{
		/*	DISABLE PRIVATE NEW COMMENT BUTTON	*/
		var btnNewCommId = 'btprivatePostComment';
		jQuery("#"+btnNewCommId).attr({"disabled":"disabled"});
		
		/*	GET COMMENT TEXT ENTERED	*/
		var commentText = jQuery("#privateCommentText").val();
		
		/*	EMPTY TEXT AREA VALUE	*/
		jQuery("#privateCommentText").val('');
		
		/*	DISABLE BUTTON AFTER, NEW COMMENT IS POSTED	*/
		jQuery('#'+btnNewCommId).addClass("transparent_class");
		jQuery('#'+btnNewCommId).removeClass("button-black_green_whitebg");
		jQuery('#'+btnNewCommId).attr({'onClick':''});
		jQuery("#"+frm_id).attr({"onSubmit":""});
	}

	if(commentText != '')
	{
		jQuery("#publicCommentText").css({'height':'86px'});
		/*	IF THERE ARE NO COMMENTS RECORDS THEN  REMOVE THAT MESSAGE	*/
		if(jQuery("#noRecordFound"))
		{
			jQuery("#noRecordFound").hide();
		}
		
		
		/*	SET PARAMETER THAT WILL BE SENT TO AJAX	*/	
		var pageName = AJAX_PATH+'makerequest.php';
		var parameters = 'pname=video_detail_comments&action=add_new_comment&status='+escape(status)+'&vid='+escape(videoId)+'&comment='+commentText+'&ctype='+type+'';
		
		var resultDiv = newDivId;
		
		/*	MAKE AJAX CALL TO POST NEW COMMENT	*/
		jQuery.ajax({
		   type: "POST",
		   url: pageName,
		   data: parameters,
		   beforeSend: function(){jQuery("#"+resultDiv).html('<center><img align="absbottom" src="'+IMAGE_PATH+'global/loaders/loader_blue.gif" /></center>');},
		   success: function(msg){
			   jQuery("#"+resultDiv).html(msg);
			   /*	ENABLE ADD NEW COMMENT  BUTTON	*/			   
			   //jQuery("#"+btnNewCommId).attr({"disabled":"disabled"});
			   
			   /*	DISABLE BUTTON AFTER, NEW COMMENT IS POSTED	*/
				jQuery('#'+btnNewCommId).addClass("transparent_class");
				jQuery('#'+btnNewCommId).removeClass("button-black_green_whitebg");
				jQuery('#'+btnNewCommId).attr({"onClick":""});
				jQuery("#"+frm_id).attr({"onSubmit":""});
				jQuery('#postNewComment h').show();
				jQuery('#postNewComment p p').hide();
		   },
			error: function(){
				//jQuery("#"+resultDiv).html('Error Loading Script');
				/*	ENABLE ADD NEW COMMENT  BUTTON	*/
				jQuery("#"+btnNewCommId).attr({"disabled":""});
				
				/*	DISABLE BUTTON AFTER, NEW COMMENT IS POSTED	*/
				jQuery('#'+btnNewCommId).addClass("transparent_class");
				
			}
		 });
	}
	else
	{		
		/*	ENABLE ADD NEW COMMENT  BUTTON	*/
		jQuery("#"+btnNewCommId).attr({"disabled":"disabled"});
		
		/*	DISABLE BUTTON AFTER, NEW COMMENT IS POSTED	*/
		jQuery('#'+btnNewCommId).addClass("transparent_class");
		jQuery('#'+btnNewCommId).attr({'onClick':''});
	}
	return false;
}
/*	FUNCTION TO SHOW HIDE REPLY BOX, FOR LEVEL 1-2	*/
function showReplyBox(level,cmid)
{
	if(level == 'one')
	{
		var subContentId = "replyBoxLevelOne_"+cmid;
		var linkId = "linkReplyLevelOne_"+cmid;
		 
		 jQuery('#'+subContentId+' p p').hide();
		//jQuery("#replyTextLevelOne_"+cmid).attr({"disabled":"disabled"});
		//alert ("enter text");
	}
	else if(level == 'two')
	{
		var subContentId = "replyBoxLevelTwo_"+cmid;
		var linkId = "linkReplyLevelTwo_"+cmid;
		jQuery('#'+subContentId+' p p').hide();
		//jQuery("#replyTextLevelOne_"+cmid).attr({"disabled":"disabled"});
		
	}
	
	if(jQuery("#"+subContentId).css("display") == "none")
	{
		/*	DISPLAY REPLY BOX DIV	*/
		jQuery("#"+subContentId).show();
		jQuery("#"+linkId).html('Cancel Reply');
		//jQuery("#btpostReplyLevelOne_"+cmid).attr({"disabled":"disable"});
		//alert(cmid);
	}
	else
	{
		/*	HIDE REPLY BOX DIV	*/
		jQuery("#"+subContentId).hide();
		jQuery("#"+linkId).html('Reply');
	}
	
}

/*	FUNCTION TO SHOW HIDE REPLY BOX, FOR REPLY TO THIS THREAD	*/
function showReplyToThisThreadBox(cmid)
{
	var subContentId = "replyBoxLevelOne_"+cmid;
	var linkId = "linkReplyLevelOne_"+cmid;
	jQuery('#'+subContentId+' p p').hide();
	//jQuery("#"+btnNewCommId).attr({"disabled" : "disabled"});
	/*	DISPLAY REPLY BOX DIV	*/
	jQuery("#"+subContentId).show();
	jQuery("#"+linkId).html('Cancel Reply');
}

function addNewReply(replyLevel,cmId,status,videoId,type,frm_id)
{
	/*	GENERATE UNIQUE ID	*/
	var dateObject = new Date();
	var newDivId = dateObject.getTime();

	if(replyLevel == 'one')
	{
		//alert("please enter text!!!!");
		/*	DISABLE PUBLIC NEW COMMENT BUTTON	*/
		var btnNewCommId = 'btpostReplyLevelOne_'+cmId;
	
		//jQuery("#"+btnNewCommId).addClass("transparent_class");
		
		/*	GET COMMENT TEXT ENTERED	*/
		var commentText = jQuery("#replyTextLevelOne_"+cmId).val();
	
		//jQuery("#"+btnNewCommId).attr({"disabled":""});
		/*	EMPTY TEXT AREA VALUE	*/
		jQuery("#replyTextLevelOne_"+cmId).val('');

		/*	ID TO HIDE REPLY BOX THAT WAS OPENED	*/
		var replyBoxId = "replyBoxLevelOne_"+cmId;
		var linkId = "linkReplyLevelOne_"+cmId;
		
		/*	MAIN DIV IN WHICH REPLY CONTENTS TO BE SHOWN, DYNAMICALLY THROUGH AJAX	*/
		jQuery("#replyResponceContentLevelOne_"+cmId).append('<div id="'+newDivId+'"></div>');
		
		
	}		
	else
	{
		/*	DISABLE PUBLIC NEW COMMENT BUTTON	*/
		var btnNewCommId = 'btpostReplyLevelTwo_'+cmId;
		//jQuery("#"+btnNewCommId).attr({"disabled":"disabled"});
		jQuery("#"+btnNewCommId).addClass("transparent_class");
		jQuery('#'+btnNewCommId).removeClass("button-black_green_whitebg");
		jQuery("#"+btnNewCommId).attr({"onClick":""});
		jQuery("#"+frm_id).attr({"onSubmit":""});
		/*	GET COMMENT TEXT ENTERED	*/
		var commentText = jQuery("#replyTextLevelTwo_"+cmId).val();
		

		/*	EMPTY TEXT AREA VALUE	*/
		jQuery("#replyTextLevelTwo_"+cmId).val('');
		
		/*	ID TO HIDE REPLY BOX THAT WAS OPENED	*/
		var replyBoxId = "replyBoxLevelTwo_"+cmId;
		var linkId = "linkReplyLevelTwo_"+cmId;
		
		/*	MAIN DIV IN WHICH REPLY CONTENTS TO BE SHOWN, DYNAMICALLY THROUGH AJAX	*/
		jQuery("#replyResponceContentLevelTwo_"+cmId).show();
		jQuery("#replyResponceContentLevelTwo_"+cmId).append('<div id="'+newDivId+'"></div>');
	}
	if(commentText != '')
	{
		/*	IF THERE ARE NO COMMENTS RECORDS THEN  REMOVE THAT MESSAGE	*/
		if(jQuery("#noRecordFound"))
		{
			jQuery("#noRecordFound").html('');
		}		
		
		/*	SET PARAMETER THAT WILL BE SENT TO AJAX	*/	
		var pageName = AJAX_PATH+'makerequest.php';
		var parameters = 'pname=video_detail_comments&action=add_new_reply&status='+escape(status)+'&vid='+escape(videoId)+'&comment='+commentText+'&comment_id='+escape(cmId)+'&level='+escape(replyLevel)+'&ctype='+type+'';
		var resultDiv = newDivId;
		
		/*	MAKE AJAX CALL TO POST NEW COMMENT	*/
		jQuery.ajax({
		   type: "POST",
		   url: pageName,
		   data: parameters,
		   beforeSend: function(){jQuery("#"+resultDiv).html('<center><img align="absbottom" src="'+IMAGE_PATH+'global/loaders/loader_blue.gif" /></center>');},
		   success: function(msg){
			   jQuery("#"+resultDiv).html(msg);
			   countReply(replyLevel,cmId,status,videoId,type);
			   /*	ENABLE ADD NEW COMMENT  BUTTON	*/
			   //jQuery("#"+btnNewCommId).attr({"disabled":"disabled"});
			   
			   /*	DISABLE BUTTON AFTER, NEW COMMENT IS POSTED	*/
				jQuery("#"+btnNewCommId).addClass("transparent_class");
				jQuery('#'+btnNewCommId).removeClass("button-black_green_whitebg");
				jQuery("#"+btnNewCommId).attr({"onClick":""});
				jQuery("#"+frm_id).attr({"onSubmit":""});
			   
			   /*	HIDE REPLY BOX	*/
				jQuery("#"+replyBoxId).hide();
				jQuery("#"+linkId).html('Reply');
		   },
			error: function(){
				//jQuery("#"+resultDiv).html('Error Loading Script');
				/*	ENABLE ADD NEW COMMENT  BUTTON	*/
				jQuery("#"+btnNewCommId).attr({"disabled":"disabled"});
				
				/*	DISABLE BUTTON AFTER, NEW COMMENT IS POSTED	*/
				jQuery("#"+btnNewCommId).addClass("transparent_class");
				
				/*	HIDE REPLY BOX	*/
				jQuery("#"+replyBoxId).hide();
				jQuery("#"+linkId).html('Reply');
			}
		 });
		
		/*	SHOW MAIN REPLY CONTENTS DIV	*/
		jQuery("#replyCommentsContent_"+cmId).show();
		
	}
	else
	{
		//alert('Please enter reply text');	
		/*	DISABLE BUTTON AFTER, NEW COMMENT IS POSTED	*/
		jQuery("#"+btnNewCommId).addClass("transparent_class");
		jQuery('#'+btnNewCommId).removeClass("button-black_green_whitebg");
		jQuery("#"+btnNewCommId).attr({"onClick":""});
		jQuery("#"+frm_id).attr({"onSubmit":""});
		
		/*	ENABLE ADD NEW COMMENT  BUTTON	*/
		//jQuery("#"+btnNewCommId).attr("disabled", "");
	}
	return false;
}

/*	IF USER IS NOT LOGIN THEN DISPLAY ERROR MESSAGE	*/
function userNotLogIn()
{
	//alert('You Have To Login First');
}

function get_sub_cat(element)
{
	
	 var cat = element.split("-");
	 //var tag_id = cat[1];
	 var category_id = cat[0];
	 var video_id = cat[1];
	 var meadia_type = cat[2];
	 
	  var pageName   = AJAX_PATH+'makerequest.php'
	  var parameters = 'pname=video_detail&action=subcategories&category_id='+encodeURI(category_id)+'&vid='+encodeURI(video_id)+'&video_type='+encodeURI(meadia_type);
	   jQuery.ajax({
	   type: "POST",
	   url: pageName,
	   data: parameters,
	   //beforeSend: function(){jQuery("#"+resultDiv).html("Loading...");},
	   success: function(result)
	   {
			//alert(result);
			//alert(msg);
			jQuery('#videoCategoryBreadCrumbs').html(result);
	    },
		error: function()
		{ //so, if data is retrieved, store it in html 
			//alert('Error Loading Script'); //show the html inside .content div 
		}
	 });
		//jQuery("#categoryval-"+tag_id).html(new_cat); 
}

function update_category_subcat(m_cat_id,sub_cat_id,video_id,video_type)
{	
	var sub_cat_id = jQuery('#sub_category').val();
	var pageName = AJAX_PATH+'makerequest.php';
	var parameters = 'pname=video_detail&action=editinfo&vid='+escape(video_id)+'&sub_cat_id='+escape(sub_cat_id)+'&video_type='+video_type+'&m_cat_id='+m_cat_id+'&option=master';
	var resultDiv = 'videoCategoryBreadCrumbs';

	/*	MAKE AJAX CALL */
	jQuery.ajax({
		   type: "POST",
		   url: pageName,
		   data: parameters,
		   beforeSend: function(){jQuery("#"+resultDiv).html('<img align="absbottom" src="'+IMAGE_PATH+'global/loaders/spinner18x18.gif" />');},
		   success: function(msg){
			//alert()
			jQuery("#"+resultDiv).html(msg);
			// 	alert(msg);
		   },
			error: function(){
				//alert('Error Loading Script');
			}
		 });
}


/*	FUNCTION TO TOGGLE MORE-LESS VIDEO TAGS	*/
function showTags(option)
{
	if(option == 'more')
	{
		/*	HIDE DEFAULT TAG LIST AND SHOW ALL TAGS DIV		*/
		jQuery("#defaultTagList").hide();
		jQuery("#allTagList").show();
	}
	else
	{
		/*	HIDE DEFAULT TAG LIST AND SHOW ALL TAGS DIV		*/
		jQuery("#allTagList").hide();
		jQuery("#defaultTagList").show();
	}
}

/*	FUNCTION TO TOGGLE MORE-LESS VIDEO DESCRIPTION	*/
function showDesc(option)
{
	if(option == 'more')
	{
		/*	HIDE DEFAULT TAG LIST AND SHOW ALL TAGS DIV		*/
		jQuery("#descLess").hide();
		jQuery("#descMore").show();
	}
	else
	{
		/*	HIDE DEFAULT TAG LIST AND SHOW ALL TAGS DIV		*/
		jQuery("#descMore").hide();
		jQuery("#descLess").show();
	}
}


/*	FUNCTION TO SHOW MAIN NAVIGATION CONTENTS, DETAILS AND EMBED-CODE		*/
function showVideoDetail(option)
{
	if(option == 'embed')
	{
		/*	CHANGE TAB CLASS TO SELECTED AND UNSELECTED	*/
		jQuery("#videoInfoDetailTab").removeClass("current");
		jQuery("#videoInfoRelatedTab").removeClass("current");
		jQuery("#videoInfoEmbedTab").addClass("current");
		jQuery("#refreshRelatedBox").hide();
		
		/*	NOW HIDE VIDEO INFO DIV AND SHOW EMBED DIV	*/
		jQuery("#video-details").hide();
		jQuery("#video-related").hide();
		jQuery("#embed-details").show();		
		
	}
	else if(option == 'detail')
	{
		/*	CHANGE TAB CLASS TO SELECTED AND UNSELECTED	*/
		jQuery("#videoInfoEmbedTab").removeClass("current");
		jQuery("#videoInfoRelatedTab").removeClass("current");
		jQuery("#videoInfoDetailTab").addClass("current");
		jQuery("#refreshRelatedBox").hide();
		
		/*	NOW HIDE EMBED DIV AND SHOW VIDEO INFO DIV 	*/
		jQuery("#embed-details").hide();
		jQuery("#video-related").hide();
		jQuery("#video-details").show();	
	}
	else
	{
		/*	CHANGE TAB CLASS TO SELECTED AND UNSELECTED	*/
		jQuery("#videoInfoEmbedTab").removeClass("current");
		jQuery("#videoInfoDetailTab").removeClass("current");
		jQuery("#videoInfoRelatedTab").addClass("current");
		jQuery("#refreshRelatedBox").show();
		
		/*	NOW HIDE EMBED DIV AND SHOW VIDEO INFO DIV 	*/
		jQuery("#embed-details").hide();
		jQuery("#video-details").hide();
		jQuery("#video-related").show();
		
	}
}

/*	THIS FUNCTION IS USED FOR COPY TO CLIPBOARD	*/


/*	FUNCTION TO MAIN SECTIONS I-E COMMENTS AND POPD BY		*/

function showMainCommentsPopd(option)
{
	if(option == 'popd_by')
	{
		/*	CHANGE TAB CLASS TO SELECTED AND UNSELECTED	*/
		jQuery('#sortby_comments_video').hide();
		jQuery("#mainTabComments").removeClass("current");
		jQuery("#mainTabPopd").addClass("current");
		
		/*	NOW HIDE VIDEO INFO DIV AND SHOW EMBED DIV	*/
		jQuery("#commentsWrap").hide();
		jQuery("#mainPopdByContainer").show();		
		
		/*	SHOW BOTTOM CONTENTS 	*/
		jQuery("#newCommentContent").hide();
		jQuery("#popPaginationContent").show();
		
		/*	HIDE SORT OPTION WHEN POPD-BY TAB IS SELECTED	*/
		jQuery("#commentsSortby").hide();		
		jQuery("#sort-submenu").css('visibility','hidden');
	}
	else
	{
		/*	CHANGE TAB CLASS TO SELECTED AND UNSELECTED	*/
		jQuery('#sortby_comments_video').show();
		jQuery("#mainTabPopd").removeClass("current");
		jQuery("#mainTabComments").addClass("current");
		
		/*	NOW HIDE EMBED DIV AND SHOW VIDEO INFO DIV 	*/
		jQuery("#mainPopdByContainer").hide();
		jQuery("#commentsWrap").show();	
		
		/*	SHOW BOTTOM CONTENTS 	*/
		jQuery("#popPaginationContent").hide();
		jQuery("#newCommentContent").show();
		
		/*	SHOW SORT OPTION WHEN POPD-BY TAB IS SELECTED	*/
		jQuery("#commentsSortby").show();
	}
}


function showMainCommentsPopd_logout(option)
{
	if(option == 'popd_by')
	{
		/*	CHANGE TAB CLASS TO SELECTED AND UNSELECTED	*/
		jQuery('#sortby_comments_video').hide();
		jQuery("#mainTabComments").removeClass("current");
		jQuery("#mainTabPopd").addClass("current");
		
		/*	NOW HIDE VIDEO INFO DIV AND SHOW EMBED DIV	*/
		jQuery("#commentsWrap").hide();
		jQuery("#mainPopdByContainer").show();		
		
		/*	SHOW BOTTOM CONTENTS 	*/
		jQuery("#newCommentContent").hide();
		jQuery("#popPaginationContent").show();
		
		/*	HIDE SORT OPTION WHEN POPD-BY TAB IS SELECTED	*/
		jQuery("#commentsSortby").hide();		
		jQuery("#sort-submenu").css('visibility','hidden');
	}
	else
	{
		/*	CHANGE TAB CLASS TO SELECTED AND UNSELECTED	*/
		jQuery('#sortby_comments_video').show();
		jQuery("#mainTabPopd").removeClass("current");
		jQuery("#mainTabComments").addClass("current");
		
		/*	NOW HIDE EMBED DIV AND SHOW VIDEO INFO DIV 	*/
		jQuery("#mainPopdByContainer").hide();
		jQuery("#commentsWrap").show();	
		
		/*	SHOW BOTTOM CONTENTS 	*/
		jQuery("#popPaginationContent").hide();
		jQuery("#newCommentContent").hide();
		
		/*	SHOW SORT OPTION WHEN POPD-BY TAB IS SELECTED	*/
		jQuery("#commentsSortby").show();
	}
}

/*	FUNCTION FOR POPED-BY PAGINATION	*/
function showMembersPopdVideo(page,videoId)
{
	/*	SET PARAMETER THAT WILL BE SENT TO AJAX	*/	
	var pageName = AJAX_PATH+'makerequest.php';
	var parameters = 'pname=video_detail_comments&action=show_popd_by&page='+escape(page)+'&vid='+escape(videoId)+'';
	var resultDiv = 'mainPopdByContainer';
	
	/*	MAKE AJAX CALL */
	jQuery.ajax({
		   type: "POST",
		   url: pageName,
		   data: parameters,
		   /*beforeSend: function(){jQuery("#"+resultDiv).html('<center><img align="absbottom" src="'+IMAGE_PATH+'global/loaders/loader_blue.gif" /></center>');},*/
		   success: function(msg){
			   jQuery("#"+resultDiv).html(msg);
		   },
			error: function(){
				//jQuery("#"+resultDiv).html('Error Loading Script');
			}
		 });
}




/*	FUNCTION TO SORT COMMENTS	*/
function commentsSortBy(option,videoId,pageName)
{
	
	/*	FIRST REMOVE SELECTED CLASS FROM ALL OPTIONS	*/
	jQuery("#playlistLastUpdated2").removeClass("field-background");
	jQuery("#playlistAlphabitical2").removeClass("field-background");
	jQuery("#playlistMostPopular2").removeClass("field-background");
	jQuery("#playlistReverseOrder2").removeClass("field-background");
	
	/*	CHK WHICH OPTION IS CLICKED, AND MAKE IT SELECTED	*/
	if(option == 'latest')
	{
		jQuery("#playlistLastUpdated2").addClass("field-background");
		
		
		/*	SET THE SORT OPTION HIDDEN FIELD VALUE TO SELECTED, THAT WILL B USED TO GET COMMENTS	*/
		//jQuery("input#sortByOption").val('latest');
		document.getElementById('sortByOption').value = 'latest';
	}
	else if(option == 'oldest')
	{
		jQuery("#playlistAlphabitical2").addClass("field-background");
		
		/*	SET THE SORT OPTION HIDDEN FIELD VALUE TO SELECTED, THAT WILL B USED TO GET COMMENTS	*/
		//jQuery("input#sortByOption").val('oldest');
		document.getElementById('sortByOption').value = 'oldest';
	}
	else if(option == 'highest')
	{
		jQuery("#playlistMostPopular2").addClass("field-background");
		
		/*	SET THE SORT OPTION HIDDEN FIELD VALUE TO SELECTED, THAT WILL B USED TO GET COMMENTS	*/
		//jQuery("input#sortByOption").val('highest');
		document.getElementById('sortByOption').value = 'highest';
	}
	else if(option == 'lowest')
	{
		jQuery("#playlistReverseOrder2").addClass("field-background");
		
		/*	SET THE SORT OPTION HIDDEN FIELD VALUE TO SELECTED, THAT WILL B USED TO GET COMMENTS	*/
		//jQuery("input#sortByOption").val('lowest');
		document.getElementById('sortByOption').value = 'lowest';
	}
	
	/*	HIDE SORT MENU	*/
	jQuery("#sort-submenu").css('visibility','hidden');
	
	/*	GET THE CURRENT COMMENT SECTION FROM HIDDEN FIELD I-E PUBLIC,PRIVATE,YOUR COMMENTS ETC	*/
	var commSection = jQuery("#commentsCurrentSection").val();
	
	/*	SHOW COMMENTS WITH SORT OPTIONS	*/
	showComments(commSection,videoId,pageName)

}

/*	FCUNTION TO SHOW SORT MENU FOR COMMENTS	*/
/*function showSubMenus(obj) 
{
	var menu = document.getElementById(obj);
	if (menu.style.visibility != 'hidden') {
		menu.style.visibility = 'hidden';
	}
	else {
		menu.style.visibility = 'visible';
	}
}*/

/*	FUNCTION TO SCROLL TO SELECTED THREAD	*/
function  scrollToId(elementId)
{
	/*var jQuerytarget = jQuery('#'+elementId);
	 jQuerytarget = jQuerytarget.length && jQuerytarget || jQuery('[name=' + this.hash.slice(1) +']');
	 if (jQuerytarget.length) {
		 jQuerytarget.ScrollTo(400);
		 return false;
	 }*/
	 window.scrollTo(800,800);
}
/*	FUNCTION TO MAKE VOTE FOR COMMENTS	*/
function makeCommentVote(vote,comm_id)
{
	/*	SET PARAMETER THAT WILL BE SENT TO AJAX	*/	
	var pageName = AJAX_PATH+'makerequest.php';
	var parameters = 'pname=video_detail_comments&action=add_new_vote&comm_id='+escape(comm_id)+'&vote='+escape(vote)+'';
	var resultDiv = 'commentsVoting_'+comm_id;

	/*	MAKE AJAX CALL */
	jQuery.ajax({
		   type: "POST",
		   url: pageName,
		   data: parameters,
		   beforeSend: function(){jQuery("#"+resultDiv).html('<img align="absbottom" src="'+IMAGE_PATH+'global/loaders/spinner18x18.gif" />');},
		   success: function(msg){
			 jQuery("#"+resultDiv).html(msg);
		   },
			error: function(){
				//alert('Error Loading Script');
			}
		 });
}

/*	FUNCTION TO SUGGEST SUB CATEGORY, FOR CURRENT VIDEO	*/
function suggestVideoSubCategory(videoId,catId)
{
	/*	SET PARAMETER THAT WILL BE SENT TO AJAX	*/	
	var pageName = AJAX_PATH+'makerequest.php';
	var parameters = 'pname=video_detail&action=suggest_sub_cat&vid='+escape(videoId)+'&cat_id='+escape(catId)+'';
	var resultDiv = 'suggestSubCategoryContent';

	/*	MAKE AJAX CALL */
	jQuery.ajax({
		   type: "POST",
		   url: pageName,
		   data: parameters,
		   beforeSend: function(){jQuery("#"+resultDiv).html('<img align="absbottom" src="'+IMAGE_PATH+'global/loaders/spinner18x18.gif" />');},
		   success: function(msg){
			 jQuery("#"+resultDiv).html(msg);
		   },
			error: function(){
				//alert('Error Loading Script');
			}
		 });
}
function suggestVideoMasterCategory(videoId,mediaType,option,masterCatId)
{
	/*	SET PARAMETER THAT WILL BE SENT TO AJAX	*/
	
	var pageName = AJAX_PATH+'makerequest.php';
	var parameters = 'pname=video_detail&action=suggest_master_cat&type='+escape(mediaType)+'&vid='+escape(videoId)+'&option='+escape(option)+'&master_cat='+escape(masterCatId)+'';
	var resultDiv = 'suggestMasterCategoryContent';	

	/*	MAKE AJAX CALL */
	jQuery.ajax({
		   type: "POST",
		   url: pageName,
		   data: parameters,
		  /* beforeSend: function(){jQuery("#"+resultDiv).html('<img align="absbottom" src="'+IMAGE_PATH+'global/loaders/spinner18x18.gif" />');},*/
		   success: function(msg){
			 jQuery("#"+resultDiv).html(msg);
		   },
			error: function(){
				//alert('Error Loading Script');
			}
		 });
}
/*	SHOW MASTER CATEGORY SUGGESTION	*/
function cancelCategorySuggesstion(videoId,mediaType)
{
	/*	SET PARAMETER THAT WILL BE SENT TO AJAX	*/	
	var pageName = AJAX_PATH+'makerequest.php';
	var parameters = 'pname=video_detail&action=cancel_cat_suggest&vid='+escape(videoId)+'&type='+escape(mediaType)+'';
	var resultDiv = 'videoCategoryBreadCrumbs';	

	/*	MAKE AJAX CALL */
	jQuery.ajax({
		   type: "POST",
		   url: pageName,
		   data: parameters,
		  /* beforeSend: function(){jQuery("#"+resultDiv).html('<img align="absbottom" src="'+IMAGE_PATH+'global/loaders/spinner18x18.gif" />');},*/
		   success: function(msg){
			 jQuery("#"+resultDiv).html(msg);
		   },
			error: function(){
				//alert('Error Loading Script');
			}
		 });
}


/*	FUNCTION TO ADD SUGGESSTED CATEGORY	*/
function addSuggesstedCategory(videoId,catId,catType,mediaType)
{
	/*	SET PARAMETER THAT WILL BE SENT TO AJAX	*/	
		
	var pageName = AJAX_PATH+'makerequest.php';
	var parameters = 'pname=video_detail&action=add_sugg_cat&vid='+escape(videoId)+'&cat_id='+escape(catId)+'&cat_type='+escape(catType)+'&type='+escape(mediaType)+'';
	
	/*if(catType == 'master')
	{
		var resultDiv = 'suggestMasterCategoryContent';
	}
	else
	{
		var resultDiv = 'suggestSubCategoryContent';
	}*/
	
	var resultDiv = 'videoCategoryBreadCrumbs';
	
	
	/*	MAKE AJAX CALL */
	jQuery.ajax({
		   type: "POST",
		   url: pageName,
		   data: parameters,
		   beforeSend: function(){jQuery("#"+resultDiv).html('<img align="absbottom" src="'+IMAGE_PATH+'global/loaders/spinner18x18.gif" />');},
		   success: function(msg){
			 
			 //alert(msg);
			 jQuery("#"+resultDiv).html(msg);
		   },
			error: function(){
				//alert('Error Loading Script');
			}
		 });
}

/*	FUNTION TO SHOW NOT LOGIN ALERT MESSAGE	*/
function showNotLoginAlert()
{
	/*	SHOW ALERT BOX	*/
	jQuery('#commentPostedAlertNotLogin').show('fast');
	
	/*	FUNCTION TO SCROLL TO ALERT BOX, IF USER IS NOT LOG-IN	*/
	scrollToId('commentsSortby');

	/*	HIDE ADD NEW BOXES FOR PUBLIC AND PRIVATE	*/
	jQuery('#addNewCommentPublic').hide();
	jQuery('#addNewCommentPrivate').hide();
	
}
/*	COMMENTS AND REPLIES, SCROLL EFFECT	*/
function commentScroll()
 {
	jQuery('a[href*=#]').click(function() {
	
	  if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
		&& location.hostname == this.hostname) {
		 var jQuerytarget = jQuery(this.hash);
		 jQuerytarget = jQuerytarget.length && jQuerytarget || jQuery('[name=' + this.hash.slice(1) +']');
		 if (jQuerytarget.length) {
			 jQuerytarget.ScrollTo(400);
			 return false;
		 }
	  };
	});
}

/*	THIS FUNCTION IS USED FOR COPY TO CLIPBOARD	*/
function copyText(option) {
    /* This function was modified 2007 by Roderick Divilbiss
    and was based upon two scripts:

    The first script was from
    The JavaScript Source!! http://javascript.internet.com
    Created by: Mark O'Sullivan :: http://lussumo.com/
    Jeff Larson :: http://www.jeffothy.com/
    Mark Percival :: http://webchicanery.com/

    The second script was taken from http://blog.deconcept.com/swfobject/
    
    */
    /*if (window.clipboardData) {
        window.clipboardData.setData("Text",text2copy);
    }else{
        var so = new SWFObject('clipboard.swf', 'copy_contents', '0', '0', '4');
        so.addVariable('clipboard', escape(text2copy));
        so.write('flashcontent');
		//alert(so.write);
    }*/
	
	
	if(option == 'embed')
	{
		/*	GET VIDEO EMBED CODE BY ID OF TEXTAREA	*/
		var copyText = jQuery("#areaEmbedCode").val();
	}
	else
	{
		/*	GET VIDEO PERMANENT LINK FROM TEXT BOX	*/
		var copyText = jQuery("#videoPermaLinkText").val();
	}
	
	//	IF BROWSER IS I-E	//
	if (window.clipboardData) 
	{
		//	IF TEXT SUCCESSFULLY COPIES FOR I-E, THEN SHOW COPIED STATUS	//
		if( window.clipboardData.setData("Text",copyText) )
		{
			
			if(option == 'embed')
			{
				//	CHANGE EMBED COPY STATUS TO COPIED	/
				jQuery("#embedCopyStatus").removeClass("option");
				jQuery("#embedCopyStatus").html('<a href="#">Copied</a>');
				jQuery("#embedCopyStatus").addClass("optionCopied");
			}
			else
			{
				//	CHANGE PREMA LINK COPY STATUS TO COPIED	//
				jQuery("#premaLinkCopyStatus").removeClass("option");
				jQuery("#premaLinkCopyStatus").html('<a href="#">Copied</a>');
				jQuery("#premaLinkCopyStatus").addClass("optionCopied");
			}
		}
	}
	

   /*else if (window.netscape) { // Mozilla
            
			   try {
                        netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

                        var gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);

                        gClipboardHelper.copyString(copyText);
                } catch(e) {
                        return alert(e +'\n\nPlease type: "about:config" in your address bar.\nThen filter by "signed".\nChange the value of "signed.applets.codebase_principal_support" to true.\nYou should then be able to use this feature.');
                }
        }
   */
	//	ELSE IF THERE IS ANOTHER BROWSER THEN I-E	//
	
	else {
                var flashcopier = 'flashcopier';
                if (!document.getElementById(flashcopier))
				{
                    var divholder = document.createElement('div');
                    divholder.id = flashcopier;
                    document.body.appendChild(divholder);
				}
                document.getElementById(flashcopier).innerHTML = '';

        	 	var divinfo = '<embed src="'+BASE_PATH+'templates/video_detail/clipboard.swf" FlashVars="clipboard=' + escape(copyText) + '" width="30" height="30" type="application/x-shockwave-flash"></embed>';	
                document.getElementById(flashcopier).innerHTML = divinfo;
				//alert("copy3");
				
			if(option == 'embed')
			{
				//	CHANGE EMBED COPY STATUS TO COPIED	//
				jQuery("#embedCopyStatus").removeClass("option");
				jQuery("#embedCopyStatus").html('<a href="#">Copied</a>');
				jQuery("#embedCopyStatus").addClass("optionCopied");
			}
			else
			{
				//	CHANGE PREMA LINK COPY STATUS TO COPIED	/
				jQuery("#premaLinkCopyStatus").removeClass("option");
				jQuery("#premaLinkCopyStatus").html('<a href="#">Copied</a>');
				jQuery("#premaLinkCopyStatus").addClass("optionCopied");
			}
			
			
            }

}


/*	FUNCTION TO ENABLE ADD NEW COMMENT BUTTON	*/

function enableAddCommentBtn(textAreaId,btnId,commentType,video_id,frm_id,level,commentId)
{
	var commentid=  textAreaId.split('_');
		
	if( jQuery('#'+textAreaId).val() == '' )
	{	
	///  SHOW HIDE SPELL CHECK ENABLE DISABLE//
		// PUBLIC//
		if(commentid[1]==undefined)
		{
		jQuery('#postNewComment h').show();
		jQuery('#postNewComment p p').hide();
		}
		
				//LEVEL ONE//
		jQuery('#replyBoxLevelOne_'+commentid[1]+' h').show();
		jQuery('#replyBoxLevelOne_'+commentid[1]+' p p').hide();
		
		//LEVEL TWO//
		jQuery('#replyBoxLevelTwo_'+commentid[1]+' h').show();
		jQuery('#replyBoxLevelTwo_'+commentid[1]+' p p').hide();
		
		
		///  SHOW HIDE SPELL CHECK ENABLE DISABLE//
		
		jQuery('#'+btnId).addClass("transparent_class");
		jQuery('#'+btnId).removeClass("button-black_green_whitebg");
		jQuery("#"+btnId).attr({"onClick":""});
		jQuery("#"+frm_id).attr({"onSubmit":""});
	}
	else
	{
		jQuery('#'+btnId).removeClass("transparent_class");
		jQuery('#'+btnId).addClass("button-black_green_whitebg");
		if(level=='')
		{
			jQuery("#"+btnId).attr({"onClick":"addNewComment('"+commentType+"','"+video_id+"','video','"+frm_id+"')"});
			jQuery("#"+frm_id).attr({"onSubmit":"return addNewComment('"+commentType+"','"+video_id+"','video','"+frm_id+"');"});
		}
		else
		{
			jQuery("#"+btnId).attr({"onClick":"addNewReply('"+level+"','"+commentId+"','"+commentType+"','"+video_id+"','video','"+frm_id+"')"});
			jQuery("#"+frm_id).attr({"onSubmit":"return addNewReply('"+level+"','"+commentId+"','"+commentType+"','"+video_id+"','video','"+frm_id+"');"});
		}
		/*else if(level=='two')
		{
			jQuery("#"+btnId).attr({"onClick":"addNewReply('"+level+"','"+commentId+"','"+commentType+"','"+video_id+"','video','"+frm_id+"')"});
			jQuery("#"+frm_id).attr({"onSubmit":"addNewReply('"+level+"','"+commentId+"','"+commentType+"','"+video_id+"','video','"+frm_id+"')"});
		}*/
		///  SHOW HIDE SPELL CHECK ENABLE DISABLE//
		//PUBLIC//
		if(commentid[1]==undefined)
		{
		
		jQuery('#postNewComment h').hide();
		jQuery('#postNewComment p p').show();
		
		var cls = jQuery("#postNewComment p p").attr('class');
		if(cls=='spellcheckNoError')
		{ 	jQuery("#postNewComment p p").removeClass('spellcheckNoError');
			jQuery("#postNewComment p p").addClass('spellcheck');
			
			jQuery("#postNewComment p p span span h").hide();
			jQuery("#postNewComment p p span span a").text('Spell Check');
		}
		}
		
		//LEVEL ONE//
		jQuery('#replyBoxLevelOne_'+commentid[1]+' h').hide();
		jQuery('#replyBoxLevelOne_'+commentid[1]+' p p').show();

			
		var cls = jQuery('#replyBoxLevelOne_'+commentid[1]+' p p').attr('class');
		if(cls=='spellcheckNoError')
		{ 
			jQuery('#replyBoxLevelOne_'+commentid[1]+' p p').removeClass('spellcheckNoError');
			jQuery('#replyBoxLevelOne_'+commentid[1]+' p p').addClass('spellcheck');
			
			jQuery('#replyBoxLevelOne_'+commentid[1]+' p p span span h').hide();
			jQuery('#replyBoxLevelOne_'+commentid[1]+' p p span span a').text('Spell Check');
		}
		
		
		//LEVEL TWO//
		jQuery('#replyBoxLevelTwo_'+commentid[1]+' h').hide();
		jQuery('#replyBoxLevelTwo_'+commentid[1]+' p p').show();
		
		var cls = jQuery('#replyBoxLevelTwo_'+commentid[1]+' p p').attr('class');
		if(cls=='spellcheckNoError')
		{ 	jQuery('#replyBoxLevelTwo_'+commentid[1]+' p p').removeClass('spellcheckNoError');
			jQuery('#replyBoxLevelTwo_'+commentid[1]+' p p').addClass('spellcheck');
			
			jQuery('#replyBoxLevelTwo_'+commentid[1]+' p p span span h').hide();
			jQuery('#replyBoxLevelTwo_'+commentid[1]+' p p span span a').text('Spell Check');
		}
		///  SHOW HIDE SPELL CHECK ENABLE DISABLE//
		
	}
	
	
}


function showSortBox(divId)
{  
	setTimeout(function()
	{ 
		 if(varToggle)
		  {
			jQuery('#playlistSortBtn').removeClass();
			jQuery('#playlistSortBtn').addClass('buttonSelected');
		
			jQuery('#'+divId).css('display','block');
			varToggle = false;
		  }
		  else
		  {
			jQuery('#playlistSortBtn').removeClass();
			jQuery('#playlistSortBtn').addClass('button');
			
			jQuery('#'+divId).css('display','none');
			varToggle = true;
		  }
	}, 10);	  
};

/* LIBRARY STAR THIS FUNCTOIN  */
function libraryStarThis(video_id,starred)
{
	jQuery('#stared li#star-this').html('<a title="" onclick="libraryRemoveStar(\''+video_id+'\',\''+starred+'\');" href="javascript:;">Remove</a>');
	jQuery('#stared li#star-this a').addClass('acton-starred');
	jQuery('#stared li#star-this a').removeClass('log_in_acton-star-this');
	jQuery('#stared_widescreen li#star-this_widescreen').html('<a title="" onclick="libraryRemoveStar(\''+video_id+'\',\''+starred+'\');" href="javascript:;">Remove</a>');
	jQuery('#stared_widescreen li#star-this_widescreen a').addClass('acton-starred');
	jQuery('#stared_widescreen li#star-this_widescreen a').removeClass('log_in_acton-star-this');

	/*jQuery('#default_options_'+video_id+' li.starred').show();
	jQuery('#choosed_options_'+video_id+' li.starred').show();	
	*/
	/*jQuery('#options_'+video_id).append('<ul id="choosed_options_'+video_id+'" style="display:none;"><li class="starred"><a href="#" title="">Starred</a></li></ul>');*/
	/* CALL AJAX FILE */
	var parameters = 'video_id='+video_id+'&pname=star_video&option=addstar';
	var pageName = AJAX_PATH+'makerequest.php';
	jQuery.ajax({
	   type: "POST",
	   url: pageName,
	   data: parameters,
	   success: function(msg){
		//alert(msg);
		
	   },
	   error: function(){
			alert('Error in Ajax call .....');
	   }
    });
}

function libraryRemoveStar(video_id,starredpage)
{
/*	jQuery('#default_options_'+video_id+' li.starred').html('<a title="" onclick="libraryStarThis(\''+video_id+'\',\''+starredpage+'\');" href="javascript:;">Star this</a>');
	jQuery('#default_options_'+video_id+' li.starred').addClass('starthis');
	jQuery('#default_options_'+video_id+' li.starthis').removeClass('starred');
	jQuery('#choosed_options_'+video_id).remove();*/
	//jQuery('#options_'+video_id).append('<li class="starthis"><a href="javascript:;" onclick="libraryStarThis('+video_id+'); " title="">Star this</a></li>');
	jQuery('#stared li#star-this').html('<a title="" onclick="libraryStarThis(\''+video_id+'\',\''+starredpage+'\');" href="javascript:;">Star this</a>');
	jQuery('#stared li#star-this a').addClass('log_in_acton-star-this');
	jQuery('#stared li#star-this a').removeClass('log_in_acton-starred');
	jQuery('#stared_widescreen li#star-this_widescreen').html('<a title="" onclick="libraryStarThis(\''+video_id+'\',\''+starredpage+'\');" href="javascript:;">Star this</a>');
	jQuery('#stared_widescreen li#star-this_widescreen a').addClass('log_in_acton-star-this');
	jQuery('#stared_widescreen li#star-this_widescreen a').removeClass('log_in_acton-starred');
/*	if(starredpage == 1)
	{
		jQuery('#'+video_id).fadeOut();	
	}*/
	var parameters = 'video_id='+video_id+'&pname=star_video&option=removestar';
	var pageName = AJAX_PATH+'makerequest.php';
	jQuery.ajax({
	   type: "POST",
	   url: pageName,
	   data: parameters,
	   success: function(msg){
		//alert(msg);
	   },
	   error: function(){
			alert('Error in Ajax call .....');
	   }
    });
}

function edit_category_subcat(video_id,cat_id,video_type,m_cat_id)
{

	var pageName = AJAX_PATH+'makerequest.php';
	var parameters = 'pname=video_detail&action=edit_categories_sub&vid='+escape(video_id)+'&cat_id='+escape(cat_id)+'&video_type='+video_type+'&master_id='+m_cat_id+'&option=master';
	var resultDiv = 'videoCategoryBreadCrumbs';

	/*	MAKE AJAX CALL */
	jQuery.ajax({
		   type: "POST",
		   url: pageName,
		   data: parameters,
		   beforeSend: function(){jQuery("#"+resultDiv).html('<img align="absbottom" src="'+IMAGE_PATH+'global/loaders/spinner18x18.gif" />');},
		   success: function(msg){
			//alert(msg);
			jQuery("#"+resultDiv).html(msg);
			// 	alert(msg);
		   },
			error: function(){
				//alert('Error Loading Script');
			}
		 });
}
/*function cat_change(element) { 
		var elem_id = element.id;
		var cat = elem_id.split("-");
		var tag_id = cat[1];
		
		var currentid = jQuery('#category').val();
		var ids = currentid.split("_");
		var field_value = ids[0];
		var cat_name = ids[1];
		var vid = ids[2];
		var m_cat_name = ids[3];
		
		var pageName   = AJAX_PATH+'makerequest.php'
		var parameters = 'pname=video_detail&action=editinfo&val='+encodeURI(field_value)+'&vid='+vid+'&fieldname=cat_id';
		
		//var new_cat = m_cat_name+' > '+cat_name;
	jQuery.ajax({
	   type: "POST",
	   url: pageName,
	   data: parameters,
	   //beforeSend: function(){jQuery("#"+resultDiv).html("Loading...");},
	   success: function(msg){
		  // alert(msg);
			jQuery('#videoCategoryBreadCrumbs').html(msg);
		},
		error: function(){ //so, if data is retrieved, store it in html 
			alert('Error Loading Script'); //show the html inside .content div 
		}
	 });
		//jQuery("#categoryval-"+tag_id).html(new_cat); 
	}*/

/*function jq_makeRequest(pageName,parameters,resultDiv){
	jQuery.ajax({
	   type: "POST",
	   url: pageName,
	   data: parameters,
	   //beforeSend: function(){jQuery("#"+resultDiv).html("Loading...");},
	   success: function(msg){
		  // alert(msg);
			jQuery('#videoCategoryBreadCrumbs').html(msg);
		},
		error: function(){ //so, if data is retrieved, store it in html 
			alert('Error Loading Script'); //show the html inside .content div 
		}
	 });
}*/

function changeHeight(d) {
	document.getElementById(d).style.height = document.getElementById(d).scrollHeight+"px";
	//alert(document.getElementById(d).scrollHeight+"px");
	if(d!='frmPublicComment')
	{
		val_div=d.split('_');
		if(val_div[0]=='replyTextLevelOne')
		{
			var a=document.getElementById(d).scrollHeight+"px";
			var b=parseInt(a)
			if(b>86)
			{
				var h=58+parseInt(a);
			}
			else
			{
				h=144;
			}
			//alert(val_div[1]);
			//alert(h);			
			jQuery('#'+d).parent().parent().css({'height':h+'px'});
		}
		else if(val_div[0]=='replyTextLevelTwo')
		{
			var a=document.getElementById(d).scrollHeight+"px";
			var b=parseInt(a)
			if(b>86)
			{
				var h=58+parseInt(a);
			}
			else
			{
				h=144;
			}
			jQuery('#'+d).parent().parent().css({'height':h+'px'});
		}
	}
}




function addPlaylistProcess(video_screen)
{
	if(video_screen=='standard')
	{
	//alert('hi');
		var top		= jQuery('#add_playlist_standard').position().top+25;
		var left	= jQuery('#add_playlist_standard').position().left-104;
		//jQuery('#playlistProcess').css({'display':'block','margin-left':'586px','margin-top':'-886px','position':'absolute'});
		jQuery('#playlistProcess').css({'display':'block','left':left+'px','top':top+'px'});
	}
	else
	{
		var top		= jQuery('#add_playlist_widescreen').position().top+25;
		var left	= jQuery('#add_playlist_widescreen').position().left-104;
		//jQuery('#playlistProcess').css({'display':'block','margin-left':'586px','margin-top':'-886px','position':'absolute'});
		jQuery('#playlistProcess').css({'display':'block','left':left+'px','top':top+'px'});
	}
}
function add_to_playlist(video_id,list_id)
{ 
	if(list_id==null)
	{
		return false;
	}
	else
	{
		var pageName = AJAX_PATH+'makerequest.php';
		var parameters = 'pname=addToPlaylistVideoDetail&option=add_to_playlist&list_id='+list_id+'&video_ids='+video_id;
		jQuery.ajax({	type:	"POST",
						url:	pageName,
						data:	parameters,
						success:function()
						{
							var optionhtml = '<p><a id="pl_'+list_id+'" href="javascript:;" class="playlist-category"><span id="pl_link">'+jQuery('#modalbox_pl_'+video_id+' option:selected').text()+'</span></a></p>';
							jQuery('#modalbox_pl_'+video_id+' option:selected').remove();
							jQuery('#already_in').show();
							jQuery('#pl_alreadyin_'+video_id).append(optionhtml);
						}
					});
	}
}



function remove_from_playlist(video_id,list_id)
{
	var pageName = AJAX_PATH+'makerequest.php';
	var parameters = 'pname=removeFromPlaylistVideoDetail&playlistId='+list_id+'&video_id='+video_id;
	jQuery.ajax({
				type:	"POST",
				url:	pageName,
				data:	parameters,
				success: function(result)
				{
					jQuery('#modalbox_pl_'+video_id).append('<option value="'+list_id+'">'+jQuery('#pl_'+list_id).text()+'</option>');
					jQuery('#pl_'+list_id).remove();
					if(jQuery('#pl_alreadyin_'+video_id+' a.playlist-category').length == 0)
					{
						jQuery('#already_in').hide();
					}
				}
			});
}




function showCreatePlaylist()
{ 
	// CLEARING PREVIOUS VALUES //
	//var top  = jQuery('#playlistProcess').position().top+16;
	//var left = jQuery('#playlistProcess').position().left-899;
		title = jQuery('#video-details div h2').text();
	
		if(title.length < 46)
		{
			jQuery('#addtoplaylist span').text('Add to playlist: "'+title +'"');
		}
		else
		{
			newval= title.substring(0,45);	
			jQuery('#addtoplaylist span').text('Add to playlist: "'+newval +'...."');
		}
	
	
		window.scrollTo(400,400);
		jQuery('#addtoplaylist').show();
		jQuery('#video').css({'visibility':'hidden'});
		//jQuery('#playlistProcess').css({'display':'block'});
		jQuery('.textbox').val('');
		jQuery('.textarea').val('');
		jQuery('#share').val('Anyone');
		jQuery('#sort').val('Recent');
		jQuery('#Enable').attr("checked", "checked");
	
	// CLEARING PREVIOUS VALUES //	

		jQuery('.error').hide();
	
	// SHOWING DIV //
		//jQuery('#pannelbox-wrapper').css({'display':'block','top':top+'px','margin-left':left+'px','position':'absolute','width':'100%','text-align':'center','left':'0'})
		jQuery('#mainbox_playlistpanel').show();
		jQuery('#pannelbox-wrapper').show();
		jQuery('#playListCreatedDiv').hide();
		jQuery('#creatPlayListDiv').show();
		jQuery('#title').focus();
/*		if(page_name=='library')
		{
			jQuery.scrollTo('#videoOptions', 400 );
		}else if(page_name=='playlist')
		{ 
			//jQuery.scrollTo('#frmPlaylistOptions', 40 );
			jQuery('#pannelbox-wrapper').css('top','120px');
		}*/
	//END OF SHOWING DIV //
}

function closeplaylist()
{ 
		jQuery('#video').css({'visibility':'visible'});
		jQuery('#mainbox_playlistpanel').hide();
		jQuery('#pannelbox-wrapper').hide();
	    if (checkplayliststs ==1)
		{
		  checkplayliststs = 0;
		  window.location.reload(true);
		}
}
	
	////  CREATING PLAYLIST  ////
	function creatPlayList()
	{
		jQuery('#create_playlist_button').removeClass('button-black_green_brownbg');
		jQuery('#create_playlist_button').addClass('playlistButtonChangeState');
		setTimeout(function()
		{
			jQuery('#create_playlist_button').removeClass('playlistButtonChangeState');
			jQuery('#create_playlist_button').addClass('button-black_green_brownbg');
			
		}, 100);
		var addinlist = jQuery('#addplaylist').attr('checked');
		var rightlibrary =jQuery('#addtoplaylist').css('display');
		var title = escape(jQuery('#title').val());
		var description = escape(jQuery('#description').val() );
		var share = escape(jQuery('#share').val() );
		var comments = jQuery("#public_radio > input[name='comments']:checked").val();	
		//alert(comments);
		if(title=='')
		{
			jQuery('.error').hide();
			jQuery('#provideTitle').css('display','block');	
		}
		else
		{
		
		var pageName = AJAX_PATH+'makerequest.php';
		var parameters = 'pname=createPlayList&title='+title+'&description='+description+'&share='+share+'&comments='+comments;
 		var resultDiv = 'playlists';	
			jQuery.ajax({
			   type: "POST",
			   url: pageName,
			   data: parameters,
			   success: function(msg){
					if(msg == 'Playlist Already Exists!')
					{
						jQuery('.error').hide();
						jQuery('#alreadyExsist').show();
					}
					else if(msg == 'Invalid Playlist title!')
					{
						jQuery('.error').hide();	
						jQuery('#invalidTitle').show();	
					}
					else if(msg== 'Error occured while creating playlist!')
					{
						jQuery('.error').hide();
						jQuery('#errorOccurd').show();	
					}
					else if(msg== 'Playlist created successfully!')
					{							
						jQuery('.error').hide();
						jQuery('#creatPlayListDiv').hide();	
						jQuery('#playListCreatedDiv').show();

						
						var pageName = AJAX_PATH+'makerequest.php';
		var parameters = 'pname=getPlaylist&action=getplaylist&title='+title;

			jQuery.ajax({
			   type: "POST",
			   url: pageName,
			   data: parameters,
			   success: function(msg){

				   pl_id = msg;
				   if((addinlist==true)&&(rightlibrary =='block'))
					   {

							add_to_playlist(addvideotoplaylist,pl_id);
					   
						}
			   }
			});

						
					}
			
		   	},
			error: function(){
				//alert('Error Loading Script');
			}
		 });
			
		}
	return false;
	}
	
	
	////  END OF CREATING PLAYLIST  ////

//// Starting of Count Characters /////////

function count_chars(obj)
{
	var text_length = jQuery(obj).val().length;
	
	if(jQuery(obj).attr('id') == 'title')
	{
		var max_length = 75;
		if(text_length < max_length)
		{
			jQuery('#ctitle').html((max_length-text_length)+' chars left');
		}
		else
		{
			jQuery('#ctitle').html('0 chars left');
		}
	}
	else
	{
		var max_length = 300;
		if(text_length < max_length)
		{
			jQuery('#cdesc').html((max_length-text_length)+' chars left');
		}
		else
		{
			jQuery('#cdesc').html('0 chars left');
		}
	}	
	
	if(text_length > max_length)
	{
		newval = jQuery(obj).val().substring(0,max_length);
		jQuery(obj).val(newval)
		obj.scrollTop = obj.scrollHeight;
	}
}
//////////   End of Char Counter    /////////

function update_size_popplayer(userId,size_pop_player)
{
	var pageName = AJAX_PATH+'makerequest.php';
	
	var parameters = 'pname=video_detail&action=sizeofplayer&screen='+size_pop_player+'&user_id='+userId;
	
	//var resultDiv = 'rsltdiv2';	
		/*	MAKE AJAX CALL */
	jQuery.ajax({
		   type: "POST",
		   url: pageName,
		   data: parameters,
		   success: function(msg){
			   // jQuery("#"+resultDiv).html(msg);	
				if(msg == 'success' && size_pop_player=='widescreen')
				{
						jQuery('#facebook_like_id').hide();
						//jQuery('.post-buzz').hide();
						jQuery('.tweetmeme').hide();
						
						jQuery('#standard_video_option').hide();
						//jQuery('#widescreen').show();
						jQuery('#widescreen_video_option').show();
						jQuery('#title_video_widescreen').show();
						jQuery('#videoCover').css({'background':'url('+IMAGE_PATH+'video_detail/video-bg-widescreen.png) no-repeat','height':'506px','width':'827px','padding-top':'10px','margin-top':'11px'});
						jQuery('#videoCover div embed').attr('width','803');
						jQuery('#videoCover div embed').attr('height','479');

						jQuery('#videoCover div object').attr('width','803');
						jQuery('#videoCover div object').attr('height','479');
						
						jQuery('#videoCover div object embed').attr('width','803');
						jQuery('#videoCover div object embed').attr('height','479');
						
						var x = jQuery('#videoCover div object param#flashvars').attr('value');
						var y = x.replace(/&vw=[0-9]+&/i,'&vw=790&');
						var y = y.replace(/&vh=[0-9]+&/i,'&vh=400&');
						jQuery('#videoCover div object param#flashvars').attr({'value':y});	
						
						var x = jQuery('#videoCover div object embed').attr('flashvars');
						var y = x.replace(/&vw=[0-9]+&/i,'&vw=790&');
						var y = y.replace(/&vh=[0-9]+&/i,'&vh=400&');
						jQuery('#videoCover div object embed').attr({'flashvars':y});
						
						embed = jQuery("#videoCover div#video").html();
						jQuery("#videoCover div#video").html(embed);

				}
				else if(msg == 'success' && size_pop_player=='standard')
				{
						jQuery('#facebook_like_id').show();
						//jQuery('.post-buzz').show();
						jQuery('.tweetmeme').show();
						
						//window.scrollTo(166,166);
						jQuery('#standard_video_option').show();
						//jQuery('#widescreen').hide();
						jQuery('#widescreen_video_option').hide();
						jQuery('#title_video_widescreen').hide();
						//jQuery('#videoCover').css({'background':'url('+IMAGE_PATH+'video_detail/video-bg.png) no-repeat','height':'410px','padding-top':'10px','clear':'both','width':'','padding-bottom':'16px','margin-top':'52px'});
						jQuery('#videoCover').css({'background':'url('+IMAGE_PATH+'video_detail/video-bg.png) no-repeat','height':'410px','padding-top':'10px','clear':'both','width':'','margin-top':'52px'});
						jQuery('#videoCover div embed').attr('width','480');
						jQuery('#videoCover div embed').attr('height','385');
						
						jQuery('#videoCover div object').attr('width','480');
						jQuery('#videoCover div object').attr('height','385');
						
						jQuery('#videoCover div object').attr('width','480');
						jQuery('#videoCover div object').attr('height','385');
						
						var x = jQuery('#videoCover div object param#flashvars').attr('value');
						var y = x.replace(/&vw=[0-9]+&/i,'&vw=450&');
						var y = y.replace(/&vh=[0-9]+&/i,'&vh=300&');
						jQuery('#videoCover div object param#flashvars').attr({'value':y});	
						
						var x = jQuery('#videoCover div object embed').attr('flashvars');
						var y = x.replace(/&vw=[0-9]+&/i,'&vw=450&');
						var y = y.replace(/&vh=[0-9]+&/i,'&vh=300&');
						jQuery('#videoCover div object embed').attr({'flashvars':y});
						
						embed = jQuery("#videoCover div#video").html();
						jQuery("#videoCover div#video").html(embed);
				}
						
			},
			error: function(){
				//alert('Error Loading Script');
			}
		 });
}


function widescreen()
{
	/*var widescreen_div='<div id="details"><div id="video-details" class="descDetail"><a href="#">2045 <span>Pop it!</span></a></div><div class="clear"></div><div id="share-this"><p>Share this vid:</p><ul><li><a href="#" class="share-twitter selected">Twitter</a></li><li><a href="#" class="share-facebook">Facebook</a></li><li><a href="#" class="share-digg">Digg</a></li><li><a href="#"  class="share-myspace">Myspace</a></li></ul></div><ul id="stared"><li><a class="acton-star-this" href="#">Star this</a></li><li><a class="acton-add-playlist" href="#">Add to playlist</a></li><li><a class="action-widescreen4-3" href="#">Standard</a></li></ul></div><div id="embed"></div>';*/
	//jQuery('#standard_screen').hide();
	jQuery('#standard_video_option').hide();
	//jQuery('#widescreen').show();
	jQuery('.tweetmeme').hide();
	jQuery('#facebook_like_id').hide();
	
	jQuery('#widescreen_video_option').show();
	jQuery('#title_video_widescreen').show();
	jQuery('#videoCover').css({'background':'url('+IMAGE_PATH+'video_detail/video-bg-widescreen.png) no-repeat','height':'506px','width':'827px','padding-top':'10px','margin-top':'11px'});
	jQuery('#videoCover div embed').attr('width','803');
	jQuery('#videoCover div embed').attr('height','479');

	jQuery('#videoCover div iframe').attr('width','803');
	jQuery('#videoCover div iframe').attr('height','479');

	jQuery('#videoCover div iframe object').attr('width','803');
	jQuery('#videoCover div iframe object').attr('height','479');


	var x = jQuery('#videoCover div object param#flashvars').attr('value');
	if((typeof x)!="undefined"){
		var y = x.replace(/&vw=[0-9]+&/i,'&vw=790&');
		var y = y.replace(/&vh=[0-9]+&/i,'&vh=400&');
		jQuery('#videoCover div object param#flashvars').attr({'value':y});	
	}
	var x2 = jQuery('#videoCover div object embed').attr('flashvars');
	if((typeof x2)!="undefined"){
		var y = x2.replace(/&vw=[0-9]+&/i,'&vw=790&');
		var y = y.replace(/&vh=[0-9]+&/i,'&vh=400&');
		jQuery('#videoCover div object embed').attr({'flashvars':y});
	}
	
	embed = jQuery("#videoCover div#video").html();
	jQuery("#videoCover div#video").html(embed);
	
}

function standardscreen()
{
	//window.scrollTo(166,166);
	//jQuery('#standard_screen').show();
	jQuery('#standard_video_option').show();
	//jQuery('#widescreen').hide();
	
	jQuery('.tweetmeme').show();
	jQuery('#facebook_like_id').show();
	
	jQuery('#widescreen_video_option').hide();
	jQuery('#title_video_widescreen').hide();
	//jQuery('#videoCover').css({'background':'url('+IMAGE_PATH+'video_detail/video-bg.png) no-repeat','height':'410px','padding-top':'10px','clear':'both','width':'','padding-bottom':'16px','margin-top':'52px'});
	jQuery('#videoCover').css({'background':'url('+IMAGE_PATH+'video_detail/video-bg.png) no-repeat','height':'410px','padding-top':'10px','clear':'both','width':'','margin-top':'52px'});
	jQuery('#videoCover div embed').attr('width','480');
	jQuery('#videoCover div embed').attr('height','385');

	jQuery('#videoCover div iframe').attr('width','480');
	jQuery('#videoCover div iframe').attr('height','385');

	jQuery('#videoCover div iframe object').attr('width','480');
	jQuery('#videoCover div iframe object').attr('height','385');


	var x = jQuery('#videoCover div object param#flashvars').attr('value');
	var y = x.replace(/&vw=[0-9]+&/i,'&vw=450&');
	var y = y.replace(/&vh=[0-9]+&/i,'&vh=300&');
	jQuery('#videoCover div object param#flashvars').attr({'value':y});	
	
	var x = jQuery('#videoCover div object embed').attr('flashvars');
	var y = x.replace(/&vw=[0-9]+&/i,'&vw=450&');
	var y = y.replace(/&vh=[0-9]+&/i,'&vh=300&');
	jQuery('#videoCover div object embed').attr({'flashvars':y});
	
	embed = jQuery("#videoCover div#video").html();
	jQuery("#videoCover div#video").html(embed);
}

function countReply(replyLevel,cmId,status,videoId,type)
{
		var pageName = AJAX_PATH+'makerequest.php';
		var parameters = 'pname=video_detail_comments&action=count_reply&status='+escape(status)+'&vid='+escape(videoId)+'&comment_id='+escape(cmId)+'&level='+escape(replyLevel)+'&ctype='+type+'';
	
		/*	MAKE AJAX CALL TO POST NEW COMMENT	*/
		jQuery.ajax({
		   type: "POST",
		   url: pageName,
		   data: parameters,
		   success: function(msg){
			   	if(msg==1)
				{
					var txt_count='reply';
				}
				else
				{
					var txt_count='replies';
				}
				if(replyLevel=='one')
				{
					jQuery('#showReply_'+cmId).html(msg+' '+txt_count);
				}
				else
				{
					jQuery('#showReplyChild_'+cmId).html(msg+' '+txt_count);
				}
		   },
			error: function(){

			}
		 });
}
function enable_disable_chat(status)
{
	if(status=='enable')
	{
		
		
		jQuery('#standard_video_option').hide();
		//jQuery('#widescreen').show();
		jQuery('#widescreen_video_option').show();
		jQuery('#title_video_widescreen').show();
		jQuery('#embed_chat').show();
		jQuery('#videoCover').css({'background':'url('+IMAGE_PATH+'video_detail/video-bg-chat.png) no-repeat','height':'428px','width':'826px','padding-top':'10px','margin-top':'11px'});
		jQuery('#videoCover div object').attr('width','480');
		jQuery('#videoCover div object').attr('height','385');
		jQuery('#videoCover div embed').attr('width','480');
		jQuery('#videoCover div embed').attr('height','385');
		
		jQuery('#videoCover div#embed_chat embed').attr('width','323');
		jQuery('#videoCover div#embed_chat embed').attr('height','385');


	}
	else
	{
		jQuery('#standard_video_option').show();
		//jQuery('#widescreen').hide();
		jQuery('#widescreen_video_option').hide();
		jQuery('#title_video_widescreen').hide();
		jQuery('#embed_chat').hide();
		//jQuery('#videoCover').css({'background':'url('+IMAGE_PATH+'video_detail/video-bg.png) no-repeat','height':'389px','padding-top':'10px','clear':'both','width':'','padding-bottom':'16px','margin-top':'52px'});
		jQuery('#videoCover').css({'background':'url('+IMAGE_PATH+'video_detail/video-bg.png) no-repeat','height':'389px','padding-top':'10px','clear':'both','width':'','margin-top':'52px'});
		jQuery('#videoCover div object').attr('width','480');
		jQuery('#videoCover div object').attr('height','385');
		jQuery('#videoCover div embed').attr('width','480');
		jQuery('#videoCover div embed').attr('height','385');
	}
}


function update_embedChat(userId,status)
{
	var pageName = AJAX_PATH+'makerequest.php';
	
	var parameters = 'pname=video_detail&action=embedchat&status_chat='+status+'&user_id='+userId;
	
	//var resultDiv = 'rsltdiv2';	
		/*	MAKE AJAX CALL */
	jQuery.ajax({
		   type: "POST",
		   url: pageName,
		   data: parameters,
		   success: function(msg)
		   {
				if(status=='enable')
				{
					
					
					jQuery('#standard_video_option').hide();
					//jQuery('#widescreen').show();
					jQuery('#widescreen_video_option').show();
					jQuery('#title_video_widescreen').show();
					jQuery('#embed_chat').show();
					jQuery('#videoCover').css({'background':'url('+IMAGE_PATH+'video_detail/video-bg-chat.png) no-repeat','height':'428px','width':'826px','padding-top':'10px','margin-top':'11px'});
					jQuery('#videoCover div object').attr('width','480');
					jQuery('#videoCover div object').attr('height','385');
					jQuery('#videoCover div embed').attr('width','480');
					jQuery('#videoCover div embed').attr('height','385');
					
					jQuery('#videoCover div#embed_chat embed').attr('width','323');
					jQuery('#videoCover div#embed_chat embed').attr('height','385');
			
			
				}
				else
				{
					jQuery('#standard_video_option').show();
					//jQuery('#widescreen').hide();
					jQuery('#widescreen_video_option').hide();
					jQuery('#title_video_widescreen').hide();
					jQuery('#embed_chat').hide();
					//jQuery('#videoCover').css({'background':'url('+IMAGE_PATH+'video_detail/video-bg.png) no-repeat','height':'389px','padding-top':'10px','clear':'both','width':'','padding-bottom':'16px','margin-top':'52px'});
					jQuery('#videoCover').css({'background':'url('+IMAGE_PATH+'video_detail/video-bg.png) no-repeat','height':'389px','padding-top':'10px','clear':'both','width':'','margin-top':'52px'});
					jQuery('#videoCover div object').attr('width','480');
					jQuery('#videoCover div object').attr('height','385');
					jQuery('#videoCover div embed').attr('width','480');
					jQuery('#videoCover div embed').attr('height','385');
				}
		   }
		});
}


///////////////// related videos Javascript /////////////////////

//current_slide = 1;

function next(total_slide)
{
	if(current_slide == total_slide)
		current_slide = 1;
	else
		current_slide++;
	
	slide(current_slide,total_slide);
}

function prev(total_slide)
{
	if(current_slide == 1)
		current_slide = total_slide;
	else
		current_slide--;
	slide(current_slide,total_slide);
}

function slide(id,total_slide)
{
	if(id > total_slide || id < 1) return false;
	jQuery('a.selected').removeClass('selected');
	jQuery('#p'+id).addClass('selected');	
	
	var DivWidth = 382;
	var leftM = 0;
	//alert(ids[0]);
	if(id == 1)
	{
		leftM = 0;
	}
	else if(id == total_slide)
	{
		leftM = DivWidth*(total_slide-1);
	}
	else
	{
		leftM = DivWidth*(id-1);
	}		
	jQuery("#sliding_div").animate({ marginLeft: "-"+leftM+"px"}, 400 );		
}


function showPopIt(videoId)
{
		//jQuery('#textPop_'+videoId).css('display','block');
		jQuery('#textPop_'+videoId).fadeIn('fast');
}

function hidePopIt(videoId)
{
		//jQuery('#textPop_'+videoId).css({'display':'none'});
		jQuery('#textPop_'+videoId).fadeOut('fast');
}

function popItRelated(videoId,fb_publish,tw_publish)
{	
	/*	SET PARAMETER THAT WILL BE SENT TO AJAX	*/	
	if(fb_publish == null)
		fb_publish = 'no';

	if(tw_publish == null)
		tw_publish = 'no';
	
	jQuery('#popit_'+videoId).fadeOut();
	var requestURL=AJAX_PATH+'makerequest.php?pname=video_detail&action=popitRelated&value='+escape(videoId)+'&fb_publish='+fb_publish+'&tw_publish='+tw_publish+'&r=?';  
		   jQuery.getJSON(requestURL,
		function(msg){
			setTimeout(function(){
									jQuery('#popit_'+videoId).fadeIn();
									jQuery('#popit_'+videoId).html(msg['success']);
									jQuery('#popit_'+videoId).removeAttr('onClick');
									jQuery('#popit_'+videoId).addClass('popd');
									//jQuery('#popit_'+videoId).append('<em style="overflow: visible;">Pop\'d</em>');
								 },
								 600);
							jQuery('#'+videoId).unbind('mouseenter mouseleave');
				   });	
}

function relatedVideoLogin(relatedVideoId,param,curVideoId,slideId)
{
	var requestURL=AJAX_PATH+'makerequest.php?pname=video_detail&action=relatedVideoInfo&value='+escape(relatedVideoId)+'&r=?';  
	var pageName = AJAX_PATH+'makerequest.php';
	var parameters = 'pname=video_detail&action=relatedVideoInfo&relatedVideoId='+relatedVideoId+'&param='+param+'&curVideoId='+curVideoId+'&slideId='+slideId;
		jQuery.ajax({
		   			type: "POST",
		   			url: pageName,
		   			data: parameters,
		   			success: function(msg)
		   			{
						jQuery('#video-related').html(msg);
					}
		});
}
