/* --------------------------------------- formularovy validator ---------------------------- */
formValidator = SZN.ClassMaker.makeClass({
    NAME: "formValidator",
    VERSION: "1.0",
    CLASS: "class"
});
formValidator.prototype.$constructor = function(rootObj){
	this.root = SZN.gEl(rootObj);
	this.mailOnly = false;
	this.inputs = this.root.getElementsByTagName('input');
	this.warning = [];
	for(var i=0;i<this.inputs.length;i++){
		if(this.inputs[i].className == 'mailOnly'){ this.mailOnly = this.inputs[i]; }
		var warning = this.inputs[i].getAttribute('warning');
		if(warning == '1'){
			this.warning.push(this.inputs[i]);
		}
	}
	this._go();
}
formValidator.prototype._checkEmail = function(strng){
    var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/
    if(RegExp.test(strng)){
        var error = '';
    }else{
        var error = 'spatne zadany email';
    }
    return error;
}
formValidator.prototype._check = function(){
	if(this.mailOnly == false){
		for(var i=0;i<this.warning.length;i++){
			if(this.warning[i].value == ''){
				this.message += this.warning[i].name+' - nevyplněno \n';
			}
		}
	} else {
		if(this.mailOnly.checked == false){
			for(var i=0;i<this.warning.length;i++){
				if(this.warning[i].value == ''){
					this.message += this.warning[i].name+' - nevyplněno \n';
				}
			}
		} else {
			var emailError = this._checkEmail(this.root.email.value);
			if(emailError != ''){ this.message = emailError; }
		}
	}
}
formValidator.prototype._onSubmit = function(e,elm){
	this.message = '';
	this._check();
	if(this.message != ''){
		SZN.Events.cancelDef(e);
		alert(this.message);
	} else { return true; }
}
formValidator.prototype._go = function(){
	this.submitAction = SZN.Events.addListener(this.root,'submit',this,'_onSubmit',false,true);
}



/* ----------------------------------------- zilka map area menu --------------------------------------------------*/
zilkaMenu = SZN.ClassMaker.makeClass({
    NAME: "zilkaMenu",
    VERSION: "1.0",
    CLASS: "class"
});
zilkaMenu.prototype.$constructor = function(){
	this.rootMap = SZN.gEl('zilkaMap');
	this.rootMenu = SZN.gEl('menu');
	this.rootImg = SZN.gEl('mainImg');
	this.rootTxt = SZN.gEl('home');
	this.texts = [];
	this.areas = [];
	this.menus = [];
	this.imgs = [];
	this.classes = ['kolekce','dbc','diagnostika','rezervace','novinky','kontakt'];
	var areas = this.rootMap.getElementsByTagName('area');
	var menus = this.rootMenu.getElementsByTagName('a');
	var imgs = this.rootImg.getElementsByTagName('a');
	var texts = this.rootTxt.getElementsByTagName('div');
	for(var i=0;i<texts.length;i++){ this.texts.push(texts[i]); }
	for(var i=0;i<areas.length;i++){
		this.areas.push(areas[i]);
		this.menus.push(menus[i]);
		this.imgs.push(imgs[i]);
 	}
	this._go();
}
zilkaMenu.prototype._show = function(e,elm){
	SZN.Events.stopEvent(e);
	for(var i=0;i<this.areas.length;i++){
	    /* schovani menu kdyz je aktivni */
	    if(this.menus[i].className.indexOf('active') > 0){
         	var mc = this.menus[i].className.split('active');
            this.menus[i].className = mc[0];
		}
	    /* kdyz souhlasi je to ta area */
	    if(this.areas[i].className == elm.className){
	        /* zaktivneni menu */
	        if(elm == this.areas[i]){
	        	this.menus[i].className = elm.className+' active';
	        }
	        /* rozdani souradnic */
	        switch(elm.className){
	            case 'kolekce': var coord = ['0','61']; break;
	            case 'diagnostika': var coord = ['277','46']; break;
	            case 'dbc': var coord = ['80','57']; break;
	            case 'rezervace': var coord = ['480','159']; break;
	            case 'novinky': var coord = ['523','207']; break;
	            case 'kontakt': var coord = ['584','50']; break;
			}
			/* zviditelneni obrazku */
	        this.imgs[i].style.display = 'block';
	        this.imgs[i].style.visibility = 'visible';
	        this.imgs[i].style.left = coord[0]+'px';
	        this.imgs[i].style.top = coord[1]+'px';
		} else { /* jinak zneviditelneni */
		    this.imgs[i].style.display = 'none';
	        this.imgs[i].style.visibility = 'hidden';
		}
	}
	for(var i=0;i<this.texts.length;i++){
    	var cn = this.texts[i].id;
		var txtId = cn.split('hp_');
		//alert(elm.className.indexOf(txtId[1]));
		if(elm.className.indexOf(txtId[1])>=0){
		    this.texts[i].style.display = 'block';
		    this.texts[i].style.visibility = 'visible';
		} else {
		    this.texts[i].style.display = 'none';
		    this.texts[i].style.visibility = 'hidden';
		}
	}
}
/* schovani obrazku */
zilkaMenu.prototype._hide = function(e,elm){
    for(var i=0;i<this.areas.length;i++){
	    if(this.areas[i].className == elm.className){
	        this.menus[i].className = elm.className;
	        this.imgs[i].style.display = 'none';
	        this.imgs[i].style.visibility = 'hidden';
		}
	}
	for(var i=0;i<this.texts.length;i++){
    	var cn = this.texts[i].id;
		var txtId = cn.split('hp_');
		//alert(txtId[1]);
		if(txtId[1] == 'home'){
		    this.texts[i].style.display = 'block';
		    this.texts[i].style.visibility = 'visible';
		} else {
		    this.texts[i].style.display = 'none';
		    this.texts[i].style.visibility = 'hidden';
		}
	}
}
/* rozdani eventu menu a arenam */
zilkaMenu.prototype._go = function(){
	for(var i=0;i<this.areas.length;i++){
		this.areaAction = SZN.Events.addListener(this.areas[i],'mouseover',this,'_show',false,true);
		this.areaOutAction = SZN.Events.addListener(this.imgs[i],'mouseout',this,'_hide',false,true);
		this.menuAction = SZN.Events.addListener(this.menus[i],'mouseover',this,'_show',false,true);
		this.menuOutAction = SZN.Events.addListener(this.menus[i],'mouseout',this,'_hide',false,true);
	}
	for(var i=0;i<this.texts.length;i++){
    	var cn = this.texts[i].id;
		var txtId = cn.split('hp_');
		//alert(txtId[1]);
		if(txtId[1] == 'home'){
		    this.texts[i].style.display = 'block';
		    this.texts[i].style.visibility = 'visible';
		} else {
		    this.texts[i].style.display = 'none';
		    this.texts[i].style.visibility = 'hidden';
		}
	}
}

/*------------------------------  gallery mover  ---------------------------------------------------*/
galleryMover = SZN.ClassMaker.makeClass({
    NAME: "galleryMover",
    VERSION: "1.0",
    CLASS: "class"
});
/*
* konstruktor tridy pro posouvani galerii nahledu
* root - korenovy element ve kterem je element ktery se posouva naplnen nahledy
* move - element nesouci nahledy s pozici absolute pro posouvani
*/
galleryMover.prototype.$constructor = function(root,move){
	this.root = SZN.gEl(root);
	//this.root.style.overflow = 'hidden';
	//this.root.style.position = 'relative';
	this.move = SZN.gEl(move);
	var imgsSize = this.move.getElementsByTagName('img');
	this.imgSize = 0;
	for(var i=0;i<imgsSize.length;i++){
		var imgSize = imgsSize[i].offsetWidth;
		this.imgSize = imgSize > this.imgSize ? imgSize : this.imgSize;
	} 
	//this.move.style.position = 'absolute';
	//this.move.style.top = '0px';
	//this.move.style.left = '0px';
	this.top = 0;
	this.bottom = 0;
	this.moveAction = false;
	if(SZN.Browser.client == 'ie'){
	    var load = SZN.Events.addListener(window,'load',this,'_create',false,true);
	} else {
		this._create();
	}
}
/*
* metoda pro najeti mysi na element pro posunuti nahoru
*/
galleryMover.prototype._upOver = function(e,elm){
	this.moveAction = true;
	this.action = window.setInterval( SZN.bind( this,this._top) ,25);
}
/*
* metoda pro vypocet posunuti nahledu nahoru
*/
galleryMover.prototype._top = function(){
	this.top = this.top >= 0 ? 0 : this.top+10;
	this.move.style.top = this.top+'px';
}
/*
* metoda pro najeti mysi na element pro posunuti dolu
*/
galleryMover.prototype._bottom = function(){
	var heightMove = this.move.offsetHeight;
	var heightRoot = this.root.offsetHeight;
	var differ = parseInt(('-'+(heightMove-heightRoot)),10);
	this.top = this.top <= differ ? differ : this.top-10;
	this.move.style.top = this.top+'px';
}
/*
* metoda pro najeti mysi na element pro posunuti dolu
*/
galleryMover.prototype._downOver = function(e,elm){
	this.moveAction = true;
	this.action = window.setInterval( SZN.bind(this,this._bottom) ,25);
}
/*
* metoda pro zruseni posunu nahoru
*/
galleryMover.prototype._upOut = function(e,elm){
	this.moveAction = false;
	window.clearInterval(this.action);
}
/*
* metoda pro zruseni posunu dolu
*/
galleryMover.prototype._downOut = function(e,elm){
	this.moveAction = false;
	window.clearInterval(this.action);
}
/*
* metoda pro posouvani galerii nahledu pomoci kolecka mysi
*/
galleryMover.prototype._wheelAction = function(e,elm){
	SZN.Events.cancelDef(e);
	var wheelDelta = this._mouseWheelDelta(e);
	var heightMove = this.move.offsetHeight;
	var heightRoot = this.root.offsetHeight;
	var differ = parseInt(('-'+(heightMove-heightRoot)),10);
	if(wheelDelta < 0){
		this.top = this.top <= differ ? differ : this.top-20;
	} else if (wheelDelta > 0){
		this.top = this.top >= 0 ? 0 : this.top+20;
	}
	this.move.style.top = this.top+'px';
}
/*
* metoda pro sjednoceny vypocet delty kolecka mysi
*/
galleryMover.prototype._mouseWheelDelta = function(e){
    if(e.wheelDelta){
        if(window.opera){ delta = (e.wheelDelta/120); }
		else { delta = e.wheelDelta/120; }
    }
	else if(e.detail){ delta = -(e.detail/3); }
    return delta;
}
/*
* metoda pro nalinkovani udalosti na jednotlive elementy
*/
galleryMover.prototype._link = function(){
	if((SZN.Browser.klient != 'ie') && (SZN.Browser.klient != 'opera') && (SZN.Browser.klient != 'safari')){
            this.rollAction = SZN.Events.addListener(this.root,'DOMMouseScroll', this, "_wheelAction", false,true);
    } else {
            this.rollAction = SZN.Events.addListener(this.root,'mousewheel', this, "_wheelAction", false,true);
    }
	this.upOverAction = SZN.Events.addListener(this.up,'mouseover',this,'_upOver',false,true);
	this.downOverAction = SZN.Events.addListener(this.down,'mouseover',this,'_downOver',false,true);
	this.upOutAction = SZN.Events.addListener(this.up,'mouseout',this,'_upOut',false,true);
	this.downOutAction = SZN.Events.addListener(this.down,'mouseout',this,'_downOut',false,true);
}
/*
* metoda pro vytvoreni sipek pro posouvani galerii pri najeti mysi na sipky
*/
galleryMover.prototype._create = function(){
	var up = {
		height:'16px',
		position:'absolute',
		top:'0px',
		width:this.imgSize+'px',
		zIndex:'999',
		background:'url(./img/galleryUp.jpg) bottom center no-repeat'
	}
	var down = {
	    height:'16px',
		position:'absolute',
		bottom:'0px',
		width:this.imgSize+'px',
		zIndex:'999',
		background:'url(./img/galleryDown.jpg) bottom center no-repeat'
	}
	this.up = SZN.cEl('div','','',up);
	this.down = SZN.cEl('div','','',down);
	this.root.appendChild(this.up);
	this.root.appendChild(this.down);
	var movers = [this.up,this.down];
	this._link();
}
/*******************  Image Changer **********************
 *	Changovani obrazku v predanem elementu kde v Divu je jeden hlavni obrazek a ve spanu je obrazek za ktery se ma hlavni vymenit 
 **/
imageChanger = SZN.ClassMaker.makeClass({
    NAME: "imageChanger",
    VERSION: "1.0",
    CLASS: "class"
});
imageChanger.prototype.$constructor = function(root){
	this.root = SZN.gEl(root);
	SZN.Events.onDomReady(this,'_link');
	//this._link();
}
imageChanger.prototype._showNextImg = function(e,elm){
	var imgSrc = elm.src;
	var imgSplt = imgSrc.split('/');
	var imgCh = imgSplt[imgSplt.length-1];
	var imgCh1 = imgCh.split('.');
	var imgChSrc = imgCh1[0]+'1.'+imgCh1[1];
	var imgPath = '';
	for(var i=0;i<imgSplt.length-1;i++){
		imgPath += imgSplt[i]+'/';
	}
	imgPath += imgChSrc;
	elm.src = imgPath;
}
imageChanger.prototype._hideNextImg = function(e,elm){
	var imgSrc = elm.src;
	var imgSplt = imgSrc.split('/');
	var imgNextSplt = imgSplt[imgSplt.length-1].split('.');
	var imgName = imgNextSplt[0].substring(0,(imgNextSplt[0].length-1));
	var imgPath = '';
	for(var i=0;i<(imgSplt.length-1);i++){
		imgPath += imgSplt[i]+'/';
	}
	imgPath += imgName+'.'+imgNextSplt[1];
	elm.src = imgPath;
}
imageChanger.prototype._link = function(){
	var divs = this.root.getElementsByTagName('div');
	for(var i=0;i<divs.length;i++){
		var imgs = divs[i].getElementsByTagName('img');
		var showAction = SZN.Events.addListener(imgs[0],'mouseover',this,'_showNextImg',false,true);
		var hideAction = SZN.Events.addListener(imgs[0],'mouseout',this,'_hideNextImg',false,true);
	}
}
/*******************  Image Roller **********************
 *	Rollovani obrazku ulozenych v poli pri fadovacim prechodu
 *	Vyzaduje interpolator.js  
 **/
photoRoll = SZN.ClassMaker.makeClass({
    NAME: "photoRoll",
    VERSION: "1.0",
    CLASS: "class"
});
photoRoll.prototype.$constructor = function(photos,root){
	this.photos = photos;
	this.root = SZN.gEl(root);
	//this.root.innerHTML = '';
	this.numPhotos = this.photos.length;
	//SZN.Events.onDomReady(this,'_makeImg');
	window.setTimeout(SZN.bind(this,this._makeImg), 10000);
}
photoRoll.prototype._randomNum = function(max){
	var rn = Math.floor(Math.random()*max);
	return rn;
}
photoRoll.prototype._makeImg = function(){
	this.root.innerHTML = '';
	var i = this._randomNum(this.numPhotos);
	this.img = SZN.cEl('img');
	this.img.src = this.photos[i];
	this.root.appendChild(this.img);
	this._showImg();
}
photoRoll.prototype._showImg = function(){
	var intr = new SZN.CSSInterpolator(this.root, 3000,{});
	var opacityInt = SZN.Browser.client == 'ie' ? 100 : 1;
	intr.addProperty('opacity',0,opacityInt,'');
	intr.start();
	window.setTimeout(SZN.bind(this,this._nextImg), 10000);
}
photoRoll.prototype._nextImg = function(){
	this.root.removeChild(this.img);
	this._makeImg();
}
/*******************  Gallery **********************
 *	jednoducha galerie pro zobrazovani obrazku ktere jsou umistene v jednom elementu a jsou zobrazovane ve druhem elementu 
 **/
photoGallery = SZN.ClassMaker.makeClass({
    NAME: "photoGallery",
    VERSION: "1.0",
    CLASS: "class"
});
photoGallery.prototype.$constructor = function(imgsRoot,showRoot){
	this.imgsRoot = SZN.gEl(imgsRoot);
	this.showRoot = SZN.gEl(showRoot);
	this._go();
}
photoGallery.prototype._showImg	= function(e,elm){
	var path = elm.src.split('?')[1];
	var imgPath = path.split('&')[0];
	var img = imgPath.split('Path=')[1];
	var imgRoot = this.showRoot.getElementsByTagName('img')[0];
	imgRoot.src = img;
}
photoGallery.prototype._go = function(){
	var imgs = this.imgsRoot.getElementsByTagName('img');
	for(var i=0;i<imgs.length;i++){
		var showAction = SZN.Events.addListener(imgs[i],'click',this,'_showImg',false,true);
	}
}

