window.addEvent('domready', function() { 
sshow = new slideShow( $$('#banner .banner-slider') );
sshow.next.periodical( 5000, sshow );

if($$('.item-pdf')[0]) {

  $$('.item-pdf').each(function(elem,i) { 

      var a = $(elem).getElement('a').getProperty('href');
      if(a==null)
      $(elem).dispose();
      //console.log(a);

    });
}
/* vypne zobrazovanie obrazka ak nieje pri produkte */
if($$('.item-image')[0]) {

  $$('.item-image').each(function(elem,i) { 

      var a = $(elem).getElement('img');
      if(a==null)
      $(elem).dispose();
      //console.log(a);

    });
}

/* nastavi pocet referenciii v indexe */
if($$('.ref')[0]) {
  $$('.ref li').each(function(elem,i) { 
      if(i>3)
      $(elem).dispose();
      //console.log(a);
    });
}




if($$('.sortiment')[0]) {
 
$$('.sortiment').each(function(elem,i) { 
        elem.setStyle('cursor','pointer');
	var hreff = $(elem).getElement('a').get('href');
    // console.log(hreff.test('sortiment'));
       if(hreff!=null && location.href.test('sortiment')==true){
       var data = hreff.split('/');
       hreff = data[1];
       } 

       
	$(elem).getElement('a').dispose();
		elem.addEvent('click', function() {
			window.location.href = location.href+hreff;
		});

});
}

});


function slideShow( Obj ){
	var pass = this;
	// initializing
	this.curImg = 0;
	this.slides = Obj;
	var curr=0;
	//$$('.slogan').fade('out');
//        $$('.slogan').setStyle('opacity',0.8);	//aelias
	this.slides.each( function( img, index ){
	var Alem =   new Element ('a',{'href':'javascript:void(null)', 'class': 'control', id:'next-'+index,
							  'events': { 'click': function(){ sshow.current(index); if(this.removeClass('active'))this.addClass('active'); }
								 	 }
	}).inject('banners-controller');//.set('text',(index+1));
	    if (index==0)
             Alem.addClass('active');
	img.set('morph', { duration:900, transition: Fx.Transitions.Quad.easeOut, onComplete: function() {  /* $$('.slogan h2')[ pass.curImg ].fade('in');/*tween('opacity',0,1);*/} });
	if( index > 0) img.setStyles({ opacity: 0 });
	//if( index > 0) $$('.slogan')[ index ].setStyle('opacity',0);	//aelias
	}, this);

	this.next = function(){
		pass.curImg++;		        	
		curr++;                       		
//		//$$('.slogan h2').();
		//$$('.slogan h2').fade('out');
                // $$('.slogan h2').setStyle('opacity',0);
        	this.slides.each( function( img, index ){
			img.morph({ opacity: 0 });
		}, this);
		
              
		$$('a.control').each( function( alem, i ){
					alem.removeClass('active');
					var curi = (i+1);
					if(curr==curi){
					//console.log(curr);
					}
		});

		if( curr == this.slides.length ) curr = 0;
                    $('next-'+(curr)).addClass('active');
		if( pass.curImg == this.slides.length ) pass.curImg = 0;
                var prevImg = pass.curImg-1;
                if( prevImg == -1) prevImg = this.slides.length-1;
                $$('.slogan')[ prevImg ].setStyle('opacity',0);
              $$('.slogan')[ pass.curImg ].setStyle('opacity',1);
              //$$('.slogan h2').fade('in');

		this.slides[ pass.curImg ].morph({ opacity: 1 });
		




	}
	this.prev = function(){
		pass.curImg--;
		this.slides.each( function( img, index ){
			img.morph({ opacity: 0 });
		}, this);
		if( pass.curImg < 0 ) pass.curImg = this.slides.length - 1;
		this.slides[ pass.curImg ].morph({ opacity: 1 });


	}

	this.current = function(index) {
		$$('a.control').each(function(alem,i) {
			alem.removeClass('active');

		});
		//console.log(index);
		this.slides.each( function( img ){
			img.morph({ opacity: 0});
		}, this);

           // $$('.slogan h2')[ index ].tween('opacity',0,1);
		this.slides[index].morph({ opacity: 1 });
	}
}


