$.fn.rotatorBannerTourism = function(){
	var self = this;
	var rotaData;
	var currentSlide=0;
	
	$.post('/?q=GET_BANNER_ROTATOR_SLIDES', {  }, function(data) {
		rotaData = data;		
		$(window).resize(function(){ self.resizeWindow(); });		
		$(self).prepend('<div style="position: absolute; top: 0px; left: 0px; width: '+$(self).width()+'px; height: '+$(self).height()+'px;"></div>');
		self.startShow();
	}, "json");
	
	this.getHtmlDiv = function(slideObj, top, left) {
		return '<div style="display: none; position: absolute; top: '+(top ? top : 0)+'px; left: '+(left ? left : 0)+'px; width: '+$(self).width()+'px; height: '+$(self).height()+'px;">'+(slideObj.url!="0"?'<a href="'+slideObj.url+'">':'')+'<img src="/'+slideObj.img+'" />'+(slideObj.url!="0"?'</a>':'')+'</div>';
	}
	
	this.resizeWindow = function(){
		$("div", this).each(function(){
			$(this).css("width", $(self).width()+"px")
				   .css("height", $(self).height()+"px");
		});
	}

	this.startShow = function() {	
		if (rotaData[currentSlide].effects == "move_right") {
			$(this).prepend(this.getHtmlDiv(rotaData[currentSlide], 0, -$(this).width()));
			$("div:last",this).animate({left: $(self).width()+'px'}, "slow", function(){ $(this).remove(); });
			$("div:first",this).show().animate({left: '0px'}, "slow");			
		}else if (rotaData[currentSlide].effects == "move_left") {
			$(this).prepend(this.getHtmlDiv(rotaData[currentSlide], 0, $(this).width()));
			$("div:last",this).animate({left: -$(self).width()+'px'}, "slow", function(){ $(this).remove(); });
			$("div:first",this).show().animate({left: '0px'}, "slow");	
		}else if (rotaData[currentSlide].effects == "move_down") {
			$(this).prepend(this.getHtmlDiv(rotaData[currentSlide], -$(this).height()));
			$("div:last",this).animate({top: $(self).height()+'px'}, "slow", function(){ $(this).remove(); });
			$("div:first",this).show().animate({top: '0px'}, "slow");	
		}else if (rotaData[currentSlide].effects == "move_up") {
			$(this).prepend(this.getHtmlDiv(rotaData[currentSlide], $(this).height()));
			$("div:last",this).animate({top: -$(self).height()+'px'}, "slow", function(){ $(this).remove(); });
			$("div:first",this).show().animate({top: '0px'}, "slow");							
		}else{
			$(this).prepend(this.getHtmlDiv(rotaData[currentSlide]));
			$("div:last",this).fadeOut("slow", function(){ $(this).remove(); });
			$("div:first",this).fadeIn("slow");			
		}
		
		delay = rotaData[currentSlide].delay ? rotaData[currentSlide].delay : 3000;	
		currentSlide = (currentSlide >= rotaData.length-1) ? 0 : currentSlide+1;
		setTimeout(function(){ self.startShow(); }, delay);
	}	

}





function close_banner (obj) {
	div = $(obj).parents('.banner').get(0);
	$(div).remove();
	return false;
}

$(document).ready(function(){
	$('a[rel="lightbox"]').lightBox();
	$("a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'slow',theme:'light_square',slideshow:2000, autoplay_slideshow: false});
	$("#rotator").rotatorBannerTourism();	
	
	
	
	$('img[rel="goodsItem"]').bind({ 
		mouseenter: function() {
			td = $(this).parents("td").get(0);
			$(".goodsDescription", td).fadeIn("fast").bind("mouseleave", function(){
				$(this).fadeOut("fast", function(){ $(this).hide(); });
			});
		}
	});
});
