//Rutas de las imagenes
if(pais=="MX"){
	var imagenes = new Array(6);
		imagenes[0]="images/home/banner_header_mx.png";
		imagenes[1]="images/home/HEADER_fondo_04.jpg";
		imagenes[2]="images/home/HEADER_fondo_04.jpg";
		imagenes[3]="images/home/HEADER_fondo_02.jpg";
		imagenes[4]="images/home/banner_header_mx.png";
		imagenes[5]="images/home/HEADER_fondo_04.jpg";
}else{
	var imagenes = new Array(6);
		imagenes[0]="images/home/HEADER_fondo_04.jpg";
		imagenes[1]="images/home/HEADER_fondo_04.jpg";
		imagenes[2]="images/home/HEADER_fondo_04.jpg";
		imagenes[3]="images/home/HEADER_fondo_02.jpg";
		imagenes[4]="images/home/HEADER_fondo_03.jpg";
		imagenes[5]="images/home/HEADER_fondo_04.jpg";
}
var headBack = new Array(6);
//Precargo las imagenes
for(var i=0; i<imagenes.length; i++){
	img = new Image();
	img.src = imagenes[i];
	headBack[i]="url("+imagenes[i]+")";
}

if (!ESET) {
  var ESET = {};
}

ESET.Home = {
  selected: 0,
  index: 0,
  fade_busy: false,

  init: function() {
    this.setTabEvents();
    if(pais=="MX"){
  		$('home_slides').style.backgroundImage=headBack[this.index];
		$('home_slides').onclick=function(){
				location.href="http://www.eset-la.com/estudiantes.php?utm_source=sitio-la&utm_medium=header&utm_campaign=estudiantes-mexico";
		}
		$('home_slides').style.cursor="pointer";
	}
  },

  setTabEvents: function() {
    $('tabs_title_links').getElements('a').each(function(link, index) {
      link.addEvent('click', function(evt) {
        evt.stop();
        this.selectTab(index);
      }.bind(this));
    }.bind(this));
  },

  selectTab: function(index) {


	//alert(this.selected);

	if(!this.fade_busy) {


	  this.fade_busy = true;
      this.index = index;
      $('home_slides').style.backgroundImage=headBack[this.index];

      var previous = new Fx.Tween($$('.tabs_content')[this.selected], {
        duration: 250,
        onComplete: function() {

          $$('.tabs_content')[this.selected].setStyle('display', 'none');
          $('tabs_title_links').getElements('a')[this.selected].removeClass('selected');

          var next = new Fx.Tween($$('.tabs_content')[this.index], {
            duration: 250,
            onComplete: function() {
              this.fade_busy = false;
            }.bind(this)
          });

          next.set('opacity', 0).start('opacity', 1);

          $$('.tabs_content')[this.index].setStyle('display', 'block');

          $('tabs_title_links').getElements('a')[this.index].addClass('selected');
          this.selected = this.index;


        }.bind(this)
      }).start('opacity', 0);

			var arVersion = navigator.appVersion.split("MSIE")
			var version = parseFloat(arVersion[1])
			if (version < 7) {
				var slides = [ 1, 1, 1, 1, 1, 1];
			}else if(pais=="MX"){
				var slides = [ 0, 2, 1, 3, 0, 4];
			}else {
				var slides = [ 0, 1, 0, 2, 1, 3];
			}
      if(slides[this.selected] != slides[this.index]) {
		if(pais=='MX'){
			if(this.index==0 || this.index==4){
				$('home_slides').onclick= function(){
					location.href="http://www.eset-la.com/estudiantes.php?utm_source=sitio-la&utm_medium=header&utm_campaign=estudiantes-mexico";
				};
				$('home_slides').style.cursor="pointer";
			}else{
				$('home_slides').onclick= function(){};
				$('home_slides').style.cursor="default";
			}
		}
        new Fx.Morph($('home_slides').getElement('ul').getElements('li')[slides[this.selected]], {
          duration: 500,
          transition: 'cubic:out'
        }).start({
          'opacity': 0,
          'top': 30
        });

        new Fx.Morph($('home_slides').getElement('ul').getElements('li')[slides[this.index]], {
          duration: 500,
          transition: 'cubic:out'
        }).set({
          'opacity': 0,
          'display': 'block',
          'top': 30
        }).start({
          'opacity': 1,
          'top': 0
        });
      }
    }
  }
}

window.addEvent('domready', function() {
  ESET.Home.init();
});