/*
 * jQuery projeteFloater
 * Copyright (c) 2010 Projete Web
 * Version: 1.00 (27-JAN-2010)
 * Requires: jQuery v1.3.2 or later
*/
(function($){
				
var ver = '1.00';

$.fn.projetefloater = function(options) {
											
	$.fn.projetefloater.ver = function() { return ver; };
	
	// Valores defaults
	$.fn.projetefloater.defaults = {
		position:		'bottonRight',	// topLeft, topRight, center, bottonLeft, bottonRight
		fxInput:		'scrollRight',	// normal, scrollDown, scrollUp, scrollLeft, scrollRight
		fxOutput:		'scrollLeft',	// normal, scrollDown, scrollUp, scrollLeft, scrollRight						
		speed:			1500,			// Velocidade para abrir e fechar
		delay:			0,				// Tempo antes de abrir o floater em segundos, 0 para desabilitar
		timeout:		0, 				// Tempo para fechar o floater automaticamente em segundos, 0 para desabilitar
		close:			null
	};
	
	
	var opts = $.extend($.fn.projetefloater.defaults, options);
	
	return this.each(function() {
		
		var $cont = $(this);
		
																				
		$($cont).css({
			position: 'absolute',
			opacity: 0,
			display: 'none',
			zIndex: 999999
		});
		
		$('html').css({height: '100.2%'});
		
		var screenHeight = $(window).height();
		var screenWidth = $(window).width();
		var objHeight = $($cont).outerHeight();
		var objWidth = $($cont).outerWidth();
		var objPosition = $($cont).position();
		
		// posiciona o close
		$(opts.close).css({
			position: 'absolute',
			cursor: 'pointer',
			top: 10,
			left: objWidth - 38
		});
								
		// Fecha o floater						
		$(opts.close).click(function() {							
			switch(opts.fxOutput) {
				case 'normal':
					$($cont).animate({opacity: 0}, opts.speed, function() {
						$($cont).remove();
					});
					break;
				case 'scrollDown':
					var deslocamento = screenHeight - objPosition.top;
					$($cont).animate({top: deslocamento, opacity: 0}, opts.speed, function(){
						$($cont).remove();
					});
					break;
				case 'scrollUp':
					var deslocamento = objPosition.top - objHeight;
					$($cont).animate({top: deslocamento, opacity: 0}, opts.speed, function(){
						$($cont).remove();
					});
					break;
				case 'scrollLeft':
					var deslocamento = objPosition.left - objWidth;
					$($cont).animate({left: deslocamento, opacity: 0}, opts.speed, function(){
						$($cont).remove();
					});
					break;
				case 'scrollRight':
					$($cont).css('position', 'fixed');
					var deslocamento = screenWidth - objPosition.left;
					$($cont).animate({left: deslocamento, opacity: 0}, opts.speed, function(){
						$($cont).remove();
					});
					break;
			}														
		});
		
		$('#closeFloater').click(function(e) {
			e.preventDefault();
		});
		
		if (opts.timeout) {
			setTimeout(function(){
				$(opts.close).click();
			}, opts.timeout * 1000);
		}
		// Fim do fecha o banner
								
		setTimeout(function() {
			$($cont).css({display: 'block'});
			switch(opts.position) {	// Caucula a posição			
				case 'topLeft':
					if (opts.fxInput == 'normal')
						$($cont).css({position: 'fixed', top: 0, left: 0});
					else if (opts.fxInput == 'scrollDown')
						$($cont).css({position: 'fixed', top: -objHeight});
					else if (opts.fxInput == 'scrollUp')
						$($cont).css({position: 'fixed', top: screenHeight - objHeight});
					else if (opts.fxInput == 'scrollLeft')
						$($cont).css({position: 'fixed', top: 0, left: screenWidth - objWidth})
					else if (opts.fxInput == 'scrollRight')
						$($cont).css({position: 'fixed', top: 0, left: -objWidth})
					$($cont).animate({
						opacity: 1,
						top: 0,
						left: 0
					}, opts.speed, function() {
						$($cont).css('position', 'fixed');
					});
					break;
				case 'topRight':
					if (opts.fxInput == 'normal')
						$($cont).css({position: 'fixed', top: 0, left: screenWidth - objWidth});
					else if (opts.fxInput == 'scrollDown')
						$($cont).css({position: 'fixed', top: -objHeight, left: screenWidth - objWidth});
					else if (opts.fxInput == 'scrollUp')
						$($cont).css({position: 'fixed', top: screenHeight - objHeight, left: screenWidth - objWidth});
					else if (opts.fxInput == 'scrollLeft')
						$($cont).css({position: 'fixed', top: 0, left: screenWidth + objWidth});
					else if (opts.fxInput == 'scrollRight')
						$($cont).css({position: 'fixed', top: 0, left: -objWidth});
					$($cont).animate({
						top: 0,
						left: (screenWidth - objWidth),
						opacity: 1
					}, opts.speed, function(){
						$($cont).css('position', 'fixed');
					});
					break;
				case 'center':
					if (opts.fxInput == 'normal')
						$($cont).css({position: 'fixed', top: (screenHeight / 2 - objHeight / 2), left: (screenWidth / 2 - objWidth / 2)});
					else if (opts.fxInput == 'scrollDown')
						$($cont).css({position: 'fixed', top: -objHeight, left: (screenWidth / 2 - objWidth / 2)});
					else if (opts.fxInput == 'scrollUp')
						$($cont).css({position: 'fixed', top: screenHeight + objHeight, left: (screenWidth / 2 - objWidth / 2)});
					else if (opts.fxInput == 'scrollLeft')
						$($cont).css({position: 'fixed', top: (screenHeight / 2 - objHeight / 2), left: screenWidth + objWidth});
					else if (opts.fxInput == 'scrollRight')
						$($cont).css({position: 'fixed', top: (screenHeight / 2 - objHeight / 2), left: -objWidth});
					$($cont).animate({
						opacity: 1,
						top: (screenHeight / 2 - objHeight / 2),
						left: (screenWidth / 2 - objWidth / 2)
					}, opts.speed, function(){
						$($cont).css('position', 'fixed');
					});
					break;
				case 'bottonLeft':
					if (opts.fxInput == 'normal')
						$($cont).css({position: 'fixed', top: (screenHeight - objHeight), left: 0});
					else if (opts.fxInput == 'scrollDown')
						$($cont).css({position: 'fixed', top: 0, left: 0});
					else if (opts.fxInput == 'scrollUp')
						$($cont).css({position: 'fixed', top: screenHeight + objHeight, left: 0});
					else if (opts.fxInput == 'scrollLeft')
						$($cont).css({position: 'fixed', top: screenHeight - objHeight, left: screenWidth + objWidth});
					else if (opts.fxInput == 'scrollRight')
						$($cont).css({position: 'fixed', top: screenHeight - objHeight, left: -objWidth});
					$($cont).animate({
						opacity: 1,
						top: (screenHeight - objHeight),
						left: 0
					}, opts.speed, function() {
						$($cont).css('position', 'fixed');
					});
					break;
				case 'bottonRight':
					if (opts.fxInput == 'normal')
						$($cont).css({position: 'fixed', top: (screenHeight - objHeight), left: (screenWidth - objWidth)});
					else if (opts.fxInput == 'scrollDown')
						$($cont).css({position: 'fixed', top: 0, left: (screenWidth - objWidth)});
					else if (opts.fxInput == 'scrollUp')
						$($cont).css({position: 'fixed', top: screenHeight + objHeight, left: (screenWidth - objWidth)});
					else if (opts.fxInput == 'scrollLeft')
						$($cont).css({position: 'fixed', top: (screenHeight - objHeight), left: (screenWidth + objWidth)});
					else if (opts.fxInput == 'scrollRight')
						$($cont).css({position: 'fixed', top: (screenHeight - objHeight), left: -objWidth});
					$($cont).animate({
						opacity: 1,
						top: (screenHeight - objHeight),
						left: (screenWidth - objWidth)
					}, opts.speed, function() {
						$($cont).css('position', 'fixed');
					});
					break;
			} // Fim caucula posiÃ§Ã£o
		}, opts.delay * 1000);
		
	}); // Fim do return each
	
}; // Fim do fn geral

})(jQuery);
