/*var RZcarousel=new Class({initialize:function(b,c){this.setOptions({onRotate:Class.empty,onStop:Class.empty,onAutoPlay:Class.empty,onShowSlide:Class.empty,panelSelector:'.panel',slidesSelector:'.slide',buttonsSelector:'.button',buttonNextSelector:'.button-next',buttonPrevSelector:'.button-prev',slideInterval:4000,transitionDuration:700,transitionEffect:'scroll',startIndex:0,buttonOnClass:'selected',buttonOffClass:'off',rotateAction:'none',rotateActionDuration:100,rotateActionEffect:'scroll',autoplay:'on'},c);
this.container=$(b);
this.panel=this.container.getElement(this.options.panelSelector);
this.slides=this.container.getElements(this.options.slidesSelector);
this.buttons=this.container.getElements(this.options.buttonsSelector);
this.buttonNext=this.container.getElement(this.options.buttonNextSelector);
this.buttonPrev=this.container.getElement(this.options.buttonPrevSelector);
this.currentSlide=null;
if(this.options.transitionEffect=='crossfade'||this.options.rotateActionEffect=='crossfade'){this.fxCrossfade=new Array();
this.slides.each(function(d,a){this.fxCrossfade[a]=new Fx.Style(d,'opacity');
if(a!=this.options.startIndex)d.setStyle('opacity',0)},this);
this.options.transitionEffect='crossfade';
this.options.rotateActionEffect='crossfade'}else{this.fxScroll=new Fx.Scroll(this.panel,{'wait':false});
this.fxFade=new Fx.Style(this.panel,'opacity',{'wait':false})}this.setupButtons();
this.showSlide(this.options.startIndex,1);
if(this.options.autoplay=='on'||this.options.autoplay=='once')this.autoplay()},setupButtons:function(){if(this.options.rotateAction!='none'){var b=null;this.buttons.each(function(d,a){$(d).addEvent(this.options.rotateAction,function(){if(this.options.rotateActionEffect=='scroll'){this.showSlide(a,this.options.rotateActionDuration,this.options.rotateActionEffect)}else{$clear(b);b=this.showSlide.delay(this.options.rotateActionDuration,this,[a,this.options.rotateActionDuration,this.options.rotateActionEffect])}this.stop()}.bind(this))},this)}if(this.buttonNext&&this.buttonPrev){this.buttonNext.addEvent('click',function(){if(this.currentSlide+1>=this.slides.length){next=0}else{next=this.currentSlide+1};
alert("gigi");
this.showSlide(next,this.options.rotateActionDuration,this.options.rotateActionEffect);
this.stop()}.bind(this));
this.buttonPrev.addEvent('click',function(){if(this.currentSlide-1<0){next=this.slides.length-1}else{next=this.currentSlide-1};
this.showSlide(next,this.options.rotateActionDuration,this.options.rotateActionEffect);
this.stop()}.bind(this))}},showSlide:function(c,e,f){if(c==this.currentSlide)return;
this.slides.each(function(d,a){var b=$(this.buttons[a]);if(a==c&&a!=this.currentSlide){if(b)b.removeClass(this.options.buttonOffClass).addClass(this.options.buttonOnClass)}else{if(b)b.removeClass(this.options.buttonOnClass).addClass(this.options.buttonOffClass)}},this);
switch(f){case'fade':this.fxFade.setOptions({'duration':e});
this.fxFade.start(1,0.01).chain(function(){this.fxScroll.setOptions({'duration':1});
this.fxScroll.toElement(this.slides[c]);
this.fxFade.start(0.01,1)}.bind(this));break;case'crossfade':this.slides.each(function(d,a){this.fxCrossfade[a].setOptions({'duration':e});if(a==c){this.fxCrossfade[a].start(1)}else if(d.getStyle('opacity')>0){this.fxCrossfade[a].start(0)}},this);break;case'scroll':this.fxScroll.setOptions({'duration':e});
this.fxScroll.toElement(this.slides[c])}this.currentSlide=c;
this.fireEvent('onShowSlide',c)},rotate:function(){if(this.currentSlide+1>=this.slides.length){next=0}else{next=this.currentSlide+1};
if(this.options.autoplay=='once'&&next==0){this.stop();return};
this.showSlide(next,this.options.transitionDuration,this.options.transitionEffect);
this.fireEvent('onRotate')},autoplay:function(){this.slideshowInt=this.rotate.periodical(this.options.slideInterval,this);
this.fireEvent('onAutoPlay')},stop:function(){clearInterval(this.slideshowInt);this.fireEvent('onStop')}});
RZcarousel.implement(new Options);
RZcarousel.implement(new Events);*/

    var YOODropdownMenu=new Class({
         Implements:  [Options],
        
        
        initialize:function(element,options){this.setOptions({mode:'default',itemSelector:'li',dropdownSelector:'ul',duration:600,remainTime:800,remainClass:'remain',transition:Fx.Transitions.linear,wait:false},options);
    var obj=this;
    this.menu=$(element);
    this.timer=null;
    this.dropdowns=[];
    this.remain=[];
    if(!this.menu)return;
    this.menu.addEvents({mouseenter:function(event){obj.remain=[];obj.removeRemain(10)},mouseleave:function(event){obj.remain.each(function(item){item.addClass(obj.options.remainClass)});
    obj.removeRemain(obj.options.remainTime)}});
    this.menu.getElements(this.options.itemSelector).each(function(item){var dropdown=item.getElement(this.options.dropdownSelector);
    if(dropdown){this.dropdowns.include(item);
    if(this.options.mode=='slide'){this.attachSlideFx(item,dropdown)}else{this.attachDefaultFx(item,dropdown)}item.addEvents({mouseenter:function(event){item._dropdownhover=true;obj.remain=[];
    if(!item.hasClass(obj.options.remainClass)&&!window.opera){item.fireEvent('fx.dropdown')}},mouseleave:function(event){item._dropdownhover=false;
    if(obj.menu!=event.relatedTarget&&!obj.menu.hasChild(event.relatedTarget)){obj.remain.include(item)}else{item.fireEvent('dropdownleave')}}})}}.bind(this))},attachDefaultFx:function(item,dropdown){var styles=dropdown.getStyles('width','height','opacity');
    var reset={'width':0,'height':0};var div=new Element('div').adopt(dropdown.getChildren()).injectInside(dropdown).setStyle('width',styles.width.toInt());
    var fx=new Fx.Styles(dropdown,this.options);
    switch(this.options.mode){case'width':reset={'width':0};
    break;
    case'height':reset={'height':0};break}item.addEvent('fx.dropdown',function(){fx.stop();
    fx.element.setStyles($extend(reset,window.ie?{'overflow':'hidden'}:{'opacity':0,'overflow':'hidden'}));
    fx.start(styles).chain(function(){fx.element.setStyles(styles)})})},attachSlideFx:function(item,dropdown){var styles=dropdown.getStyles('width','height','opacity');
    var div=new Element('div').adopt(dropdown.getChildren()).injectInside(dropdown);
    var fx1=new Fx.Styles(dropdown,this.options);
    var fx2=new Fx.Styles(div,this.options);
    item.addEvent('fx.dropdown',function(){fx1.stop();
    fx1.element.setStyles({'height':0,'overflow':'hidden'});
    fx1.start(styles).chain(function(){fx1.element.setStyles(styles)})
    ;fx2.stop();fx2.element.setStyles({'margin-top':-styles.height.toInt()});
    fx2.start({'margin-top':0})})},removeRemain:function(delaytime){$clear(this.timer);
    this.timer=(function(){this.dropdowns.each(function(item){if(item.hasClass(this.options.remainClass)&&!item._dropdownhover)item.fireEvent('dropdownleave');
    item.removeClass(this.options.remainClass)}.bind(this))}).delay(delaytime,this)},matchHeight:function(){if(this.menu){this.menu.getElements('li.level2 div.sub').each(function(sub){var hover=sub.getParent().getElement('div.hover-box4');
    var height=Math.max(sub.getCoordinates().height,hover.getCoordinates().height);
    var elements=[sub,hover];elements.each(function(element){var offset=element.getStyle('padding-top').toInt()+element.getStyle('padding-bottom').toInt()+element.getStyle('border-top-width').toInt()+element.getStyle('border-bottom-width').toInt();
    element.setStyle('height',height-offset)})})}},matchUlHeight:function(){if(this.menu){this.menu.getElements('div.dropdown-3').each(function(div){var elements=div.getChildren();
    var height=0;
    elements.each(function(element){height=Math.max(element.getCoordinates().height,height)});elements.each(function(element){var offset=element.getStyle('padding-top').toInt()+element.getStyle('padding-bottom').toInt()+element.getStyle('border-top-width').toInt()+element.getStyle('border-bottom-width').toInt();
    element.setStyle('height',height-offset)})})}}});
    YOODropdownMenu.implement(new Events,new Options);



var RZcarousel = new Class( {
	initialize : function(b, c) {
		 this.setOptions( {
		 onRotate : Class.empty, 
		 onStop : Class.empty, 
		 onAutoPlay : Class.empty, 
		 onShowSlide : Class.empty, 
		 panelSelector : '.panel', 
		 slidesSelector : '.slide', 
		 buttonsSelector : '.button', 
		 buttonNextSelector : '.button-next', 
		 buttonPrevSelector : '.button-prev', 
		 slideInterval : 4000, 
		 transitionDuration : 700, 
		 transitionEffect : 'scroll', 
		 startIndex : 0, 
		 buttonOnClass : 'selected', 
		 buttonOffClass : 'off', 
		 rotateAction : 'none', 
		 rotateActionDuration : 100, 
		 rotateActionEffect : 'scroll', 
		 autoplay : 'on'
		}, c);
		this.container = $(b);
		this.panel = this.container.getElement(this.options.panelSelector);
		this.slides = this.container.getElements(this.options.slidesSelector);
		this.buttons = this.container.getElements(this.options.buttonsSelector);
		this.buttonNext = this.container.getElement(this.options.buttonNextSelector);
		this.buttonPrev = this.container.getElement(this.options.buttonPrevSelector);
		this.currentSlide = null;

		if(this.options.transitionEffect == 'crossfade' || this.options.rotateActionEffect == 'crossfade') {
			this.fxCrossfade = new Array();
			this.slides.each(function(d, a) {
				this.fxCrossfade[a] = new Fx.Style(d, 'opacity');
				if(a != this.options.startIndex)
					d.setStyle('opacity', 0);
			}, this);
			this.options.transitionEffect = 'crossfade';
			this.options.rotateActionEffect = 'crossfade';
		}
		else {
			this.fxScroll = new Fx.Scroll(this.panel, {'wait':false});
			this.fxFade = new Fx.Style(this.panel, 'opacity', {'wait':false});
		}
		this.setupButtons();
		this.showSlide(this.options.startIndex, 1);
		if(this.options.autoplay == 'on' || this.options.autoplay == 'once')
			this.autoplay();
   },
   setupButtons : function() {
	  if(this.options.rotateAction != 'none') {
		 var b = null;
		 this.buttons.each(function(d, a) {
			$(d).addEvent(this.options.rotateAction, function() {
			   if(this.options.rotateActionEffect == 'scroll') {
				  this.showSlide(a, this.options.rotateActionDuration, this.options.rotateActionEffect);
			   }
			   else {
				  $clear(b);
				  b = this.showSlide.delay(this.options.rotateActionDuration, this, [a, this.options.rotateActionDuration, this.options.rotateActionEffect]);
			   }
			   this.stop();
			}.bind(this))
		 }, this)
	  }
	  if(this.buttonNext && this.buttonPrev) {
		 this.buttonNext.addEvent('click', function() {
			if(this.currentSlide + 1 >= this.slides.length) {
			   next = 0;
			}
			else {
			   next = this.currentSlide + 1;
			};
			this.showSlide(next, this.options.rotateActionDuration, this.options.rotateActionEffect);
			this.stop();
		 }.bind(this));
		 this.buttonPrev.addEvent('click', function() {
			if(this.currentSlide - 1 < 0) {
			   next = this.slides.length - 1;
			}
			else {
			   next = this.currentSlide - 1;
			};
			this.showSlide(next, this.options.rotateActionDuration, this.options.rotateActionEffect);
			this.stop();
		 }.bind(this))
	  }
   },
   showSlide : function(c, e, f) {
	  if(c == this.currentSlide)
		return;
		this.slides.each(function(d, a) {
			var b = $(this.buttons[a]); if(a == c && a != this.currentSlide) {
				if(b)
					b.removeClass(this.options.buttonOffClass).addClass(this.options.buttonOnClass);
			}
			else {
				if(b)
					b.removeClass(this.options.buttonOnClass).addClass(this.options.buttonOffClass);
			}
		 }, this);
		 switch(f) {
			case'fade':
				this.fxFade.setOptions( {'duration':e} );
				this.fxFade.start(1, 0.01).chain(function() {
					this.fxScroll.setOptions( {'duration':1} );
					this.fxScroll.toElement(this.slides[c]);
					this.fxFade.start(0.01, 1);
				}.bind(this));
				break;
			case'crossfade':
				this.slides.each(function(d, a) {
					this.fxCrossfade[a].setOptions( {'duration':e} );
					if(a == c) {
						this.fxCrossfade[a].start(1);
					}
					else if(d.getStyle('opacity') > 0) {
						this.fxCrossfade[a].start(0);
					}
				}, this);
				break;
			case'scroll':
				this.fxScroll.setOptions( {'duration':e} );
				this.fxScroll.toElement(this.slides[c]);
				break;
		 }
		 this.currentSlide = c;
		 this.fireEvent('onShowSlide', c);
   },
   rotate : function() {
	  if(this.currentSlide + 1 >= this.slides.length) {
		 next = 0;
	  }
	  else {
		 next = this.currentSlide + 1;
	  };
	  if(this.options.autoplay == 'once' && next == 0) {
		 this.stop();
		 return;
	  };
	  this.showSlide(next, this.options.transitionDuration, this.options.transitionEffect);
	  this.fireEvent('onRotate');
   },
   autoplay : function() {
	  this.slideshowInt = this.rotate.periodical(this.options.slideInterval, this);
	  this.fireEvent('onAutoPlay');
   },
   stop : function() {
	  clearInterval(this.slideshowInt);
	  this.fireEvent('onStop');
   }
}); 
RZcarousel.implement(new Options); 
RZcarousel.implement(new Events);


var LapTools = {
	start: function() {
		
        
        var dropdown = new YOODropdownMenu('menu', { mode: 'default', dropdownSelector: 'div.dropdown', transition: Fx.Transitions.Expo.easeOut });
 
 
       /* 
        
		$('menu').getElements('li.title').each( function( elem ){
		var list = elem.getElement('ul.links');
		var myFx = new Fx.Slide(list, {mode: 'horizontal',duration:600}).hide();
		elem.addEvents({
			'mouseenter' : function(){
				myFx.cancel();
				myFx.slideIn();
			},
			'mouseleave' : function(){
				myFx.cancel();
				myFx.slideOut.delay(800, myFx);
			}
		});
		})
		*/
		if($("menu2") != null) { 
		$('menu2').getElements('li.title').each( function( elem ){
		var list = elem.getElement('ul.links');
		var myFx = new Fx.Slide(list, {mode: 'horizontal',duration:600}).hide();
		elem.addEvents({
			'mouseenter' : function(){
				myFx.cancel();
				myFx.slideIn();
			},
			'mouseleave' : function(){
				myFx.cancel();
				myFx.slideOut.delay(800, myFx);
			}
		});
		})
		}    
	
		
		if($("cart") != null) {
			$('cart').getElements('li.title').each( function( elem ){
			var list = elem.getElement('table.links');
			var myFx = new Fx.Slide(list).hide();
			elem.addEvents({
				'mouseenter' : function(){
					myFx.cancel();
					myFx.slideIn();
				},
				'mouseleave' : function(){
					myFx.cancel();
					myFx.slideOut();
				}
			});
			})
		}
        
        if($("container") != null) {   
            
          //slider variables for making things easier below
        var itemsHolder = $('container');
        var myItems = $$(itemsHolder.getElements('.slideitem'));
        
        //controls for slider
        var theControls = $('controls1');
        var thePrevBtn = $(theControls.getElement('.prev_btn'));
        var theNextBtn = $(theControls.getElement('.next_btn'));
        
        
        //create instance of the slider, and start it up        
        var mySlider = new SL_Slider({
            slideTimer: 6000,
            orientation: 'vertical',      //vertical, horizontal, or none: None will create a fading in/out transition.
            fade: false,                    //if true will fade the outgoing slide - only used if orientation is != None
            isPaused: true,
            container: itemsHolder,
            items: myItems,
            prevBtn: thePrevBtn,
            nextBtn: theNextBtn
        });
        mySlider.start();          
          
        }
        
        
        if($("homepage_slide") != null) {   
            
          //slider variables for making things easier below
        var itemsHolder = $('homepage_slide');
        var slideItems = $$(itemsHolder.getElements('.slideitem'));
        
        //controls for slider
        var theControls = $('controls2');
        var thePrevBtn = $(theControls.getElement('.left_btn'));
        var theNextBtn = $(theControls.getElement('.right_btn'));
        
        
        //create instance of the slider, and start it up        
        var mySlider = new SL_Slider({
            slideTimer: 3000,
            orientation: 'horizontal',      //vertical, horizontal, or none: None will create a fading in/out transition.
            fade: true,                    //if true will fade the outgoing slide - only used if orientation is != None
            isPaused: true,
            container: itemsHolder,
            items: slideItems,
            prevBtn: thePrevBtn,
            nextBtn: theNextBtn
        });
        mySlider.start();          
          
        }
        
        
        
        
        if ($('vertical_slide')) { 
        var myVerticalSlide = new Fx.Slide('vertical_slide'); 
        $('v_toggle').addEvent('click', function(e){
        e.stop();
        myVerticalSlide.toggle();
        });
        
        var cVerticalSlide = new Fx.Slide('comment_slide'); 
        $('c_toggle').addEvent('click', function(e){
        e.stop();
        cVerticalSlide.toggle();
        });
        
        var mySlide = $$("#vertical_slide").slide("hide");
        var cSlide = $$("#comment_slide").slide("hide");
        }
        
		
        if ($('login')) {    
        $('login').addEvent('submit', function(event) {
         event.stop();   
         var req = new Request({    
         method: 'post',   
         url: $('login').get('action'),
         data: { 
         'form': 'date'
         },
         onRequest: function() { 
             //alert('Request made. Please wait...'); 
         },    
         update: $('message-here'), 
         onComplete: function(response) { 
             if(response == 'ok')
                window.location = "/login";
             if(response == 'okk')
                window.location = "/shopping_cart";
             else{
             $('response').set('class', 'response_active');  
             $('response').set('text', response); 
             }
         }
         }).post($('login')).send();   
        });
        }
        
        if ($('register')) { 
            
        function blablabla()
        {
        window.location = "/login";
        }    
            
            
           
        $('register').addEvent('submit', function(event) {
         event.stop();  
         var req = new Request({    
         method: 'post',   
         url: $('register').get('action'),
         data: { 
         'form': 'date'
         },
         onRequest: function() { 
             //alert('Request made. Please wait...'); 
         },    
         update: $('message-here'), 
         onComplete: function(response) { 
             //alert(response);
             if(response == 'ok') { 
             $('overlay').setStyle('display', 'block');
             $('alertBody').setStyle('display', 'block');
           //  setTimeout(go_to_homepage(), 10000);
            // setTimeout("blablabla()",500); 
           // setTimeout('window.location  = theURL', '0');
             }
             
             if(response == 'okk') 
               window.location = "/shopping_cart";
             else {
             $('response').set('class', 'response_active'); 
             $('response').set('text', response); 
            // $('response').adopt(response);
             }
         }
         }).post($('register')).send();   
        });
        
        }
        

        
        
		if($("gallery") != null) {
			$('gallery').getElements('li.title').each( function( elem ){
			var list = elem.getElement('table.links');
			var myFx = new Fx.Slide(list).hide();
			elem.addEvents({
				'mouseenter' : function(){
					myFx.cancel();
					myFx.slideIn();
				},
				'mouseleave' : function(){
					myFx.cancel();
					myFx.slideOut();
				}
			});
			})
		}
		
		// Contact
		if($('contactForm') != null) {
			$('contactForm').addEvent('submit', function(e) {
				e.stop();
				this.set('send', {onComplete: function(response) {
					if(response == "ok") {
						document.location.reload();
					}
                    else if(response == "okk"){
                        $('response').set('class', 'response_active');  
                        $('response').setStyle('width', '300px');  
                        $('response').set('text', 'Mesajul dumneavoastra a fost trimis.'); 
                    }
                    
					else {
						alert("Atentie !!!\n\n" + response);
					}
				}});
				this.send();
			});
		}
		
		// Check CART submit
		if($('addressCartForm') != null) {
			$('addressCartForm').addEvent('submit', function(e) {
				e.stop();
				this.set('send', {onComplete: function(response) {
					if(response == "ok") {
						redirect("/cart_thankyou");
					}
					else {
						alert("Atentie !!!\n\n" + response);
					}
				}});
				this.send();
			});
		}
        
            // Forgot pass form
        if($('forgotPasswdForm') != null) {
            $('forgotPasswdForm').addEvent('submit', function(e) {
                e.stop();
                this.set('send', {onComplete: function(response) {
                    if(response == "ok") {
                        //document.location.reload();
                        $('response').set('class', 'response_active');  
                        $('response').set('text', 'Un mesaj a fost trimis la adresa de e-mail introdusa de tine.'); 
                    }
                    else {
                        alert("Atentie !!!\n\n" + response);
                    }
                }});
                this.send();
            });
        }
    
        
        // Comments form submit
        if($('commentForm') != null) {
            $('commentForm').addEvent('submit', function(e) {
                e.stop();
                this.set('send', {onComplete: function(response) {
                    if(response == "ok") {
                        //document.location.reload();
                        $('response').set('text', 'Mesajul a fost trimis'); 
                    }
                    else {
                        alert("Atentie !!!\n\n" + response);
                    }
                }});
                this.send();
            });
        }        
        

		
	}
};
window.addEvent('load', LapTools.start); 



/*
// Mouse poinetr capture
window.addEvent("mousemove", function(event) {
	var msx = event.page.x;
	var msy = event.page.y;
	if($('tooltip') != null) {
		$('tooltip').style.left = (msx + 15) + "px";
		$('tooltip').style.top = (msy + 20) + "px";
	}
	if($('tooltip2') != null) {
		$('tooltip2').style.left = (msx - 60) + "px";
		$('tooltip2').style.top = (msy - 130) + "px";
	}
});

*/

