(function($) {
	//public functions
	var methods = {
		init : function(options) {
			var defaults = {}, opts, $t, $bannerNavBlock,
			currBannerIndex=0, oldBannerIndex=0;
			
			$t = $(this);
			opts = $.extend(defaults, options);
			$banners = $t.find("li");
			$banners.not(":first").hide().css({opacity:0});
			$banners.filter(":first").show().css({opacity:1});			
			
			$links = new Array($banners.length);
			
			$bannerNavBlock = $("div.bannerNavBlock");
			
			$banners.each(function(i){

				//create button for this banner 
				$banner = $(this);		
				
				$links[i] = $(document.createElement("a"));
				$links[i].addClass("bannerSquare");
				$links[i].attr("href","#");
				$links[i].text(" ");
				$links[i].click(function(){
					$("a.bannerSquare.current").removeClass("current");
					$(this).addClass("current");
					methods.showImg(i);
					return false;
				});		

				//add to some block				
				$bannerNavBlock.append($links[i]);
			});
			
			$links[0].addClass("current");

			//add listeners for showNext, prev and showImg(index)
			/*$next_link.click(function(){
				methods.showNextImg();
			});
			$previous_link.click(function(){
				methods.showPrevImg();
			});*/
						
			clearTimeout(imgTimeout);
			imgTimeout = setTimeout(methods.showNextImg, 7000);
						
		}, 
		showImg : function(index){
			currBannerIndex = index;
			currBannerIndex = (currBannerIndex<0)?($banners.length-1):currBannerIndex;		
			currBannerIndex = (currBannerIndex>=$banners.length)?0:currBannerIndex;		
			showCurrImage();			
		},
		showNextImg : function(){
			currBannerIndex++;
			currBannerIndex = (currBannerIndex>=$banners.length)?0:currBannerIndex;		
			showCurrImage();
		},
		showPrevImg : function(){
			currBannerIndex--;
			currBannerIndex = (currBannerIndex<0)?($banners.length-1):currBannerIndex;		
			showCurrImage();
		}
	};
	
	/*
		private vars
	*/
	var $banners, $buttons, currBannerIndex=0, oldBannerIndex=0, imgTimeout=0;
	
	/*
		private functions
	*/
	function showCurrImage(){
		//hide
		if (oldBannerIndex!=currBannerIndex)
		{	$($banners[oldBannerIndex]).css("z-index", 5).animate({opacity:0}, 750, "linear", function(){
				$(this).hide();
			},750);
		}
		//go to next
		$($banners[currBannerIndex]).css("z-index", 6).show().animate({opacity:1}, 750);
		
		clearTimeout(imgTimeout);
		imgTimeout = setTimeout(methods.showNextImg, 7000);
		
		$("a.bannerSquare.current").removeClass("current");
		$links[currBannerIndex].addClass("current");
		
		oldBannerIndex = currBannerIndex;
	}
	
	
	$.fn.bannerRotation = function(method) {
		//Method Calling Login
		if (methods[method]) {
			return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
		} else if (typeof method === 'object' || !method) {
			return methods.init.apply(this, arguments);
		} else {
			$.error('Method ' + method + ' does not exist on jQuery.');
		}
	};
})(jQuery);
