$(document).ready(function(){

	// Print button
	$(".printer").click(function(){
		window.print();
		return false;
	});

	// Close parent
	$(".close_parent").click(
			function () {
				$(this).parent().fadeTo(400, 0, function () { // Links with the class "close" will close parent
					$(this).slideUp(400);
				});
				return false;
			}
		);
		
		
	// Username input replace
	$('input.username_onfocus').focus(function(){
		
		if($(this).val() == "Username")
		{
			$(this).val("");
		}
		
	});
	$('input.username_onfocus').blur(function(){
		
		if($(this).val() == "")
		{
			$(this).val("Username");
		}
		
	});
	
	
	// Password input replace
	$('input.password_onfocus_text').show();
	$('input.password_onfocus').hide();
	
	$('input.password_onfocus_text').focus(function() {
	    $('input.password_onfocus_text').hide();
	    $('input.password_onfocus').show();
	    $('input.password_onfocus').focus();
	});
	$('input.password_onfocus').blur(function() {
	    if($('input.password_onfocus').val() == '') {
	        $('input.password_onfocus_text').show();
	        $('input.password_onfocus').hide();
	    }
	});
	
	
	// forms accordion
	$(".category_collapse").hover(function() {
						$(this).addClass('over_state');
				    	}, function() {
				    	$(this).removeClass('over_state');
				    });
				    
	$(".category_collapse").click(function(){
		var checkElement = $(this).next("div");
		if(checkElement.is(':visible'))
		{
			return false;
		}
		else
		{
			$(this).parent().find(".category_collapse").removeClass('current_state');
			$(this).parent().find(".category_collapse").next("div:visible").slideUp("normal");
			checkElement.slideDown("normal");
			$(this).addClass('current_state');
			return false;
		}
	});

});

// Toggle Fade
(function($) {
  $.fn.toggleFade = function(settings)
  {
  	if(settings==undefined) {
			settings={ speedIn : 'slow'};
		}
  	settings = jQuery.extend(
  		{
        speedIn: "normal",
        speedOut: settings.speedIn
  		}, settings
  	);
  	return this.each(function()
  	{
  	  var isHidden = jQuery(this).is(":hidden");
      jQuery(this)[ isHidden ? "fadeIn" : "fadeOut" ]( isHidden ? settings.speedIn : settings.speedOut);
    });
  };
})(jQuery);
