/**
 * Slide Show de Imagens
 * 
 * @author: Thomaz Takashi Oda Toyama.
 * @retrun void
 */
 
(function($){
	$.fn.slideShow = function(options){
		var settings 	= $.extend({},$.fn.slideShow.defaults,options);
		var parent		= $(this);
		var width		= parent.outerWidth(true);
		var height		= parent.outerHeight(true);
		var ul			= $('ul:first',parent)
		var li			= $('li',parent);
		var flag		= true;
		
		parent.css({'position':'relative','overflow':'hidden'});
		
		li.css({
			 'float'	: 'left'
			,'width'	: width + 'px'
			,'height'	: height +'px'
		});
		
		ul.css({
			 'position'	: 'absolute'
			,'width'	: (width * li.length) + 'px'
			,'height'	: height +'px'
			,'left'		: 0
			,'top'		: 0
		});
		
		$(settings.prev).css({opacity: "0.5", cursor: 'default'});
		if(( parseInt( ul.css('left') ) + width) > 0 && flag && li.length > 1)
			$(settings.next).css({opacity: "1.0"});
		else $(settings.next).css({opacity: "0.5", cursor: 'default'});
		
		$(settings.prev).click(function(){
			if(( parseInt( ul.css('left') ) + width) < (width) && flag){
				flag = false;
				$(settings.next).css({cursor: 'pointer'}).animate({opacity: "1.0"},'slow');
				ul.animate({left: '+='+width+'px'},settings.speedy,function(){ 
					flag = true; 
					if(!(( parseInt( $(this).css('left') ) + width) < (width) && flag)){
						$(settings.prev).css('cursor','default').animate({opacity: "0.5"});
					}
				});
			}
		});
		
		$(settings.next).click(function(){
			if(( parseInt( ul.css('left') ) + width) > 0 && flag && li.length > 1){
				flag = false;
				$(settings.prev).css({cursor: 'pointer'}).animate({opacity: "1.0"},'slow');
				ul.animate({left: '-=' + width + 'px'},settings.speedy,function(){ 
					flag = true; 
					if(!(( parseInt( $(this).css('left') ) + width) > 0 && flag)){
						$(settings.next).css('cursor','default').animate({opacity: "0.5"});
					}	
				});
			}else $(settings.next).css({opacity: "0.5", cursor: 'default'});
		});
		
		var div = new Array();
		
		
		$('.boxe-borda').mouseenter(function(){
			div.push($(document.createElement("div")).css({
				  position:'absolute'
				, opacity: "0.0"
				, top:0
				, left:0
				, 'z-index': 0
				, border:'solid 3px #ee4f1c'
				, width: $(this).innerWidth()
				, height:$(this).innerHeight() 
			}).prependTo(this));
			div[(div.length-1)].animate({opacity: "1.0"},500);
		});
		
		$('.boxe-borda').mouseleave(function(){
			var divTmp = (div.length - 1);
			for(i=divTmp;i>=0;i--){
				div[i].animate({opacity: "0.0"},250,function(){ $(this).remove(); });
			}
			div = new Array();
		});
		
	};
	$.fn.slideShow.defaults = {
		 prev: '.prev'
		,next: '.next'
		,speedy: 1000
	};
})(jQuery);
