
/** Javascript slider - zalozen na pritomnosti mootools 1.2.4 a vyssi - nutnost rozsirenych trid FX
 *  @autor - Jan Navrátil - RockLive Digital
 *  www.rocklive.cz
 *  18.7.2010  
 */ 

var Slide = new Class({
  options: {
		cont: 'slider-kont', //kontejner kde se zobrazuje slideshow
		duration: 3000,	     //doba efektu (prolnuti)
		delay: 1000,         //doba mezi zmenou obrazku 
		auto: false,         //automaticky zacit slideshow  	
		transition: Fx.Transitions.Quint.easeOut //typ FX (mootools)
	},
  initialize: function(options) {
    this.setOptions(options);
    this.cont = $(this.options.cont);
    this.first = true;
    this.auto = this.options.auto;
    /*this.cont.setStyles({
      position: 'relative'
    }); */
    /*this.buttons = new Element('div').injectInside(this.cont);
    this.buttons.set('id', this.options.cont + '-buttons');
    this.first = true;
    this.auto = this.options.auto;
    var instance = this;
    this.buttons.addEvents({
      'mouseenter': function() {
        instance.stop();
      },
      'mouseleave': function() {
        instance.play();
      }
    }); */
  },
  start: function() {
    this.images = new Array();
    this.nav = new Array();
    var x = 0;
    this.slides = $$('#'+ this.options.cont +' div.slide'); 
    //alert(this.slides);    
    for(var i in this.slides) {
      var slide = $(this.slides[i]);
      
      if (slide != null) {
        this.images[x] = slide;
        if (x > 0) {
          this.images[x].setStyles({
            position: 'absolute',
            bottom: 0,
            left: 0,
            display: 'none'
          });
        }
        x++;                          
      }          
    }
    /*this.buttonnext = new Element('a').injectInside(this.cont);
    this.buttonnext.set('id', 'next');
    this.buttonnext.set('href', '#');
    this.buttonprev = new Element('a').injectInside(this.cont);
    this.buttonprev.set('id', 'prev');
    this.buttonprev.set('href', '#');
    var instance = this;
    this.buttonnext.addEvents({
      'click': function() {
        instance.next();
      },
      'mouseenter': function() {
        instance.stop();
      },
      'mouseleave': function() {
        instance.playDelay();
      }
    });
    this.buttonprev.addEvents({
      'click': function() {
        instance.prev();
      },
      'mouseenter': function() {
        instance.stop();
      },
      'mouseleave': function() {
        instance.playDelay();
      }   
    });   */
    
    this.images[0].setStyle('display', 'block');     
    this.step = 0; 
    
    if (this.step+1 < this.images.length) {
      this.next = 1;   
    } else {
        this.next = 0;
      }
    this.efekt();   
  },
  efekt: function() {
    this.progress = true;
    var d = this.options.duration;
    var t = this.options.transition;    
    if (!this.first) {
      this.images[this.step].set('morph', {duration:d, transition: t}); 
      this.images[this.next].set('morph', {duration:d, transition: t});
      this.images[this.step].setStyles({display: 'block', opacity: 1});
      this.images[this.next].setStyles({display: 'block', opacity: 0});
      
      this.images[this.step].morph({
    		opacity: [1, 0]
      });
      this.images[this.next].morph({
    		opacity: [0, 1]
      });
            
    } 
    this.afterEfekt.delay(d + 75, this);  
    
  },
  afterEfekt: function() {
    this.progress = false; 
    if (!this.first) {
      this.step = this.next;
      this.next++;        
      if (this.next < this.images.length) {       
      } else {
        this.next = 0;         
      }
    } 
    this.first = false;    
    if(this.auto) {
			$clear(this.timer);
			this.timer = this.efekt.delay(this.options.delay, this);
		}
  },
  stop: function(){     
		$clear(this.timer);
		this.auto = false;
		$celar(this.delayTimer);
	},
	play: function() {
		if(!this.auto ) {
			$clear(this.timer);
			this.auto = true;
			if(!this.progress) {
				this.efekt();
			}
		}
	},
	playDelay: function() {
    this.delayTimer = this.play().delay(4000, this);
  },
  setSlide: function(i) {    
    if(this.progress) { return; }  
    this.next = i;  
    $clear(this.timer);
    this.efekt();
  }   
});

Slide.implement(new Options, new Events);

//nastaveni funkce po nacteni webu
/*window.addEvent('domready', function() {
    //nadefinovani options vlastnosti
  var opt = {
        cont: 'slides', //id elementu kde se budou obrazky zobrazovat
        auto: true,          //automaticky zacit s prehravanim
        delay: 3500,         //doba mezi zmenami obrazku
        duration: 3000,      //doba prolnuti
        transition: Fx.Transitions.Linear //typ prolnuti            
      };
  var slideshow = new Slide(opt); //nova instance
  slideshow.start(); //vykreslime a popr. spustime slideshow
}); */

function setMenuHover(id) {
 //var tags = document.body.getElementsByTagName("li"), buff=[]; 
 var tags = document.getElementById(id).getElementsByTagName("li"), buff=[];
    for(var i=0, mx=tags.length; i<mx;i++){
        var it = tags[i];
        //if (strpos(it.className,"parent") !== false) {
          var childs = it.childNodes;       
          for(var k=0, kx=childs.length; k<kx;k++){ 
            var ch = childs[k];
            if (ch.nodeName == "UL") {
              //ch.style.cssText = "background: #f00;";
              ch.style.display = "none";
              it.onmouseover = function() {
                 var childs = this.childNodes; 
                  for(var k=0, kx=childs.length; k<kx;k++){
                    var ch = childs[k];
                    if (ch.nodeName == "UL") {
                      ch.style.display = "block";
                    }
                  }                           
                 };
                 it.onmouseout = function() {
                 var childs = this.childNodes; 
                  for(var k=0, kx=childs.length; k<kx;k++){
                    var ch = childs[k];
                    if (ch.nodeName == "UL") {
                      ch.style.display = "none";
                    }
                  }                 
                 };              
              break;
            }  
          }         
        //}
    }
}

function setMenuHover2(id) {
 //var tags = document.body.getElementsByTagName("li"), buff=[]; 
 var tags = document.getElementById(id).getElementsByTagName("li"), buff=[];
    for(var i=0, mx=tags.length; i<mx;i++){
        var it = tags[i];
        //if (strpos(it.className,"parent") !== false) {
          if (it.className != 'active' && it.id != 'current') {
            //alert(it.onmouseover);
            if (typeof(it.onmouseover) == "undefined") {
              it.onmouseover = function() { this.className = 'active'; }
              it.onmouseout = function() { this.className = ''; }
            }   
          }          
        //}
    }
}
function onloadfce() {
	setMenuHover('menu-top');
}
function initOnload()
{var oldOnLoad;
oldOnLoadFce=window.onload;
if(typeof window.onload!='function'){
  window.onload=function(){onloadfce();};
}
  else{
  window.onload=function(){oldOnLoadFce();onloadfce();};}
}
//initOnload();

