/* ------------------------------------------------------------------------
	s3Slider

	Developed by: Boban Karišik -> http://www.serie3.info/
		CSS Help: Mészáros Róbert -> http://www.perspectived.com/
		Rewritten: mynetx -> http://mynetx.net/
	Version: 1.0

	Copyright: Feel free to redistribute the script/modify it, as
			   long as you leave my infos at the top.
------------------------------------------------------------------------- */

(function($){

	$.fn.s3Slider = function(vars) {

		var element = this;
		var current = -1;
		var isHovering = false;
		var items = $("#" + element[0].id + "Content ." + element[0].id + "Image");
		var itemsSpan = $("#" + element[0].id + "Content ." + element[0].id + "Image .overlay");

		items.each(function(i) {
			var link = $(this).find('a');
			$(this)
				.hide()
				.hover(
					function () {
						isHovering = true;
					}, 
					function () {
						isHovering = false;
					}
				)
				.find('.overlay')
					.hide()
					.click(function () {
						top.location.href = link.attr('href');
					})
					.end()
		});

		var sliderShow = function() {
			if(++current == items.length)
				current = 0;
			items.eq(current).fadeIn(1000, function() {
				$(itemsSpan[current]).slideDown(1000, function() {
					if(items.length > 1) {
						setTimeout(sliderHide, items.eq(current).attr('rel') * 1000); // ms
					}
				});
			});
		};

		var sliderHide = function() {
			if(isHovering) {
				setTimeout(sliderHide, 500);
				return;
			}
			$(itemsSpan[current]).slideUp(1000, function() {
				$(items[current]).fadeOut(1000, function() {
					sliderShow();
				});
			});
		};

		sliderShow();
	};

})(jQuery);

