	var v_comment = '';
    var v_id = user_id;
    $(document).ready(function() {
		if (show_id > 0) { 		
        i = 1;
        v_id = show_id;
        v_comment = 'show_'; 
        // user rated
        if ( typeof(user_rated) == 'undefined' ) 
            user_rated = 0;
        
        if ( user_rated > 0 ) {
            user_rated = parseInt( user_rated );
            
            tmp = 1;
            $('img[rel="vote_img"]').each(function() {
                if ( tmp <= user_rated  ){
                    $(this).attr('src', www_root + 'public/images/star_white_full.png' );
                    tmp++;
                }
            });
        }else{
            // vote images
            $('img[rel="vote_img"]').each(function() {
                $(this).attr('id', i );
                i++;
                
                // on mouse over
                $(this).mouseover(function(){
                    id = $(this).attr('id');
                    for ( j = 1 ; j <= id ; j++ ) {
                        $('img[id="' + j + '"]').attr('src', www_root + 'public/images/star_white_full.png' );
                    }
                });
                // on mouse out
                $(this).mouseout(function(){
                    id = $(this).attr('id');
                    for ( j = 1 ; j <= id ; j++ ) {
                        $('img[id="' + j + '"]').attr('src', www_root + 'public/images/star_white_empty.png' );
                    }
                });
                
                // on click, save the vote
                $(this).click(function(){
                    no_history_server_post( { m : 'vote_show' , n : $(this).attr('id') , id : show_id } , user_voted );
                });
            });
                            
        }
        
        // show / hide videos
        $('#vid_hid_trigger').click(function(){
            $('[rel=vid_hid]').toggle();
            
            rel = $('#vid_hid_trigger').attr('rel');
            $('#vid_hid_trigger').attr( 'rel', $('#vid_hid_trigger').text() );
            $('#vid_hid_trigger').text( rel );
            
            return false;
        });
        
        $('#flag_reason_trigger').click(function(){
            $('#flag_reason').toggle();
            return false;
        });
        
        $('#flag_send').click(function(){
            no_history_server_post( { m : 'flag_show', id : $('[name=flag_reason]').val(), show_id:show_id }, user_flaged );
        });
        
        $('#bbutyes').click(function(){ $('#bbut_frm').submit(); return false;});
        $('#bbutno').click(function(){ $('#bbut').show(); $('#buy_confirm').hide();    return false;});
        $('#bbut').click(function(){ $(this).hide(); $('#buy_confirm').show('fast');return false;});
        
        $('#all_videos').click(function()    {
            $("a[name=videoHiddenClass]").show();
            $(this).toggle();
            $('#few_videos').toggle();
            return false;
        });
        $('#few_videos').click(function(){
            $("a[name=videoHiddenClass]").hide();
            $(this).toggle();
            $('#all_videos').toggle();
            return false;
        });
        
        }
        // new comment
        /*$('#add_new_comment').click(function(){
            if ( $('#new_comment').val() == '' )
                display_error( 'Please write a comment.' );
            else{
                $('#comments_loader').show();
                no_history_server_post( { m : 'add_show_comment', comment : $('#new_comment').val() , id : v_id } , add_show_comment );
                $('#comments_loader').hide();
            }
            return false;
        });  */
        
        // follow
        $('#follow').click(function(){
            no_history_server_post( { m : 'follow', action : 'follow', id : show_id }, follow_callback );
            return false;
        });
        $('#stop_follow').click(function(){
            no_history_server_post( { m : 'follow', action : 'stop_follow', id : show_id }, stop_follow_callback );
            return false;
        });
            		
		$('#all_pics').click(function()	{
			$("a[name=imgHiddenClass]").show();
			$(this).toggle();
			$('#few_pics').toggle();
			return false;
		});
		$('#few_pics').click(function(){
			$("a[name=imgHiddenClass]").hide();
			$(this).toggle();
			$('#all_pics').toggle();
			return false;
		});
		
		$('#all_videos').click(function()	{
			$("a[name=videoHiddenClass]").show();
			$(this).toggle();
			$('#few_videos').toggle();
			return false;
		});
		$('#few_videos').click(function(){
			$("a[name=videoHiddenClass]").hide();
			$(this).toggle();
			$('#all_videos').toggle();
			return false;
		});
		
		$('#friends_view_all').click(function()	{
			$("#my_friends > div.hiddenClass").show();
			$(this).toggle();
			$('#friends_few_pics').toggle();
			return false;
		});
		$('#friends_few_pics').click(function(){
			$("#my_friends > div.hiddenClass").hide();
			$(this).toggle();
			$('#friends_view_all').toggle();
			return false;
		});
        
        // new comment
        $('#add_new_comment').click(function(){
            v = $('#new_comment').val();
            if ( $('#new_comment').val() == '' )
                display_error( 'Please write a comment.' );
            else if ( v.length > 500 )
                display_error( 'Comment length must have MAXIMUM 500 chars.' );
            else{
                $('#comments_loader').show();
                no_history_server_post( { m : 'add_'+v_comment+'comment', comment : $('#new_comment').val() , id : v_id } , add_comment );
                $('#comments_loader').hide();
            }
            return false;
        });
        
        $('#new_comment').keyup(function(){
            v = $(this).val(); x = v.length; 
            if ( x < 1 ) x = '0';
            $('#no_chars').html(x);
        });
		
		// show / hide videos
		$('#vid_hid_trigger').click(function(){
			$('[rel=vid_hid]').toggle();
			
			rel = $('#vid_hid_trigger').attr('rel');
			$('#vid_hid_trigger').attr( 'rel', $('#vid_hid_trigger').text() );
			$('#vid_hid_trigger').text( rel );
			
			return false;
		});
		
	});

	// adds a comment to the comment section of the show, and refreshes the comments
	function add_comment( data )
	{
		if ( data['err'] )
			display_error( data['err'] );
		else {
			build_comments( 1 );
			$('#new_comment').val('');
		}
	}
	
	$(document).ready(function() {
		build_comments( page );
	});
	
	// build comments section
	function build_comments( lpage )
	{
		page = lpage;
		
		$('#comments').hide().empty().show().append( loader() );
		if (show_id > 0)  {
		no_history_server_post( { m : 'build_'+v_comment+'comments' , page : lpage ,  show_id : v_id } , function( data ) {
			if ( data['err'] ) {
				display_error( data['err'] );
			}else if ( data['server'] &&  data['server']['comments'] ){
				
				$('#comments').hide().empty().append( data['server']['pagination'] );
				$('#comments').append( clearer(10) ).append( data['server']['comments'] ).append( data['server']['pagination'] ).show();
				
				
			}
		} );
        } else {
        no_history_server_post( { m : 'build_'+v_comment+'comments' , page : lpage ,  user_id : v_id } , function( data ) {
            if ( data['err'] ) {
                display_error( data['err'] );
            }else if ( data['server'] &&  data['server']['comments'] ){
                
                $('#comments').hide().empty().append( data['server']['pagination'] );
                $('#comments').append( clearer(10) ).append( data['server']['comments'] ).append( data['server']['pagination'] ).show();
                
                
            }
        } );
        }
		$('#comments_loader').hide();
	}
	
    function build_show_comments( lpage )
    {
        page = lpage;
        
        $('#comments').hide().empty().show().append( loader() );
        if (show_id > 0)  {
        no_history_server_post( { m : 'build_'+v_comment+'comments' , page : lpage ,  show_id : v_id } , function( data ) {
            if ( data['err'] ) {
                display_error( data['err'] );
            }else if ( data['server'] &&  data['server']['comments'] ){
                
                $('#comments').hide().empty().append( data['server']['pagination'] );
                $('#comments').append( clearer(10) ).append(data['server']['comments'] ).append( data['server']['pagination'] ).show();
                
                
            }
        } );
        }
        $('#comments_loader').hide();
    }
	
	function delete_comment(id)
	{
		if ( confirm('Are you sure you want to delete this comment ? ') ) {
			no_history_server_post( { m:'delete_'+v_comment+'comment', id:id },function() {
				build_comments( page );
			});
		}
		return false;
	}
	
    // follow
    function follow_callback( data ) {
        if ( data['err'] ){
            display_error( data['err'] );
        }else{
            $('#follow_div').hide();
            $('#stop_follow_div').show();
        }
    }
    function stop_follow_callback( data ) {
        if ( data['err'] ){
            display_error( data['err'] );
        }else{
            $('#follow_div').show();
            $('#stop_follow_div').hide();
        }
    }
    
    // the user has flaged a show. change the page .. .
    function user_flaged( data )
    {
        if ( data['err'] )
            display_error( data['err'] );
        else {
            // do html changes
            //$('#flag_reason_trigger').remove();
            $('#flag_reason').empty().append('Thank you for your interest.');
        }
    }
    
    // the user has voted. change the page .. .
    function user_voted( data )
    {
        if ( data['err'] )
            display_error( data['err'] );
        else {
            // do html changes
            $('div.img_show_rate').empty().append( data['server']['images'] );
            $('#img_your_rate').empty().append('Thank you for your vote.');
        }
    }
    
    function showJustStarted(){
        $('#schdule_annonce').next().hide();
        $('#schdule_annonce').hide();
    }
	
	