$.fn.slideshow = function(options) {
	var settings = {
		timeout: '2000',
		type: 'sequence'
	}
	if(options)
		$.extend(settings, options);

	this.css('position', 'relative');
	var imgs = $('img', this).hide().get(), slides = [], cid = this.id();
	$.each(imgs, function(i) {
		slides[i] = $(document.createElement('div')).attr(
			'id', cid+'-slide'+i).css({
				background: '#000 url('+imgs[i].src+') no-repeat center center',
				zIndex: imgs.length-i,
				position: 'absolute',
				top: 0,
				left: 0,
				height: imgs[i].height,
				width: imgs[i].width
		}).addClass("slide").get(0);
	});
	this.append(slides);

	if (imgs.length == 1) return;

	if ( settings.type == 'sequence' ) {
		setTimeout(function(){
			$.slideshow.next(slides, settings, 1, 0);
		}, settings.timeout);
	}
	else if ( settings.type == 'random' ) {
		setTimeout(function(){
			do { current = Math.floor ( Math.random ( ) * ( slides.length ) ); } while ( current == 0 )
			$.slideshow.next(slides, settings, current, 0);
		}, settings.timeout);
	}
	else {
		alert('type must either be \'sequence\' or \'random\'');
	}
};
$.slideshow = function() {}
$.slideshow.next = function (slides, settings, current, last) {
	$.each(slides, function(i) { $(slides[i]).css('display', 'none'); });
	$(slides[last]).css('display', 'block').css('zIndex', 0);
	$(slides[current]).css('zIndex', 1).fadeIn('slow');

	if ( settings.type == 'sequence' ) {
		if ( ( current + 1 ) < slides.length ) {
			current = current + 1;
			last = current - 1;
		}
		else {
			current = 0;
			last = slides.length - 1;
		}
	}
	else if ( settings.type == 'random' ) {
		last = current;
		while (	current == last ) {
			current = Math.floor ( Math.random ( ) * ( slides.length ) );
		}
	}
	else {
		alert('type must either be \'sequence\' or \'random\'');
	}
	setTimeout((function(){$.slideshow.next(slides, settings, current, last);}), settings.timeout);
}

var CartecaSite = function() {

	return {
		init: function() {
			$('.slideshow .nome').slideDown('slow');
		},

		buildSlideshow: function(container, imgs) {
			$.each(imgs, function(i, src) {
				var img = new Image();
				img.src = src;
				img.height = 120;
				img.width = 258;
				container.append(img);
			});
			$('.nome', container).hide();
			container.slideshow({
				timeout: '4000'
			});
		},

		openProdutoFoto: function() {
			$(document.createElement('div'));
			alert(window.innerHeight);
			return false;
		}
	}
}();

$(document).ready(function() {
	CartecaSite.init();
	if (section == 'inicio') {

	}
	if (section == 'catalogo') {
		$('#produto .imagem a').each(function() {
			$(this).attr('target', '_blank');
		});
		//click(CartecaSite.openProdutoFoto);
	}
});

