 $(document).ready(function() {
	/* rate popup */
	$('.v-item .dorate').click(function() {                
		pop = $('#rate-popup');
		pop.hide();
		$(this).parent().parent().append(pop);
		pop.fadeIn('fast');                
	});
	$('#rate-popup .btclose').click(function() {$('#rate-popup').fadeOut('fast')});
	$('#rate-popup .user-rating a').click(function() {            
		var point=0;
		switch ($(this).attr('class')) {
			case 'one-star':point=1;break;
			case 'two-stars':point=2;break;
			case 'three-stars':point=3;break;
			case 'four-stars':point=4;break;
			case 'five-stars':point=5;
		}
		//do something with point here
                var ul = $(this).parent().parent();
                var userid = ul.attr('id');
                var videoid = ul.parent().parent().attr('id');                
                ajax.DoRating(videoid, userid, point);		
		$('#rate-popup').fadeOut('fast');
		
	});

        //process in detailvideo page
        $('.action .cmt').click(function() {            
		pop = $('#rate-popup');                		
		pop.fadeIn('fast');
	});        
        
	/* search option */
	$('#btsearch-opt-top').click(function() {$('#search-pop-btm').hide();$('#search-pop-top').fadeIn('fast');});
	$('#btsearch-opt-btm').click(function() {$('#search-pop-top').hide();$('#search-pop-btm').fadeIn('fast');});
	$('.search-pop a').click(function() {$('.search-pop').hide();});
	$('body').click(function() {$('.search-pop').hide();});
	//emoticons
	$('.emo-list a').click(function() {
                var txtControl = document.getElementById("txtComment");
                if (txtControl.value.length + $(this).attr('id').length < 1000)
                {
                    txtControl.value += $(this).attr('id');
                    txtControl.focus();
                    document.getElementById("spCount").innerHTML = 1000 - txtControl.value.length;
                }                		
		$('#emo-pop').fadeOut('fast')
	});
	
 });

 function showEmoticonPop() {
	pop = $('#emo-pop');
	if (pop.css('display') == 'none') 
		pop.fadeIn('fast');
 }

function GotoForum()
{        
    //window.open("http://forum.vstar.tv");
}
function AddVideoToMyChannelCallback(sourceImageId)
{
    var target = document.getElementById(sourceImageId);
    if (target != null) target.className = "addfav";
}
function AddVideoToMyChannel(userid, videoid, sourceImageId)
{
    if (userid == null || videoid == null) return;
    var target = document.getElementById(sourceImageId);
    if (target != null) target.className = "addingfav";
    ajax.AddVideoToMyChannel(userid,videoid, sourceImageId, AddVideoToMyChannelCallback);
}

function RemoveVideoFromMyChannel(userid, videoid)
{
    if (userid == null || videoid == null) return;    
    ajax.RemoveVideoFromMyChannel(userid,videoid);
    var video = document.getElementById(videoid);
    if (video != null)
    {
        var parent = video.parentNode;
        if (parent != null) parent.removeChild(video);
    }
}
function DownloadCount()
{
    ajax.DownloadCount();
}
function DisableOnSubmit(target)
{
    target.disabled = true;
}
function ShowPlay(me)
{    
    var parent = me.parentNode;    
    var spanElement = document.getElementById("playbutton");    
    spanElement.parentNode.removeChild(spanElement);    
    parent.appendChild(spanElement);    
    spanElement.style.display = "";
}
function HidePlay()
{
    var spanElement = document.getElementById("playbutton");
    spanElement.style.display = "none";
}
function DoSearch(me, option)
{     
    if (document.getElementById(option).className == 'active')
    {
        me.action += '?option=' + 'video';
    }
    else
    {
        me.action += '?option=' + 'actor';
    }
}
function SearchOption(me, nextid)
{
    me.className = "active";
    var next = document.getElementById(nextid);
    if (next != null)
    {
        next.className = "last";
    }
}
function SearchOptionClick(evt)
{
    evt.cancelBubble = true;
}
function Register()
{
    var element = document.getElementById("submit");
    if (element != null) element.disabled = true;
    element =  document.getElementById("username");
    if (element != null) element.readOnly = true;
    element = document.getElementById("pass");
    if (element != null) element.readOnly = true;
    element = document.getElementById("repass");
    if (element != null) element.readOnly = true;
    element = document.getElementById("email");
    if (element != null) element.readOnly = true;
    element = document.getElementById("reemail");
    if (element != null) element.readOnly = true;
    element = document.getElementById("confirmcode");
    if (element != null) element.readOnly = true;
    element = document.getElementById("progressreg");
    if (element != null) element.style.display = "";
}