//Setup a namespace to contain your own code within the YAHOO namespace
YAHOO.namespace("Coordinova");

//Create our carousel object literal with an init method
YAHOO.Coordinova.Carousel = {
	carousels: '',
	init: function()
		{
			this.carousels = YAHOO.util.Dom.getElementsByClassName('carousel-container');
			for(i = 0; i < this.carousels.length; i++) {
				this.setup(this.carousels[i]);
			}
		},
	carousel: '',
	setup: function(carousel_el)
	{
		var carousel = new YAHOO.widget.Carousel(carousel_el,
		{
			autoPlayInterval: 5000,
			isCircular: true,
			animation: {
				speed: 1.0
				},
				numVisible: 5
		});
		carousel.on("itemSelected", function (index) { 
		//alert('aqui');
	    var item = carousel.getElementForItem(index); 		 
			if (item) { 
				switch ( getImage( item ) ) {
					case "1":
						document.getElementById('mainimg').innerHTML = "<a href='empresarial.html'><img src='img/empresa.jpg'></a>";
						document.getElementById('titulares').innerHTML = "<a href='empresarial.html'><b>Eventos Empresariales</b><br>Congresos, Convenciones, Juntas, Seminarios, Inauguraciones, etc.</a>";
						break;
					case "2":
						document.getElementById('mainimg').innerHTML = "<a href='sociales.html'><img src='img/social01.jpg'><a href='sociales.html'></a>";
						document.getElementById('titulares').innerHTML = "<a href='sociales.html'><b>Eventos Sociales</b><br>Bodas, XV A&ntilde;os, Bautizos, Primeras Comuniones, etc.</a>";
						break;
					case "3":
						document.getElementById('mainimg').innerHTML = "<a href='somos.html'><img src='img/inngde.jpg'></a>";
						document.getElementById('titulares').innerHTML = "<a href='somos.html'><b>Nuestra Empresa</b><br>Misi&oacute;n y Visi&oacute;n</a>";
						break;
					case "4":
						document.getElementById('mainimg').innerHTML = "<a href='cotiza.php'><img src='img/lineagde.jpg'></a>";
						document.getElementById('titulares').innerHTML = "<a href='cotiza.php'><b>Cotizaci&oacute;n en l&iacute;nea</b><br>Contacto y Mayor Informaci&oacute;n.</a>";
						break;
					case "5":
						document.getElementById('mainimg').innerHTML = "<img src='img/cheffBig.jpg'>";
						document.getElementById('titulares').innerHTML = "<b>Banquetes</b><br>Gourmet, buffet, postres, pasteles, etc...";					
				}
			} 
		});
		carousel.render();
		carousel.show();  
		carousel.startAutoPlay();
	}
};

//onDomReady check to see if our carousel exists, and call the setup function
YAHOO.util.Event.onDOMReady(
  function (ev) {

  var ta1S = new YAHOO.util.Anim('ta1', { 
		height: { to: 8, unit: 'px' }, 
		top: { to: 97, unit: 'px' }
	}, 1, YAHOO.util.Easing.easeOut); 
	var ta1B = new YAHOO.util.Anim('ta1', { 
		height: { to: 24, unit: 'px' }, 
		top: { to: 81, unit: 'px' }
	}, 1, YAHOO.util.Easing.easeOut); 

	var ta2S = new YAHOO.util.Anim('ta2', { 
		height: { to: 8, unit: 'px' }, 
		top: { to: 97, unit: 'px' }
	}, 1, YAHOO.util.Easing.easeOut); 
	var ta2B = new YAHOO.util.Anim('ta2', { 
		height: { to: 24, unit: 'px' }, 
		top: { to: 81, unit: 'px' }
	}, 1, YAHOO.util.Easing.easeOut); 

	var ta3S = new YAHOO.util.Anim('ta3', { 
		height: { to: 8, unit: 'px' }, 
		top: { to: 97, unit: 'px' }
	}, 1, YAHOO.util.Easing.easeOut); 
	var ta3B = new YAHOO.util.Anim('ta3', { 
		height: { to: 24, unit: 'px' }, 
		top: { to: 81, unit: 'px' }
	}, 1, YAHOO.util.Easing.easeOut); 

	var ta4S = new YAHOO.util.Anim('ta4', { 
		height: { to: 8, unit: 'px' }, 
		top: { to: 97, unit: 'px' }
	}, 1, YAHOO.util.Easing.easeOut); 
	var ta4B = new YAHOO.util.Anim('ta4', { 
		height: { to: 24, unit: 'px' }, 
		top: { to: 81, unit: 'px' }
	}, 1, YAHOO.util.Easing.easeOut); 

	var ta5S = new YAHOO.util.Anim('ta5', { 
		height: { to: 8, unit: 'px' }, 
		top: { to: 97, unit: 'px' }
	}, 1, YAHOO.util.Easing.easeOut); 
	var ta5B = new YAHOO.util.Anim('ta5', { 
		height: { to: 24, unit: 'px' }, 
		top: { to: 81, unit: 'px' }
	}, 1, YAHOO.util.Easing.easeOut); 
	//alert('li');  
	var li1 = document.getElementById('li1');
	var li2 = document.getElementById('li2');
	var li3 = document.getElementById('li3');
	var li4 = document.getElementById('li4');
	var li5 = document.getElementById('li5');
	
	ta1S.animate();
	ta2S.animate();
	ta3S.animate();
	ta4S.animate();
	ta5S.animate();

	YAHOO.Coordinova.Carousel.init();
	
	YAHOO.util.Event.addListener( li1, 'mouseover', function( e ) {
		ta1B.animate();
		ta2S.animate();
		ta3S.animate();
		ta4S.animate();
		ta5S.animate();
	} );

	YAHOO.util.Event.addListener( li2, 'mouseover', function( e ) {
		ta2B.animate();
		ta1S.animate();
		ta3S.animate();
		ta4S.animate();
		ta5S.animate();
	} );

	YAHOO.util.Event.addListener( li3, 'mouseover', function( e ) {
		ta3B.animate();
		ta1S.animate();
		ta2S.animate();
		ta4S.animate();
		ta5S.animate();
	} );

	YAHOO.util.Event.addListener( li4, 'mouseover', function( e ) {
		ta4B.animate();
		ta1S.animate();
		ta2S.animate();
		ta3S.animate();
		ta5S.animate();
	} );

	YAHOO.util.Event.addListener( li5, 'mouseover', function( e ) {
		ta5B.animate();
		ta1S.animate();
		ta2S.animate();
		ta3S.animate();
		ta4S.animate();
	} );

  }
);

function getImage(parent) {
	var el = parent.firstChild;
	var texto;
	while (el) {  // walk through till as long as there's an element
		if ( el.nodeName.toUpperCase() == "H1" ) {
			texto = el.innerHTML;
		}
		el = el.nextSibling;
	}
	return texto;
}