/* DEV. en cours */
/*- Constructor -------------------------*/
/* @container - container HTML de la TBox -------------------------------------------*/
/* @heightRef - container HTML reference pour calcul hauteur totale de la page ------*/
/* @minWidthRef - container HTML reference pour calcul largeur minimum de la page ---*/
function TTK_tBox(container, heightRef, minWidthRef){
    this.container = $(container);
	this.content = $('.tBox_content', this.container)[0];
	this.reference = $(heightRef);
	this.minWidthRef = $(minWidthRef);
	this.isShow = false;
	this.initialize();
}

/*- Initialisation : ajout des gestionnaires events -----*/	
TTK_tBox.prototype.initialize = function(){
    this.setHandlers();	    
};

/*- Set les gestionnaires events pour la tBox -----------*/
TTK_tBox.prototype.setHandlers = function(){
    var that = this;
    //resize du navigateur
	$(window).resize(function(e){
	    if(that.isIE6) that.setSizes();
	    that.setPositions();        
	});
	
	//scroll du navigateur - uniquement IE6 (fixed position)
	$(window).scroll(function(e){
       if(!that.isIE6) return; 
       that.setSizes();
       that.setPositions();	         
	});	    
	
	//btn de fermeture de la tBox
	var btnClose = $('.tBox_btn_close', this.container);
	$(btnClose).click(function(e){
	    that.hide();
	});	    	    
};

/*- Calcule les positions de la tBox ---------------*/
TTK_tBox.prototype.setPositions = function(){
    if(this.isIE6()) $(this.content).css('position', 'absolute');
	var width = $($('html')[0]).width();	
	var contentWidth = ($(this.content).width() > 0)? $(this.content).width() : $(this.content).css('width').replace('px','');
	if(isNaN(contentWidth)){
	    var firstChild = $('div', this.content)[0];
	    var contentWidth = ($(firstChild).width() > 0)? $(firstChild).width() : $(firstChild).css('width').replace('px','');
    }	
	var xPosition = (width - contentWidth) / 2;
	var height = $($('html')).height();
	if(firstChild) var contentHeight = ($(firstChild).height() > 0)? $(firstChild).height() : $(firstChild).css('height').replace('px','');
	else var contentHeight = ($(this.content).height() > 0)? $(this.content).height() : $(this.content).css('height').replace('px','');
	var scrollTop = (this.isIE6())? $('html')[0].scrollTop : 0;	    
	var yPosition = Math.floor((height - contentHeight) / 2);
	$(this.content).css('left', (xPosition > 0)? xPosition : 0 + 'px');
	$(this.content).css('top', (yPosition - 25 > 0)? (yPosition + scrollTop) - 25 : 0 + 'px');
};

/*- Calcul la taille de la tBox - Uniquement pour IE6 ------*/
TTK_tBox.prototype.setSizes = function(){
   if(!this.isIE6()) return;
   var width = $($('html')[0]).width() - 17;
   var minWidth = $(this.minWidthRef).width();
   width = (minWidth > width)? minWidth : width;
   var height = $('html')[0].scrollHeight;
   $(this.container).css('width', width + 'px');
   $(this.container).css('height', height + 'px');  
};
	
/*- Affiche la tBox -------------------------*/
TTK_tBox.prototype.show = function(){
    if(this.isIE6()) this.setSizes();
	this.setPositions();
	if(!$.browser.msie){
	    var that = this;
	    $(this.container).fadeIn('fast', function(){
	        that.isShow = true;
	    });
	}
	else {
	    this.disabledSelect();
	    $(this.container).css('display', 'block');
	    this.isShow = true;
	}
};
	
/*- Masque la tBox -------------------------------*/
TTK_tBox.prototype.hide = function() {
	if (this.isIE6()) {
		$($('html')[0]).css('height', '100%');
		$($('html')[0]).css('overflow', 'auto');
	}
	if (!$.browser.msie) {
		var that = this;
		$(this.container).animate({ opacity: 0 }, { duration: 'fast', complete: function() {
			$(this).css({ display: 'none', opacity: 1 });
			that.isShow = false;
		}});
	}
	else {
		$(this.container).css('display', 'none');
		this.enabledSelect();
		this.isShow = false
	}
};

/*- Check si IE6 est navigateur client -----------------*/
/* @return : true si IE6 est le navigateur client ------*/
TTK_tBox.prototype.isIE6 = function(){
    if($.browser.msie){
        return ($.browser.version < 7)? true : false;
	}
	else return false;
};

/*- Supprime les select de la page courant - Hack IE6 -----------------*/
TTK_tBox.prototype.disabledSelect = function(){
   if(!this.isIE6()) return; 
   var selects = $('select', document);
   $(selects).css('visibility', 'hidden');
};

/*- Supprime les select de la page courant - Hack IE6 -----------------*/
TTK_tBox.prototype.enabledSelect = function(){
   if(!this.isIE6()) return; 
   var selects = $('select', document);
   $(selects).css('visibility', 'visible');
};

