/* These two prototypes fix IE font rendering when the user has cleartype switched on. */
jQuery.fn.fadeIn = function(speed, callback) { 
    return this.animate({opacity: 'show'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeOut = function(speed, callback) { 
    return this.animate({opacity: 'hide'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
};

var animations = {
    
    oldWidth: 0,
    heightFixed: false,
    
    slideIn: function(){
        
        animations.stopAll();
        
        this.oldWidth = $("#content-wrapper").width();
        
        if(animations.heightFixed==false){
            animations.heightFixed = true;
            animations.fixHeight();
        }
        
        $("#content").fadeOut(1000, function(){
            if($.browser.msie && ($.browser.version.substring(0,1) == '7' || $.browser.version.substring(0,1) == '8')){
                animations.zeroPadding();
            }
            
            $("#content-wrapper").animate({
                width: "0",
                paddingLeft: "0",
                paddingRight: "0"
            }, 1000,
            function(){
                $(".js-tab>img").attr('src', 'uploads/images/show-me-img.gif');
            });
        });
    },
    
    slideOut: function(){
        animations.stopAll();
        
        $("#content-wrapper").animate({
            width: this.oldWidth,
            paddingLeft: "35px",
            paddingRight: "35px"
        }, 1000,
        function(){
            if($.browser.msie){
                animations.resetPadding();
            }
            $("#content").fadeIn(1000, function(){
                $(".js-tab>img").attr('src', 'uploads/images/hide-me-img.gif');
            });
        });
    },
    
    fixHeight: function(){
        var newHeight = $("#content-wrapper").height();
        
		if($.browser.msie && $.browser.version.substring(0,1) == 6){
			newHeight = newHeight;
		}else if($.browser.msie){
            newHeight = newHeight + parseInt($('#content-wrapper').css('paddingTop')) + parseInt($('#content-wrapper').css('paddingBottom'));
        }
        
        $("#content-wrapper").height(newHeight + "px");
    },
    
    zeroPadding: function(){
        $("#content-wrapper").css("paddingTop", "0").css("paddingBottom", "0");
    },
    
    resetPadding: function(){
         $("#content-wrapper").css("paddingTop", "35px").css("paddingBottom", "35px");
    },
    
    stopAll: function(){
        $("#content-wrapper").stop();
        $("#content").stop();
    }
};

ie6 = {
    bodge: function(parent, child){
        var childHeight = $(child).height();
        $(parent).height(childHeight);
    }
};

$(function(){
    $(".js-tab>img").toggle(animations.slideIn, animations.slideOut);
    
    if($.browser.msie && $.browser.version.substring(0,1) == 6){
        ie6.bodge($('#content-wrapper'), $('#content'));
    }
    
});