(function(jq){
	jq.fn.moods=function(){
		function resizeImgs() {
			var imgs      = jq('#mood').find('img');
			var winwidth  = jq(window).width();
			var winheight = jq(window).height();
					
			if(winwidth>0 && winheight>0)
			{
				imgs.each(function(){
					var imgwidth    = jq(this).width();
					var imgheight   = jq(this).height();
					var widthratio  = winwidth / imgwidth;
					var heightratio = winheight / imgheight;
					var widthdiff   = heightratio * imgwidth;
					var heightdiff  = widthratio * imgheight;
					if(heightdiff>winheight) { jq(this).css({ width: winwidth+'px', height: heightdiff+'px' }); }
					else                     { jq(this).css({ width: widthdiff+'px', height: winheight+'px' }); }
				});
			}
		} 
		
		
		if (jq("#cms_toolbar_edit_button_on").length) {
		    var mood = jq("#mood") ; 
		    mood.css("display", "none") ; 
        }
        
        var setHeight = function () {
            var _top = jq('#header').height()+1;
            var _bottom = jq('#menu_main').height();
            var _height = jq(window).height() - _top - _bottom;
            jq('#main_content').css({
                'top':_top + 'px',
                'height':_height + 'px'
            });
        }
        
        if(jq('#mood').find('img').length>1)
        {
            var t_out;
            var images = jq('#mood').find('img');
            var now    = 0;
            var max    = images.length - 1;
            var anim = function () {
                jq(images[now]).fadeOut(1500); 
                now = now<max ? now+1 : 0; 
                jq(images[now]).fadeIn(1500);
                t_out = window.setTimeout(anim, 5000);
            }
            t_out = window.setTimeout(anim, 5000);
        }
		
        return this.each(function(){
            jq(window).resize(function(){ resizeImgs(); setHeight(); });
	    	resizeImgs();
	    	setHeight();
	    });
	}
})(jQuery);
