Element.implement({
	
	targetBlank: function(){
		var href = this.href;
		this.addEvent('click', function(event){
			event.preventDefault();
			window.open(href);
		});
		return this;
	}

});

function openTab(){
	showTab.delay(5000);
};

function showTab(){
	var headerHolder = document.id('header');
	var headerInner = document.id('header-inner');
	var headerBanner = document.id('header-banner');
	headerHolder.morph({'height': '380px'});
	headerInner.morph({'height': '279px'});
	headerBanner.morph({'top': '10px'});
};

function smallIntroMouseOver(){
	var fader = document.id('fader');
	var win = document.id('window');
	fader.setStyle('opacity', 0);
	fader.morph({'display': 'block', 'opacity': 0.2});
	win.setStyle('display', 'block');
	win.getElement('.close').addEvent('click', function(event){
		event.preventDefault();
		win.setStyle('display', 'none');
		fader.setStyle('display', 'none');
	});
}

var Fake3D = new Class({

  Implements: [Options, Events],
    options: {
        direction: 'all', // horizontal | vertical | all
        item: '.layer',
        source: null,
        baseZindex: 3,
        offset: 5
    },
  
    initialize: function(container, options){

        this.container = document.id(container);
        this.setOptions(options);
     
        this.source = (this.options.source ? document.id(this.options.source) : this.container);
	    this.dimensions = window.getSize();
    
        this.items = this.container.getElements(this.options.item);
      
        this.itemData = new Array();
       
        this.items.each(function(item, index){
            var data = {
                position: {x: item.getStyle('left').toInt(), y: item.getStyle('top').toInt()},
                coeficient: item.getComputedStyle('z-index').toInt()/this.options.baseZindex
            }
            this.itemData[index] = data;
        }, this);
        
        this.source.addEvent('mousemove', function(event){
          this.render(event.client);
        }.bind(this));
        
        this.center = this.getCenter();
        
    },
    
    getCenter: function(){
        var position = this.container.getPosition();
        var containerSize = this.container.getSize();
        var center = {
            x: (position.x + containerSize.x/2).toInt(),
            y: (position.y + containerSize.y/2).toInt()
        }

        return center;
    },
    
    reset: function(){
        this.dimensions = window.getSize();
        this.center = this.getCenter();
        return this;
    },
    
    render: function(coords){
        var coef = {
            x: (this.options.offset*(coords.x - this.center.x)/this.center.x),
            y: (this.options.offset*(coords.y - this.center.y)/this.center.y)
        }
        
        this.items.each(function(item, index){
			setTopLimit = this.itemData[index].position.y - (coef.y*this.itemData[index].coeficient) / 2;
			if(setTopLimit > 0) {
				setTopLimit = 0;	
			}
		
          item.setStyles({
                top: setTopLimit,
                left: this.itemData[index].position.x - (coef.x*this.itemData[index].coeficient) * 2
            });

        }, this);

    }
});

var Schema = new Class({

  Implements: [Options, Events],
    options: {
		containerOffset: 1350,
		numItems: 5
    },
  
    initialize: function(container, options){

		this.container = document.id(container);
        this.setOptions(options);
     	this.scrollPos();
		this.scrollSize = 0;
		this.windowSize = 0;
		this.container.getElements('span').setStyles({'opacity': '0', 'display': 'block'});
		var self = this;
		this.container.getElements('a.button-plus').setStyles({'opacity': '0', 'display': 'block'});
		this.container.addEvents({mouseover: function(){ this.getElements('a.button-plus').morph({'opacity': '1'}); }, mouseout: function(){ this.getElements('a.button-plus').morph({'opacity': '0'}); }});

    },
	
	scrollPos: function(){
		window.addEvent('scroll', this.scrollCheck.bind(this));
	},
	
	scrollCheck: function(){
			if( typeof( window.pageYOffset ) == 'number' ) {
				this.scrollSize = window.pageYOffset;
			} else if( document.body && ( document.body.scrollTop ) ) {
				this.scrollSize = document.body.scrollTop;
			} else if( document.documentElement && ( document.documentElement.scrollTop ) ) {
				this.scrollSize = document.documentElement.scrollTop;
			}

			this.windowSize = document.getSize().y;

			if( (this.scrollSize + this.windowSize) > this.options.containerOffset){
				this.showIcons();				
			}
	},
	
	showIcons: function() {
		var animate = new Chain();
		var container = this.container;
		var fncs = new Array();

		for (var i = 0; i <= this.options.numItems; i++) {
			if(i < this.options.numItems){
				var fn = function(x) {
				return function() { 
					var item = this.getImage(x);
					item.set('morph', { transition: 'quad:out', duration: 300 });	
					item.morph({'opacity': '1'});	
				};
				}(i).bind(this);
				fncs.push(fn);
			} else {
				var fn = function() {
					return this.showTextBoxes();
				}.bind(this);
				fncs.push(fn);
			}
		}
			
		for (var i = 0; i <= this.options.numItems; i++) {
			animate.chain(fncs[i]);
		}
			
		animate.callChain();
		
		for (var i = 0; i <= this.options.numItems; i++) {
			animate.callChain.delay((400 * (i + 1)), animate);
		}
		var self= this;
		//this.container.getElements('a.button-plus').addEvent('click', function(){ self.toggleTextBoxes(this); });
	},
	
	getImage: function(i){
		return this.container.getElements('span')[i];
	},
	
	toggleTextBoxes: function(o){
			prev = this.container.getElements('div.shown');
			prev.set('morph', { transition: 'quad:out', duration: 600, unit: '%' }).morph({'width': '0'});
			prev.removeClass('shown');
			obj = o.getParent('div').getElement('div.text');
			obj.set('morph', { transition: 'quad:out', duration: 600, unit: '%' });
			obj.setStyle('display', 'block').addClass('shown').morph({'width': '100'});
	},
	
	showTextBoxes: function(o){
		this.container.getElements('div.text').each(function(item, index){
			item.set('morph', { transition: 'quad:out', duration: 600, unit: '%' });
			item.setStyle('display', 'block');
			item.morph({'width': '100'});
		});
		var self = this;
		this.container.getElements('a.button-plus').addEvents({mouseenter: function(){ self.highlight(this, true); }, mouseleave: function(){ self.highlight(this, false); }});
	},

	highlight: function(el, ch){
		cont = el.getParent('div');
		element = el.getParent('div').getChildren('div.text')[0];
		fader = element.getChildren('div.fader')[0];
		textNode = element.getChildren('p');
		titleNode = element.getChildren('strong');
		fader.set('tween', { duration: 400, link: 'cancel'} );
		titleNode.set('tween', { duration: 400 } );
		textNode.set('tween', { duration: 400 } );
		if(ch){
			el.addClass('active');
			fader.tween('opacity', 1, 0);
			titleNode.tween('color', '#EB1C23', '#FFFFFF');
			textNode.tween('color', '#EB1C23', '#FFFFFF');
			cont.setStyle('background-position', '0 0');
		} else { 
			el.removeClass('active');
			fader.tween('opacity', 0, 1);
			titleNode.tween('color', '#FFFFFF', '#EB1C23');
			textNode.tween('color', '#FFFFFF', '#002742');
		}
		$$('a.button-plus').each(function(item){
			if(!item.hasClass('active')){
				item.getChildren('img').set('morph', { transition: 'quad:in', duration: 150 });
				if(ch) item.getChildren('img').morph({'width': '30', 'margin-top': '4', 'margin-left': '4'});
				else item.getChildren('img').morph({'width': '38', 'margin-top': '0', 'margin-left': '0'});
			}
		});
	}	
	
});

var oldIE = (Browser.ie6);

var HouseBtns = {

	init: function(){
		this.holder = document.id('house-buttons');
		this.boxes = this.holder.getParent('div').getElements('.box');
		$$('.button-plus').addEvent('click', function(e){
			e.preventDefault();
			HouseBtns.showBox(this);
			$$('.button-plus').removeClass('active');
			this.addClass('active');
		});
		$$('.box-close').addEvent('click', function(e){
			e.preventDefault();
			HouseBtns.closeBox();
		});
		
	},
	
	showBox: function(el){
		var box = el.get('rel');
		var boxPosition;
		if(box == 'box-2') { boxPosition = 'right'; }
		else { boxPosition = 'left'; }
		this.closeBox(true, boxPosition);
		var thisBox = document.id(box);
		thisBox.addClass('active');
		thisBox.setStyles({'opacity': '0', 'display': 'block'});
		thisBox.set('morph', { transition: 'quad:out', duration: 400 });
		thisBox.morph({'opacity': '1'});
		this.holder.addClass('opened');
	},
	
	closeBox: function(ch, boxPos){
		var newBox = ch || false;
		this.boxes.each(function(el){
			if(el.hasClass('active')) el.setStyles({'opacity': '0'}); el.removeClass('active');	
		});
		if(!newBox) { this.moveHolder('center'); }
		else { 
			if(boxPos == 'left') this.moveHolder('right'); 
			else this.moveHolder('left');
		}
	},
	
	moveHolder: function(direction){
		var pos;
		if(direction == 'center') { pos = 450; this.holder.removeClass('opened'); }
		else if(direction == 'right') { pos = 620; }
		else { pos = 295; }
		this.holder.set('morph', { transition: 'quad:out', duration: 400 });
		this.holder.morph({'left': pos + 'px'});
	}
	
};

var ProductsSlide = {
	
	init: function(){
		this.holder = document.id('products-selection');
		this.slides = this.holder.getElements('img');
		this.slide();
	},
	
	anim: function(el){
		el.set('tween', { duration: 400, transition: Fx.Transitions.Expo.easeOut, link: 'chain' });
		el.tween('left', 2000, 0);
	},
	
	slide: function(){
		var myChain = new Chain();
		this.slides.each(function(item) { myChain.chain( function(){ ProductsSlide.anim(item); } ); });
		var runChain = function() { myChain.callChain(); };
		var timer = runChain.periodical(150);
	}
};

var Zoomer = {

    init: function(){
    
        this.holder = document.id('zoomer');
        $$('div.img-zoom').each(function(item){
            
            item.addEvent('mouseenter', function(){
                Zoomer.zoomIn(this);
            });
        }); 
        
    },
    
    zoomIn: function(o){
        this.holder.setStyle('display', 'block');
        if(this.holder.getElement('img')) Zoomer.clearHolder();
        var p = o.getElement('a').getAttribute('href');
        var myImage = Asset.image(p, {
            onLoad: Zoomer.anim(p, o)
        });
    },
    
    clearHolder: function(){
        this.holder.getElements('img').dispose();
    },
    
    anim: function(p, o){
        var img = new Element('img');
        var overlay = new Element('img');
        overlay.addEvent('mouseleave', function(){Zoomer.clearHolder()} );
        
        this.holder.setStyles({'margin-top': '58px', 'margin-left': '65px'});
        
        posX = o.getPosition().x;
        posY = o.getPosition().y;
        
        img.set({'src': p, 'id': 'zoomed', 'width': '71', 'height': '67'});
        img.inject(this.holder, 'top');

        overlay.set({'src': '/images/zoomer-overlay.png', 'id': 'zoomer-overlay', 'width': '86', 'height': '81'});
        overlay.inject(this.holder);
        
        img.set('morph', { transition: 'quad:out', duration: 400 });
        img.morph({'width': '191px', 'height': '177px', 'top': '9px;', 'left': '9px'});
        overlay.set('morph', { transition: 'quad:out', duration: 400 });
        overlay.morph({'width': '209px', 'height': '196px'});
        
        this.holder.set('morph', { transition: 'quad:out', duration: 400 });
        this.holder.setStyles({'left': posX - 60 + 'px', 'top': posY - 55 + 'px'});
        this.holder.morph({'margin-top': '0px', 'margin-left': '0px'});
    }
    
};

var Video = {

	init: function(){
	
		this.holder = document.id('video-player');
		this.openBtn = $$('a.button-play');
		this.closeBtn = this.holder.getElement('.video-close');
		this.openBtn.addEvent('click', function(e){
			e.preventDefault();
			this.holder.setStyle('display', 'block');
		}.bind(this));
		this.closeBtn.addEvent('click', function(e){
			e.preventDefault();
			this.holder.setStyle('display', 'none');
		}.bind(this));
		
	}
	
};

var Main = {

      init: function(){

		document.getElement('html').removeClass('no-js');

		new SmoothScroll({ duration:700 }, window); 
		
		var clix = new dwClickables({
			elements: $$('.clickable'),
			anchorToSpan: false
		});
		if($$('.img-zoom')) Zoomer.init();
		if (document.getElement('html').hasClass('no-js'))  document.getElement('html').removeClass('no-js');
		if (document.id('pruvodce')) Main.Problems.init();
		if (document.id('house-buttons')) HouseBtns.init();
		if (document.id('products-selection')) ProductsSlide.init();
		if (document.id('graphic-how-to-use')){
			if(document.id('graphic-how-to-use').hasClass('regular')) var S = new Schema('graphic-how-to-use', {numItems: 5});
			if(document.id('graphic-how-to-use').hasClass('micro')) var S = new Schema('graphic-how-to-use', {containerOffset: 1100, numItems: 3});
		}
		if(document.id('application-areas')) Areas.init();
		if(document.id('test'))	Test.init();
		if(document.id('video-player')) Video.init();
		if(document.id('form-faq')) questionValidation.init();

		var images = $$('a[rel^=lightbox]');
		if (images.length){
			var gallery = new CeraBox({
				group: true
			});
			gallery.addItems(images, {animation: 'ease'});
		}
	
		if(document.id('faq')){
			var accordion = new Fx.Accordion($$('dl dt'),$$('dd'), {
				display: -1,
				alwaysHide: true, 
				onActive: function(toggler) { toggler.addClass('active'); },
				onBackground: function(toggler) { toggler.removeClass('active'); }
			});
		}

		$$('a._blank').targetBlank();
		
		if (document.id('mista')){
			Main.dealers.init();
			}
			if(!(document.id('application-areas'))){
				if (Browser.ie6){
					new Fake3D('header', {
						source: document,
						offset: 5
					});
				} else {
					new Fake3D('header', {
						source: window,
						offset: 5
					});
				}
			}
	
		if ($('ask-us')) {
			
			document.id('form-faq').setStyle('height', '0px');
			document.id('ask-us-text').setStyle('display', 'block');
			
			var pSlide = new Fx.Slide('ask-us-text');

			document.id('ask-us-btn').addEvent('click', function(event) {
				event.stop();
				pSlide.slideOut();
				document.id('ask-us-text').tween("opacity", 0);
				document.id('form-faq').tween("height", 320);
			});
			
		}
			
		if ($('mapa-cr-wrapper')) Map.init();

	
		if ($$('.question-line')) {
			var accordion = new Fx.Accordion($$('.question-line'),$$('.content'), {
			display: -1,
			alwaysHide: true, 
			onActive: function(toggler) { toggler.addClass('active'); },
			onBackground: function(toggler) { toggler.removeClass('active'); }
		});
		}
		
	
		if ($('slider'))
		{
		var slider = $('slider');
	
		  new Slider(slider, slider.getElement('.knob'), {
			range: [10, 50],
			initialStep: 25,
			onChange: function(value){
			  if (value){
				   $$('#knob-text').set('text', value + ' km');
				   $$('#dst').set('value', value);
			  }
			}
		  });
		}
		  
	  }
	  
};

Main.Problems = {
	
	init: function(){
		
		this.element = document.id('body');
		
		this.parent = this.element.getElement('div.part');
		
		this.items = this.element.getElements('div.problem');
		
		this.current = null;

		
		this.items.each(function(item){
			var solution = item.getElement('div.solution-text');
			solution.set('tween', {duration: oldIE ? 0 : 400, property: 'opacity', link: 'cancel', transition: 'quint:out'});
			solution.get('tween').set(0);
			solution.addEvent('click', function(event){
				event.stopPropagation();
			});
			item.set('morph', {duration: oldIE ? 0 : 200, link: 'cancel', transition: 'quint:out'});
			item.store('solution', solution);
			item.store('height', item.getSize().y);
			item.store('height-target', item.getSize().y+solution.getSize().y);
			var link = item.getElement('a.solution');
			link.addEvent('click', function(event){ event.preventDefault(); });
			item.addEvent('click', function(event){
				event.stop();
				this.show(item);
			}.bind(this));
			
			var closeBtn = item.getElement('span.close')
			closeBtn.addEvent('click', function(event){
				event.stopPropagation();
				this.close();
			}.bind(this));
		}, this);
		
		document.id(document.body).addEvent('click', function(){
			this.close();
		}.bind(this));
		
	},
	
	show: function(item){
		// --- scroll
	/*	var pos = this.scrollCheck();
		var itemPos = item.getPosition().y - pos;
		var available = window.getSize().y - itemPos - 300;		
		var i = item;
		if((available < 600) || isNaN(available)) {
			var myFx = new Fx.Scroll(document.body).start(0, i.getPosition().y - 5);
		}*/
		// --- /scroll
		var current = this.current;
		if (current){
			current.retrieve('solution').get('tween').start(0);
			current.morph({
				height: current.retrieve('height'),
				opacity: 0.5
			});
			item.get('morph').set({height: current.retrieve('height-target')});
		} else {
			this.items.each(function(problem){
				if (problem != item){
					problem.retrieve('solution').get('tween').start(0);
				    problem.morph({
						opacity: 0.5,
						height: problem.retrieve('height')
					});
				}
			});

		}
		item.morph({
			opacity: 1,
			height: item.retrieve('height-target')
		});

		item.retrieve('solution').get('tween').start(1);
		this.current = item;

		this.parent.addClass('open');
	},
	
	close: function(){
		this.items.each(function(problem){
			problem.retrieve('solution').get('tween').start(0);
			problem.morph({
				opacity: 1,
				height: problem.retrieve('height')
			});
		});
		this.current = null;
		this.parent.removeClass('open');
	},
	
	scrollCheck: function(){
			if( typeof( window.pageYOffset ) == 'number' ) {
				this.scrollSize = window.pageYOffset;
			} else if( document.body && ( document.body.scrollTop ) ) {
				this.scrollSize = document.body.scrollTop;
			} else if( document.documentElement && ( document.documentElement.scrollTop ) ) {
				this.scrollSize = document.documentElement.scrollTop;
			}

			//this.windowSize = document.getSize().y;

			/*if( (this.scrollSize + this.windowSize) > this.options.containerOffset){
				this.showIcons();				
			}*/
			return this.scrollSize;
	}
};

Main.dealers = {
	
	init: function(){
		
		//this.searchDealerInput = $('form-search-dealer-city');
        //if (this.searchDealerInput) new Autocompleter.Request.JSON(this.searchDealerInput, '/obchodni-mista/mesta');
		
		$$('div.tab-anchors ul li:nth-child(first) a').addClass('active');
		firstShow = $$('div.tab-anchors ul li:nth-child(first) a').get('rel');
		//$(firstShow).setStyle('display', 'none');
		$$('div#tab-boxes div.tab-box').setStyle('display', 'none');
		$$('div#tab-boxes div:nth-child(first)').setStyle('display', 'block');
				
		$$('.tab-anchors ul li a').addEvent('click', function(event){
				event.preventDefault();
				$$('.tab-anchors ul li a').removeClass('active');
				this.addClass('active')
				
				showMe = this.get('rel');
				
				$$('.tab-box').setStyle('display', 'none');
				$(showMe).setStyle('display', 'block');
			});
		}
	
	};

var Map = {

      init: function(){
             var field = $('mapa-cr-wrapper');

             field.getElement('img').setOpacity(0.001);


             // kraje

             var areas = $('mapa-cr-large').getElements('area');

             var kraje = new Hash({
                        'zlinsky'         : [1, 2],
                        'praha'           : [2, 1],
                        'kralovehradecky' : [3, 2],
                        'vysocina'        : [1, 0],
                        'jihocesky'       : [0, 2],
                        'karlovarsky'     : [2, 0],
                        'plzensky'        : [3, 1],
                        'jihomoravsky'    : [0, 3],
                        'moravskoslezsky' : [2, 3],
                        'olomoucky'       : [1, 3],
                        'pardubicky'      : [2, 2],
                        'liberecky'       : [0, 1],
                        'ustecky'         : [3, 0],
                        'stredocesky'     : [1, 1]
             });
            

             var bubbles = new Hash({
                      	'zlinsky'         : [317, 151],
                        'praha'           : [132,  47],
                        'kralovehradecky' : [217,  35],
                        'vysocina'        : [198, 121],
                        'jihocesky'       : [116, 142],
                        'karlovarsky'     : [ 34,  27],
                        'plzensky'        : [ 53,  84],
                        'jihomoravsky'    : [251, 157],
                        'moravskoslezsky' : [339,  92],
                        'olomoucky'       : [288, 109],
                        'pardubicky'      : [233,  80],
                        'liberecky'       : [172,  -6],
                        'ustecky'         : [105,   4],
                        'stredocesky'     : [163,  54]
             });

       areas.each(function(element){
          var kraj = element.getProperty('id');
            // bubble
                  var bubble = new Element('p', { 'class' : 'bubble' });
                  //bubble.setHTML('<span>' + element.getProperty('title').replace('|', '<br />') +'</span>');
                    bubble.set('html', '<span>' + element.getProperty('title').replace('|', '<br />') +'</span>');
                    bubble.setStyles({
                        'left' : bubbles.get(kraj)[0],
                        'top'  : bubbles.get(kraj)[1]
                    });
                  var bubbleFx = new Fx.Tween(bubble, { property: 'opacity', duration: 200, wait: false });
                  bubbleFx.set(0);
                  bubble.inject(field);
                    
                    element.addEvent('mouseenter', function(event){
                        Map.move(kraje.get(kraj), field);
                            bubbleFx.start(1);
                    });
                    
                    element.addEvent('mouseleave', function(event){
                            Map.move([0, 0], field); 
                            bubbleFx.start(0);
                    });
             });
             
             var selectedRow = '';
             
             // SmoothScroll
             SmoothScroll.implement({
                useLink: function(link, anchor){
                        link.addEvent('click', function(event){
                            this.anchor = anchor;
                            this.toElement(anchor);
                            event.stop();
                            if ($(anchor)) {
                                 if ($(selectedRow)) $(selectedRow).removeClass('active');
                                 $(anchor).addClass('active');
                                 selectedRow = anchor;
                            }
                        }.bindWithEvent(this));
                    }
             });
             
             new SmoothScroll();
            
        },
        
        move: function(coords, field){
            var col = coords[0];
            var row = coords[1];
            var width = 422;
            var height = 259;
            field.setStyle('background-position', (-422*col) + 'px ' + (-259*row) + 'px');
        }
        
};


var dwClickables = new Class({
    
    Implements: [Options],

    options: {
        elements: $$('div'),
        selectClass: '',
        anchorToSpan: false
    },
    
    initialize: function(options) {
        this.setOptions(options);
        this.doClickables();
    },

    doClickables: function() {
        this.options.elements.each(function(el) {
            var anchor = el.getElements('a' + (this.options.selectClass ? '.' + this.options.selectClass : ''))[0];
            if(anchor) {
                this.setClick(el,anchor.get('href'));
             
                if(this.options.anchorToSpan) {
                    var span = new Element('span',{
                        text: anchor.get('text')
                    }).replaces(anchor);
                }
            }
            
        },this);
    },

    setClick: function(element,href) {
        element.addEvent('click', function() {
            window.location = href;
        });
    }
});

var Test = {
	init: function(){
		var self = this;
		
		document.id('vert1').setStyle('display', 'none');
		document.id('vert2').setStyle('display', 'none');
		document.id('rooms-plan').setStyle('display', 'none');
		document.id('rooms-use').setStyle('display', 'none');
		this.form = document.id('form-test-humidity');
		this.form.addEvent('submit', function(event){
			event.preventDefault();
			if(self.validate()){
				this.submit();
			}
		});
	},
	
	validate: function(){
		var valid = true;
		this.requiered = ['lname', 'lemail', 'lstreet', 'lcity', 'lzip']
		this.requiered.each(function(inp){
			var inpVal = document.id(inp);
			if(inpVal.get('value') == '') { 
				inpVal.addClass('err');
				valid = false;
			} else if(inpVal.hasClass('err')){
				inpVal.removeClass('err');
			}

		});
		this.email = document.id('lemail');
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var address = this.email.get('value');
		if(reg.test(address) == false) {
				this.email.addClass('err');
				valid = false;
		}
			
		this.agreement = document.id('agreement');
		if(this.agreement.getProperty('checked') == false){
			valid = false;
		}
		return valid;
			
	}
};

var questionValidation = {
	
	init: function(){
		this.form = document.id('form-faq');
		this.form.addEvent('submit', function(){
			var name = document.id('lname');
			var email = document.id('lemail');
			var address = email.get('value');
			var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
			var msg = document.id('lmessage');
			var err = false;
			if(name.get('value') == '') { 
				name.addClass('err');
				err = true
			} else {
				name.removeClass('err');
			}
   			if(reg.test(address) == false) {
				email.addClass('err');
				err = true;
			} else {
				email.removeClass('err');
			}
			if(msg.get('value') == '') { 
				msg.addClass('err');
				err = true
			} else {
				msg.removeClass('err');
			}
			if(err)	return false;
		});		
	}
}; 

var Areas = {

	init: function(){
		var houseAnim = Asset.image('/images/areas-house.png', {
			onLoad: function(){
				var anim = new Chain();
				var terrace = function(){
				var holder = document.id('areas-foundation').getElement('img');
				holder.setStyles({'opacity': '0', 'display': 'block'});
				holder.set('morph', { transition: Fx.Transitions.linear.easeIn, duration: 400 });
				holder.morph({ 'opacity': '1' });
			};
			
			var house  = function(){
				var holder = document.id('areas-house').getElement('img');
				holder.setStyles({'opacity': '0', 'display': 'block'});
				holder.set('morph', { transition: Fx.Transitions.linear.easeOut, duration: 500 });
				holder.morph({ 'opacity': '1', 'top': '0px' });
			};
			
			var car = function(){
				var holder = document.id('areas-car').getElement('img');	
				holder.setStyle('display', 'block');
				holder.set('morph', { transition: 'quad:out', duration: 500 });
				holder.morph({ 'left': '823px', 'top': '355px' });
			};
			
			var pool = function(){
				var holder = document.id('areas-pool').getElement('img');
				holder.setStyles({'opacity': '0', 'display': 'block'});
			 	holder.set('morph', { transition: Fx.Transitions.linear.easeIn, duration: 400 });
			 	holder.morph({ 'opacity': '1' });
			};
			
			var showButtons = function(){
			 	var holder = document.id('areas-buttons');
			 	var buttons = holder.getElements('a');
				 buttons.each(function(item, index){
					var btnPop = document.id('area-btn-' + (index+1)).getElement('img');
					  btnPop.setStyles({'opacity': '0', 'display': 'block'});
					  btnPop.set('morph', { transition: Fx.Transitions.linear.easeOut, duration: 100 });
					  btnPop.morph({'width': '38px', 'height': '36px', 'margin-left': '0px', 'margin-top': '0px', 'opacity': '1'});
				 });
			};
			
			var treeOne = function(){
				var holder = document.id('areas-tree-one').getElement('img');	
				  holder.setStyles({'opacity': '0', 'display': 'block'});
				  holder.set('morph', { transition: 'quad:out', duration: 500 });
				  holder.morph({'opacity': '1', 'width': '332px', 'height': '303px', 'left': '0px', 'top': '139px'});	
			};
			
			var treeTwo = function(){
				var holder = document.id('areas-tree-two').getElement('img');	
				  holder.setStyles({'opacity': '0', 'display': 'block'});
				  holder.set('morph', {	transition: 'quad:out', duration: 500});
				  holder.morph({'opacity': '1', 'width': '200px', 'height': '247px', 'left': '873px', 'top': '162px'});	
			};
			
			var chairs = function(){
				var holder = document.id('areas-chairs');	
				  holder.setStyles({'opacity': '0', 'display': 'block'});
				  holder.set('morph', { transition: 'quad:out', duration: 300 });
				  holder.morph({ 'opacity': '1' });	
			};
			
			var clouds = function(){
				var cloud1 = document.id('areas-cloud-one').getElement('img');
				var cloud2 = document.id('areas-cloud-two').getElement('img');
				cloud1.setStyle('display', 'block');
				cloud2.setStyle('display', 'block');
				cloud1.set('morph', { transition: 'quad:out', duration: 600 });
				cloud2.set('morph', { transition: 'quad:out', duration: 600 });
				cloud1.morph({'left': '605px', 'top': '35px'});
				cloud2.morph({'left': '300px'});
			};
			
			var enableButtons = function(){
			 	var holder = document.id('areas-buttons');
				holder.addClass('loaded');
			};
		
			anim.chain(terrace, house, car, pool, chairs, treeOne, treeTwo, clouds, showButtons, enableButtons);
			anim.callChain();
			anim.callChain.delay(300, anim);
			anim.callChain.delay(800, anim);
			anim.callChain.delay(1100, anim);
			anim.callChain.delay(1300, anim);
			anim.callChain.delay(1400, anim);
			anim.callChain.delay(1400, anim);
			anim.callChain.delay(1500, anim);
			anim.callChain.delay(1900, anim);
			anim.callChain.delay(2050, anim);
			
			}
		});

	var showSolution = function(id){
		if(document.id('solution-window')) document.id('solution-window').dispose();
		
		var solutions;
		/*if(id == 1) solution = ['solution-humidity-micro', 'solution-mould'];
		if(id == 2) solution = ['solution-humidity'], title = 'Do you have to fight high humidity, condensation and musty smells at home?',rep = 'To solve these problems just use Ceresit STOP HUMIDITY!', name = 'Bedroom';
		if(id == 3) solution = ['solution-humidity-sachets'], title = 'Do you have to fight musty smells in your closet and cupboards?',rep = 'To solve these problems just use Ceresit STOP HUMIDITY Mini Sachets!', name = 'Closet';
		if(id == 4) solution = ['solution-humidity2', 'solution-germs'], title = 'Do you have to fight high humidity, condensation and musty smells at home?', rep = 'To solve these problems just use Ceresit STOP HUMIDITY and Ceresit STOP GERMS!', name = 'Livingroom';
		if(id == 5) solution = ['solution-humidity', 'solution-mould', 'solution-germs'], title = 'Do you have high humidity, condensation and mildew development in your kitchen?<br />Do you mind the musty smell from your trash can?', rep = 'To solve these problems just use Ceresit STOP HUMIDITY, Ceresit STOP MOULD and Ceresit STOP GERMS!', name = 'Kitchen';
		if(id == 6) solution = ['solution-humidity-sachets', 'solution-germs'], title = 'Do you have to fight musty smells in your car?',rep = 'To solve these problems just use Ceresit STOP HUMIDITY Mini Sachets and Ceresit STOP GERMS!', name = 'Car';
		if(id == 7) solution = ['solution-humidity', 'solution-mould'], title = 'Do you have to fight high humidity and condensation and mildew development in your basement?',rep = 'To solve these problems just use Ceresit STOP HUMIDITY and Ceresit STOP MOULD!',name = 'Basement';
		if(id == 8) solution = ['solution-mould'], title = 'Do you have to fight mould and mildew stains on your terrace and balcony?', rep = 'To solve these problems just use Ceresit STOP MOULD!', name = 'Terrace';
		if(id == 9) solution = ['solution-mould'], title = 'Do you have to fight mould and mildew stains in your pool, sauna or pool house?', rep = 'To solve these problems just use Ceresit STOP MOULD!', name = 'Pool';*/

				
		var count = 0;
		var cont = document.id('house');
		var parent = $$('.solution-' + id);
		var holder = new Element('div');
		holder.set('id', 'solution-window');
		var textWrapper = new Element('div');
		textWrapper.addClass('text-wrapper').inject(holder);
		var heading = new Element('h2');
		heading.set('text', parent.getElement('h2').get('text')).inject(textWrapper);
		var caption = new Element('p');
		caption.addClass('caption').set('html', parent.getElement('h3').get('text')).inject(textWrapper);
		var reply = new Element('p');
		reply.addClass('reply').set('html', parent.getElement('p').get('text')).inject(textWrapper);

		parent.getElement('.solutions').each(function(item, index){
			item.clone().inject(textWrapper);
		});
		
		var closeBtn = new Element('a');
		closeBtn.addClass('solution-close').inject(holder).addEvent('click', closeWindow);
		holder.inject(cont).addClass('items-' + count);
		
		var vert = new ScrollerBar(textWrapper);
		
		/*Cufon.replace('h2', { fontFamily: 'Stop vlhkosti' });
		Cufon.replace('h3', { fontFamily: 'Stop vlhkosti' });*/
	};
	
	var closeWindow = function(){
		el = document.id('solution-window');
		el.dispose();
		
		document.id('areas-buttons').removeClass('clicked');
		$$('a.area-btn').each(function(item, index){
					item.removeClass('clicked');
					item.getChildren('span').tween('width', 0);
		});
	};
	
	$$('a.area-btn i').addEvent('mouseenter', function(){
		var cont = this.getParent('a');
		cont.addClass('active');
		var text = cont.getChildren('q').get('text');
		var textHolder = cont.getChildren('span');
		var myText = textHolder.getChildren('strong')[0];
		myText.set('text', text);
		textHolder.set('tween', {
				duration: 'short',
				transition: 'quad:out',
				unit: '%',
				link: 'cancel'
		});
		textHolder.tween('width', 100);
	});
	
	$$('a.area-btn').addEvents({
		mouseleave: function(){
		if(!(document.id('areas-buttons').hasClass('clicked'))){
			if(this.hasClass('active')){
					this.removeClass('active');
					this.getChildren('span').tween('width', 0);
					this.removeClass('clicked');
				}
			} else {
				if(this.hasClass('active')){
					if(this.hasClass('clicked') == false){
						this.removeClass('active');
						this.getChildren('span').tween('width', 0);
						this.removeClass('clicked');
					}
				}
			}
		},
	
		click: function(e){
			e.preventDefault();
			var self = this;
				$$('a.area-btn').each(function(item, index){
					if(self != item){
						item.removeClass('clicked');
						item.getChildren('span').tween('width', 0);
					}
				})
			btnId = this.get('id').substring(9, 10);
			showSolution(btnId);
			var holder = document.id('areas-buttons');
			var btn = this;
			holder.addClass('clicked');
			btn.addClass('clicked');
		}
	});
	
	}	

};

window.addEvent('domready', function() {
	Main.init();
});

Cufon.replace('h2', { fontFamily: 'Stop vlhkosti' });
Cufon.replace('h3', { fontFamily: 'Stop vlhkosti' });
Cufon.replace('.beautify', { fontFamily: 'Stop vlhkosti' });
Cufon.replace('p.caption', { fontFamily: 'Stop vlhkosti' });
Cufon.replace('#products ul li a', { fontFamily: 'Stop vlhkosti' });
Cufon.replace('#test legend', { fontFamily: 'Stop vlhkosti' });
Cufon.replace('.more-large span.arrow', { fontFamily: 'Stop vlhkosti' });
Cufon.replace('#products-selection a.more', { fontFamily: 'Stop vlhkosti' });
