/**
 *  SHOW MORE COMMENTS
 *  ---------------------------------------------------------------------------- 
 */ 
var showCommentsPage = new Array();
function showMoreComments(id_holder, nID, total_overall){

  $button = $("#comments_button_" + id_holder);
  $button.empty();
  $button.append("<center><img src='resources/template/css/images/news_feed_loading.gif' /></center>");
  
  
  if (showCommentsPage[id_holder] != null)
  { 
    showCommentsPage[id_holder] = showCommentsPage[id_holder] + 1;
  } else {
    showCommentsPage[id_holder] = 2;
  }
  
  if ((showCommentsPage[id_holder] - 1)* 5 > total_overall)
  {
    doFaceBox("There are no more comments.");
    $button.empty();
    $("#comments_button_container_" + id_holder).hide();    
    return; 
  }
  
  $.post("lib/Bumpley/Bumpley_Ajax.php", {
      where:"p_c",
      value:nID,
      page:showCommentsPage[id_holder]
    },

    function(data)
    {
      if (data.response)
      {
        $new_id = $.random(10000);
        $container = $("#comment_appender_"+id_holder);
        $container.append("<div id='new_comment_container_"+id_holder+"_"+$new_id+"' style='display: none;'>"+data.html+"</div>");        
        $("#new_comment_container_"+id_holder+"_"+$new_id).slideDown();
          
        if (showCommentsPage[id_holder] * 5 > total_overall)
        {
          $("#comments_button_container_" + id_holder).hide();
        } else {
          $button.empty();
          $button.append("show more");
        }  
      } else {
        $button.empty();
        $button.append("show more");        
        return false;
      }      
    },
    
    "json"
  );
}

/**
 *  end of SHOW MORE COMMENTS
 *  ---------------------------------------------------------------------------- 
 */ 

function showNotifications()
{
  $login_form = $('#notifications');
  if ($login_form.is(":hidden")){
    //$login_form.show("slide", {direction: "up"});
    $login_form.slideDown();
  } else {
    $login_form.hide();
  }
}

function showLogin()
{
  $login_form = $('#header_login');
  if ($login_form.is(":hidden")){
    //$login_form.show("slide", {direction: "up"});
    //$login_form.slideDown();
  } else {
    $login_form.hide();
  }
}


function toggleDisplay(holder){
  var animate = true;
  $container = $('#' + holder);
  if ($container.is(":hidden")){
    if (animate){
      $container.slideDown();
    } else {
      $container.show();
    }
  } else {
    if (animate){
      $container.slideUp();
    } else {
      $container.hide();
    }
  }  
}

function updateNotifyCounter()
{
  $.post("lib/Profile/profile_ajax.php", {
      where:"u_nc"
    },

    function(data){
      //
    }
  );  
}


function toggleComments()
{
  var animate = false;
  $login_form = $('.comments_container');
  $toggle_button = $('#toggle_comments');
  
  if ($login_form.is(":hidden")){
    /**
     *  SHOW
     */         
    if (animate){
      $login_form.slideDown();
    } else {
      $login_form.show();
    }
    $toggle_button.empty();
    $toggle_button.append("Hide Comments");
    
    $.cookie('hide_comments', null, {path: "/"});
    //alert("Should be Null: " + $.cookie('hide_comments'));
    
  } else {
    /**
     *  HIDE
     */         
    if (animate){
      $login_form.slideUp();
    } else {
      $login_form.hide();
    }
    $toggle_button.empty();
    $toggle_button.append("Show Comments");
      
    $.cookie('hide_comments', true, {path: "/"});
    //alert("Should be True: " + $.cookie('hide_comments'));
  }
}


function toggleBody()
{
  var animate = false;
  $login_form = $('.submission_body');
  $toggle_body = $('#toggle_body');
  
  if ($login_form.is(":hidden")){
    if (animate){
      $login_form.slideDown();
    } else {
      $login_form.show();
    }
    $toggle_body.empty();
    $toggle_body.append("Hide Body");
    
    $.cookie('hide_body', null, {path: "/"});
    //alert("Should be Null: " + $.cookie('hide_body'));
    
  } else {
    if (animate){
      $login_form.slideUp();
    } else {  
      $login_form.hide();
    }
    $toggle_body.empty();
    $toggle_body.append("Show Body");
        
    $.cookie('hide_body', true, {path: "/"});
    //alert("Should be true: " + $.cookie('hide_body'));
  }
}

$(document).ready(function()
{
  /**
   *  check cookies
   */
  if ($.cookie('hide_body') != null)
  {
    $toggle_body = $('#toggle_body');
    $toggle_body.empty();
    $toggle_body.append("Show Body");
    $('.toggle_body').show();
    $('.submission_body').hide();
  }
  
  if ($.cookie('hide_comments') != null)
  {
    //alert('hide comments');
    $toggle_button = $('#toggle_comments');
    $toggle_button.empty();
    $toggle_button.append("Show Comments");
    $('.toggle_comments').show();
    $toggle_body = $('#toggle_body');
    $('.comments_container').hide();
  }      
   
  
  /**
   *  nice menu
   *  
   */             
	$('#nicemenu img.arrow').click(function()
  { 							
		$('span.head_menu').removeClass('active');
		submenu = $(this).parent().parent().find('div.sub_menu');
		
		if(submenu.css('display')=='block')
    {
			$(this).parent().removeClass('active');
      
      if ($.browser.msie){  
        submenu.hide();
      } else { 	
			   submenu.hide();
      } 		
      
			$(this).attr('src','resources/template/css/images/menu/arrow_hover.png');									
		}else{
			$(this).parent().addClass('active');
      if ($.browser.msie){
        //submenu.slideDown("fast");
        submenu.show();
      } else { 	
			 submenu.slideDown("fast");
			 //submenu.show();
      } 		
			$(this).attr('src','resources/template/css/images/menu/arrow_select.png');	
		}
		
		$('div.sub_menu:visible').not(submenu).hide();
		$('#nicemenu img.arrow').not(this).attr('src','resources/template/css/images/menu/arrow.png');	
	})
	
	.mouseover(function(){ $(this).attr('src','resources/template/css/images/menu/arrow_hover.png'); })
	.mouseout(function(){ 
		if($(this).parent().parent().find('div.sub_menu').css('display')!='block'){
			$(this).attr('src','resources/template/css/images/menu/arrow.png');
		}else{
			$(this).attr('src','resources/template/css/images/menu/arrow_select.png');
		}
	});

	$('#nicemenu span.head_menu').mouseover(function(){ $(this).addClass('over')})
								 .mouseout(function(){ $(this).removeClass('over') });
	
	$('#nicemenu div.sub_menu').mouseover(function(){ $(this).fadeIn(); })
							   .blur(function(){ 
							   		$(this).hide();
									$('span.head_menu').removeClass('active');
								});		
								
	$(document).click(function(event){ 		
			var target = $(event.target);
			if (target.parents('#nicemenu').length == 0) {				
				$('#nicemenu span.head_menu').removeClass('active');
				$('#nicemenu div.sub_menu').hide();
				$('#nicemenu img.arrow').attr('src','resources/template/css/images/menu/arrow.png');
			}
	});						   
});