(function($) {
 
	$.fn.getWindowSize = function() {
		var size = {width:0,height:0};
		if (typeof(window.innerHeight) == 'number')
		{
			size.height = window.innerHeight;
			size.width = window.innerWidth;
		}
		else 
			if (document.documentElement && document.documentElement.clientHeight)
			{
				size.height = document.documentElement.clientHeight;
				size.width = document.documentElement.clientWidth;
			}
			else
				if (document.body && document.body.clientHeight)
				{
					size.height = document.body.clientHeight;
					size.width = document.body.clientWidth;
				}
		return size;
	}

	$.fn.fixedFoot = function(settings) {
		var conf =  $.extend({content:false,marginBottom:0}, settings);
	
		var windowHeight = $.fn.getWindowSize().height;
		if (windowHeight > 0) {
			var contentHeight = conf.content?$(conf.content).outerHeight():0;
			var footerHeight  = this.outerHeight();
			if (conf.content && windowHeight - (contentHeight + footerHeight) >= 0) {
				this.css({position:'absolute',bottom:conf.marginBottom});
			}
			else {
				this.css({position:'static'});
			}
		}
		return this;
   };

	$.fn.ATcaroussel = function(settings){
		var conf = $.extend({display:'inline-block',widthVignette:false,width:false,height:false,margin:'2px',time:false,belt:'#belt'},settings);
	
		var cont = $(this);
		var prev = $(this).children('#btn_prev');
		var next = $(this).children('#btn_next');
		var belt = $(this).children(belt);
		var vignettes = belt.children('*');

		var pos = {length:vignettes.length,pos:0,move:function(way){
						var vignette = vignettes.eq(this.pos);
						this.pos -= way;
						belt.stop(true);
						if(this.pos >= this.length || this.pos < 0)
						{
							this.pos = this.length - Math.abs(this.pos);
							belt.animate({left:'+='+(vignette.outerWidth()/4*way)},200);
						}
						vignette = vignettes.eq(this.pos);
						belt.animate({left:-1*vignette.position().left},400);
							
		}};

		if (conf.widthVignette)
			vignettes.css('width',conf.widthVignette);
		else
			vignettes.css('width',conf.width);
		pos.offset = parseInt(vignettes.css('width'))+(parseInt(conf.margin)*2)+4;
		cont.css({overflow:'hidden',position:'relative',margin:'0 auto'});
		belt.css({position:'absolute',top:'0',left:'0',width:pos.length*pos.offset});
		vignettes.css({display:conf.display,margin:'auto '+conf.margin});

		if (conf.width)
			cont.css('width',parseInt(conf.width)+parseInt(conf.margin)*2);
		if (conf.height)
			cont.css('height',conf.height);
		var height = parseInt(cont.css('height'));

		if (prev.length == 1)
		{
			prev.css({top:((height-prev.height())/2),left:0, position:'absolute', cursor:'pointer','z-index':1});
			prev.click(move_caroussel);
		}
		if (next.length == 1)
		{
			next.css({top:((height-next.height())/2),right:0, position:'absolute', cursor:'pointer','z-index':1});
			next.click(move_caroussel);
		}
	
		if (conf.time !== false)
			setInterval(move_caroussel,conf.time);
		function move_caroussel()
		{
			var way = false;
			if (prev.length == 1)
				way = $(this).attr('id') == prev.attr('id');
			pos.move(way?1:-1);
		}
	};
 
 })(jQuery);

