/**
 * Author : Nazrol - dev@nazsoftware.com
 * Date : 16/1/2011
 * Description : HelpSlider class
 */

function HelpSlider(args){
    var _this = this;

    this.FULL_WIDTH = 904; // Show full document
    this.HALF_WIDTH = 220; // Show only category

    this.isOpened = false;
    this.button = args.button;
    this.container = args.container;
    this.innerCloseButton = args.innerCloseButton;


    $(this.button).bind('click', {caller:this}, function(e){
        if(_this.isOpened){
            _this.close();
            _this.isOpened = false;
        }else{
            _this.show(2);
            _this.isOpened = true;
        }

    });

    // Category menu
    $(this.container+' ul.help-category li').click(function(){
        //alert($(this).children('a').attr('href'));

        _this.show(1);
        $(_this.container+' div.help-content-container div.help-content-content').css('height',($('#content-container').height()-200)+'px');
        $(_this.container+' div.help-content-container').show();

        $(_this.container+' div.help-content-container div.help-content-content').load($(this).children('a').attr('href'));

        return false;
    });

    $(this.innerCloseButton).click(function(){
        _this.close();
        _this.isOpened = false;
    });

    this.init();
}

HelpSlider.prototype.init = function(){
    $(this.container).bind(
        'load-category', this.loadCategory
    );


}

HelpSlider.prototype.loadCategory = function(e,data){
   categoryContent = $(data.container+ ' div.help-category-container div.help-category-content').show();
   containerHeight = $(data.container).height();

   $(categoryContent).height(containerHeight-40);
}

HelpSlider.prototype.close = function(){

   $(this.container+' div.help-content-container').hide();
   $(this.container+ ' div.help-category-container div.help-category-content').hide();
   $(this.container).css('border','none');

   if($.browser.msie){ // Problem with ie when using resize effect
       $(this.container).css('width', '0px');
   }else{
        $(this.container).effect("size", {to: {width: 0}, origin:['top','right']}, 200);
   }

	$(this.container).trigger('close');
}

HelpSlider.prototype.show = function(mode){
	
	$(this.container).trigger('show');


   if(mode == 1){//Full
       $(this.container).css('width', this.FULL_WIDTH+'px');

   }else{
       $(this.container).css('width', this.HALF_WIDTH+'px');
   }

   $(this.container).css('height',($('#content-container').height()-160)+'px');

   $(this.container).css('border','solid 1px #b8da7a');
   $(this.container).show(
       "slide",{direction: 'right'},200
   );
   $(this.container).trigger('load-category', {container:this.container});
}



