var titulos = ['The Chemical Brothers', 'Shakira', 'Orbital', 'Andy y Lucas', 'Alejandro Sanz', 'Jennifer Lopez', 'Madonna', 'Nelly Furtado', 'Rihanna', 'Don Omar', 'Wisin y Yandel', 'Daddy Yankee', 'Muse', 'Gwen Stefani', 'Avril Lavigne', 'David Bisbal', 'Mala Rodr�guez', 'Natalia', 'RBD', 'Nach', 'Massive Attack', 'Pignoise', 'The Prodigy', '50 Cent', 'Eminen', 'Haze', 'Calle 13', 'Fatboy Slim', 'El canto del loco', 'La oreja de Van Gogh', 'Alex Ubago', 'Sr.Trepador', 'The Crystal Method', 'R�yksopp', 'Boards of Canada', 'Thievery Corporation', 'Portishead', 'Ojos de brujo', 'El Bicho', 'El Barrio', 'Melendi', 'Green Day', 'My Chemical Romance', 'Edurne', 'Ferry Corsten', 'Enya', 'Daft Punk', 'Mago de Oz', 'Extremoduro', 'Marea', 'Christina Aguilera', 'Britney Spears', 'Kelly Minogue', 'Paul Van Dyk', 'Pastora Soler', 'U2', 'Bassement Jaxx', 'Funkst�rung', 'Sean Paul', 'Autechre', 'Eros Ramazzotti', 'Ricky Martin', 'Reincidentes', 'La 5� Estaci&oacute;n', 'Beastie Boys', 'Goldfrapp', 'Wu-Tang Clan', 'Nightwish', 'Morcheeba', '30 Seconds to Mars', 'A-ha', 'A perfect circle', 'AC/DC', 'Aerosmith', 'Alejandro Fern&aacute;ndez', 'Moby', 'Metallica', 'Dover', 'Radiohead', 'Antonio Orozco', 'Enrique Iglesias', 'Paulina Rubio', 'Tokio Hotel', 'Monica Naranjo', 'Estopa', 'The Postal Service'];
var ids = [5,8,7,10,11,12,13,14,15,16,17,18,19,20,21,22,24,27,35,29,30,33,34,36,37,38,39,43,47,48,49,50,51,52,53,54,55,60,62,63,64,65,66,71,72,75,78,85,86,87,89,90,92,95,97,98,106,108,111,112,113,114,115,116,117,118,119,120,121,122,125,127,128,129,132,133,134,136,137,139,140,142,144,146,147,149];
var aleatorio = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85];
var img, enlace, cache, contador = 0;

function fisherYates ( myArray ) {
  var i = myArray.length;
  if ( i == 0 ) return false;
  while ( --i ) {
     var j = Math.floor( Math.random() * ( i + 1 ) );
     var tempi = myArray[i];
     var tempj = myArray[j];
     myArray[i] = tempj;
     myArray[j] = tempi;
   }
};

function cambiaBanner ()
{
	img.src = cache.src;
	enlace.href = 'http://www.videoclipsya.com/artista/' + ids[aleatorio[contador]] + '/';
	enlace.title = titulos[aleatorio[contador]];

	contador++;

	if (contador >= ids.length)
	{
		contador = 0;
		fisherYates(aleatorio);
	}

	cache.src = 'http://www.videoclipsya.com/i/anuncios/' + ids[aleatorio[contador]] + '.jpg';
}

function iniciaBanner () { 
	img = document.getElementById('banner_rot'); 
	enlace = img.parentNode; 
	fisherYates(aleatorio);
       	cache = new Image();
	cache.src = 'http://www.videoclipsya.com/i/anuncios/' + ids[aleatorio[0]] + '.jpg'; 
	setInterval('cambiaBanner();', 4000); 

	img.style.display = 'block';
};

function IsImageOk(img) {
    if (!img.complete) {
        return false;
    }
    
    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
        return false;
    }

    return true;
}

function clean_images_post(where)
{
    if (!where)
        return;
        
    var img = where.getElementsByTagName('img');
    
    for (var i = 0; i < img.length; i++) {
        if (!IsImageOk(img[i])) {
            img[i].src = "i/no_image.jpg";
        }
    }
}

if (window.attachEvent) {
	window.attachEvent("onload", iniciaBanner);
    window.attachEvent("onload", function() {clean_images_post(document.getElementById('novedades'));});
} else {
	window.addEventListener('load', iniciaBanner, false);
    window.addEventListener('load',function() {clean_images_post(document.getElementById('novedades'))}, false);
}

