/**
 * Tools for toggling title-content/container visibility/display and
 * status handling
 *
 * Required element structure:
 * <xx>
 *  <h3>##title##</h3>
 *  <yy class='content'></yy>
 * </xx>
 */

jQuery.fn.hideContent = function(mode,callback){

    var afterFinish = (callback)?callback:function(){};
    var speed = (callback)?'fast':'slow';

    switch(mode){
        case 'fade' :this.children('.content').fadeOut(speed,afterFinish);break;
        case 'slide':this.children('.content').slideUp(speed,afterFinish);break;
        default: this.children('.content').hide();break;
    }

}

jQuery.fn.showContent = function(mode,callback){

    var afterFinish = (callback)?callback:function(){};
    var speed = (callback)?'fast':'slow';

    switch(mode){
        case 'fade' :this.children('.content').fadeIn(speed,afterFinish);break;
        case 'slide':this.children('.content').slideDown(speed,afterFinish);break;
        default: this.children('.content').show();break;
    }

}

jQuery.fn.setTitle = function(title){
    this.children('h3').html(title);
}

jQuery.fn.setContent = function(content){
    this.children('.content').html(content);
}

jQuery.fn.enable = function(){
    if(this.hasClass('disabled'))
        this.removeClass('disabled');
    this.addClass('enabled');
}

jQuery.fn.disable = function(){
    if(this.hasClass('enabled'))
        this.removeClass('enabled');
    this.addClass('disabled');
}


jQuery.fn.showLoader = function(){

	var loader = $(this).find('.ajax_loader');
	
	if( loader.length!= 0 )
		return

	title = $(this).find('h3');
	var loader = $('<img src="images/ajax_loader.gif" class="ajax_loader">');
	loader.css('margin-left','5px');
	title.append(loader);
}

jQuery.fn.hideLoader = function(){
	var loader = $(this).find('.ajax_loader');
	
	if(loader.length > 0)
		loader.remove();
}
