/**
* Troca de imagens da página inicial MercoPlast
* Desenvolvido por GHS Web - www.ghsweb.com.br
* Proibida a cópia total ou parcial sem autorização.
*/

// Não funciona no IE6 e browsers mais antigos. Com ele, as imagens ficam estáticas.
if (!($.browser.msie == true && parseInt($.browser.version) <= 6))
{
	$('#loading_header').css('display', 'block');

	var Home = {
		img: new Array(),
		base: '',
		atual: 0,
		timer: false,

		init: function(base, img)
		{
			// Passa variáveis da função para variáveis da classe.
			this.base	= base;
			this.img	= img;

			for (i = 0; i < this.img.length; i++)
			{
				$('#rotator').append('<img src="' + this.base + this.img[i] + '" class="rotate_images" id="rotator_img_' + i + '" alt="" style="display:none;" />');
			}

			window.onload = function()
			{
				$('#loading_header').fadeOut(500, function(){ $('#rotator').animate({opacity:1.0}, 500); $('#rotator_img_0').css('display', 'block'); });

				// JS do Google Chrome não faz desaparecer a imagem "loading" sem este código.
				setInterval(function(){$('#loading_header').fadeOut(500);}, 250);

				this.timer = setTimeout("Home.rotacao()", 6000);			
			}
		},
		rotacao: function()
		{
			$('#rotator_img_' + this.atual).fadeOut(500, function() { Home.atual = (Home.atual == (Home.img.length-1)) ? 0 : (Home.atual+1); $('#rotator_img_' + Home.atual).fadeIn(300) });

			this.timer = setTimeout("Home.rotacao()", 6000);
		}
	}

	// Inicia
	Home.init('/media/img/home_rotator/', ['img_1.png', 'img_2.png', 'img_3.png']);
}
