﻿/**
 * @author Oriol Cabau
 */

jQuery(document).ready(function(){
	
	jQuery(window).load(function(){
		setTimeout(animarticker, 7000);
	});
	
	if(jQuery.browser.msie){
		var numtxt = 1;
	}else{
		var numtxt = 0;
	}
	var control = true;
	var frases = new Array(
							"Bienvenidos a GrauOnline",
							"La mejor selecci&oacute;n de Europa en la red",
							"M&aacute;s de 9.000 productos",
							"Todas las D.O. Espa&ntilde;olas",
							"Vinos de m&aacute;s de 40 pa&iacute;ses",
							"Licores de todo el mundo",
							"El mejor Whisky, Ginebra y Vodka",
							"Cervezas de importaci&oacute;n",
							"Selecci&oacute;n de productos gourmet",
							"Accesorios para el vino",
							"Os esperamos"
							);
	
	function cambiartexto(){
		jQuery('#textB').fadeOut(200, function(){
			
			if(numtxt == 10){
				jQuery("#stickerInicio").fadeOut(400, function(){
					jQuery(this).css("left", "-2400px");
					jQuery('#textB').html(frases[10]).fadeIn(200);
				});
			}else if(numtxt == 11){
				jQuery('#bInicio').css("background", "url(../img/img01.jpg)");
				jQuery('#textB').html(frases[0]).fadeIn(200);
				numtxt = 0;
				setTimeout(animarticker, 7000);
			}else{
				jQuery('#textB').html(frases[numtxt]).fadeIn(200);
			}
			
		});
		
		numtxt++;
		
		setTimeout(cambiartexto, 7000);
	}
		
	function cambiartextomsie(){
		jQuery('#textB').fadeOut(0, function(){
			
			if(numtxt == 10){
				jQuery("#stickerInicio").fadeOut(400, function(){
					jQuery(this).css("left", "-2400px");
					jQuery('#textB').html(frases[10]).fadeIn(0);
				});
			}else if(numtxt == 11){
				jQuery('#bInicio').css("background", "url(../img/img01.jpg)");
				jQuery('#textB').html(frases[0]).fadeIn(0);
				numtxt = 0;
				setTimeout(animarticker, 7000);
			}else{
				jQuery('#textB').html(frases[numtxt]).fadeIn(0);
			}
			
		});
		
		numtxt++;
		
		setTimeout(cambiartextomsie, 7000);
	}
	
	function animarticker(){
		jQuery("#stickerInicio").fadeIn(400, function(){
			jQuery('#bInicio').css("background", "url(../img/img02.jpg)");
			jQuery("#stickerInicio").animate({"left": "0px"}, 63000, "linear");
		});
		if(jQuery.browser.msie && control == true){
			setTimeout(cambiartextomsie, 0);
			control = false;
		}else if(control == true){
			setTimeout(cambiartexto, 0);
			control = false;
		}
	}
	
});
