/*pushoptions*//*cleearoptions*//*jslint browser:true*//*jslint white:false*//*jslint strict:false*//*jslint devel:true*//*jslint widget: true*//*jslint onevar:false*//*jslint undef:true*//*jslint nomen:true*//*jslint eqeqeq:true*//*jslint plusplus:false*//*jslint bitwise:true*//*jslint regexp:true*//*jslint maxerr: 200*/
/* -- utf-8 check -- ěščřžýáíé -- */
var search_button, js_hover_map_area, js_click_map_area, js_kraj_id, dealer_search_form, form_validation, x_box, region, search_value, elRotator;

window.addEvent("domready", function() {

            /* roll */
       
  if($("product_list")){          
    var product_list = new Roll({
      id : "product_list_wheeler", 
      prev_id : "product_list_wheeler_right",
      next_id : "product_list_wheeler_left",
      crop_width : 654,
      item_width : 654,
      item_width_addend : 0,
      visible_items : 1,
      duration : "normal",
      transition : "sine:out",
      stop_wheeling : "true"
    });
  } 

				/* xbox */
	x_box = new XBox();

				/* form-validation */
	form_validation = new FormValidation({
		default_border : "1px solid #CEC7B7"
	});

				/* targetblanks */

	$$("a.targetblank").addEvent("click", function(event) {
		if(typeof window.open(this.href) === "object") {
			event.stop();
	  }
	});

	if($("search_kraj_submit")) {
	  $("search_kraj_submit").addEvent("click", function(){
			$("search_kraj").submit();
			return false;
	  });
	}
      
	if($("search_k")) {
	  $$("#search_k map area").addEvent("click", function(){
	  	$("k_id").value = this.className;
			$("search_k").submit();
			return false;
	  });
	}
      
  if($$("enquiry_form")) {
	  $$(".enquiry_form .submit_button_real").setStyle("display","none");
	  $$(".enquiry_form .submit_button").setStyle("display","block");
		$$(".enquiry_form .submit_button").addEvent("click", function(){
			this.parentNode.parentNode.submit();
	  });
	}
	
	      /* spam filter */

		
	if($$(".being")){
		var r=/u\s(.+)\s.+\s(.+)\sa/i;
	  $$(".being").each(function(el){
			var n=r.exec(el.getFirst().innerHTML);
			el.getLast().value=readNumber(n[1])+readNumber(n[2]);
			el.setStyle("display","none");
	  });
	}
		
		
		
  if($("checkc")){
     var l=$("txt").innerHTML;
     var r=/u\s(.+)\s.+\s(.+)\sa/gi;
     var n=r.exec(l);
     $("f_check").value=readNumber(n[1])+readNumber(n[2]);
     $("checkc").setStyle("display", "none");
  }

        /* validation-form value */
        
  tmp = $$("form.test_value");
	if(tmp && tmp.length > 0) {
    tmp.addEvent('submit', function() {
    	var v, els, i, elsL;
    	els = this.retrieve('inputs');
    	if (els && els !== false) {
			}
			else {
				els = this.getElements('input.ks_val');
				if (els && els.length > 0) {
					this.store('inputs', els);
				}
				else {
					this.store('inputs', false);
				}
			}

			if (els && els !== false) {
				for (i = 0, elsL = els.length; i < elsL; i++) {
		    	v = els[i].value;
		    	if (isNaN(v) || parseInt(v, 10) != v || v < 1 || v.test(/[\D]{1,}/)) {
		    		els[i].focus();
		    		alert('Do kolonky pro množství prosím zadejte celé kladné číslo.');
		    		return false;
					}
					else {
						v = v.toInt();
			      if (v > 1000) {
			    		els[i].focus();
			        alert("Maximální počet objednáných výrobků jednoho druhu je 1000.\n\rDěkueme za pochopení.");
			        return false;
			      }
			    }
				}
			}
    });
  }

				/* dealer map */
	if($("dealer_search_lcol")) {
	  region = {
	    "map_def" : 1,
	    "liberecky_kraj" : 10,
	    "moravskoslezsky_kraj" : 12,
	    "olomoucky_kraj" : 13,
	    "pardubicky_kraj" : 16,
	    "plzensky_kraj" : 17,
	    "stredocesky_kraj" : 20,
	    "ustecky_kraj" : 24,
	    "kraj_vysocina" : 25,
	    "zlinsky_kraj" : 26,
	    "hlavni_mesto_praha" : 3,
	    "jihocesky_kraj" : 5,
	    "jihomoravsky_kraj" : 6,
	    "karlovarsky_kraj" : 7,
	    "kralovehradecky_kraj" : 9
	  };
	  
	  if($("legend")){
	  var help = $("question_mark");
  	var helpIn = $("legend");
  	if (help) {
  		help.addEvent("mouseenter", function() {
  			helpIn.setStyle("display", "block");
  		});
  		helpIn.addEvents({
  			'mouseenter': function() {
  				helpIn.setStyle("display", "block");
  			},
  			'mouseleave': function() {
  				helpIn.setStyle("display", "none");
  			}
  		});
  	} 
		} 
	
	  js_hover_map_area = $("js_hover");
	  js_click_map_area = $("js_click");
	  js_kraj_id = $('kraj_id');
	  dealer_search_form = $('dealer_search_form');
	
		$$("#dealer_search_lcol map area").addEvent("mouseenter", function(){
			js_hover_map_area.setProperties({"class": "map_hover", title: this.title, width: this.alt}).addClass(this.id);
		});
		$("js_prague").addEvents({
			"mouseenter": function() {
				this.removeClass("disabled");
				js_hover_map_area.className = "map_hover map_def";
			},
			"mouseleave": function() {
				this.addClass("disabled");
			},
			"click": function() {
				js_click_map_area.className = "map_hover hlavni_mesto_praha";
				js_kraj_id.value = "3";
				dealer_search_form.submit();
			}
		});
		js_hover_map_area.addEvent("click", function() {
			js_click_map_area.className = this.className;
			js_kraj_id.value = region[this.className.substr(10)];
			dealer_search_form.submit();
		});
		$("map_def").addEvent("click", function() {
			js_click_map_area.className = "map_hover map_def";
			js_kraj_id.value = region[this.className.substr(10)];
			dealer_search_form.submit();
			return false;
		});
		$('f_kraj').addEvent('change', function(){
			js_kraj_id.value = region[this.options[this.selectedIndex].value];
			this.form.submit();
		});
	}

/* search text */

	if($$("html").get("lang") == "en"){
	  search_value = "Search word...";
	} else {
	  search_value = "Hledaný výraz...";
	}

	search_button = $("search_button");

	if(search_button){
	  if(search_button.get('value') === "") {
	    search_button.set('value', search_value);
	  }
	  search_button.addEvents({
			"click": function() {
		    if(this.get('value') === search_value) {
		      this.set('value', "");
		    }
		  },
			"blur": function() {
		    if(this.get('value') === "") {
		      this.set('value', search_value);
		    }
		  }
		});
	}
	

if ($("all_lightbox")){
  $("all_lightbox").setStyle("width", window.getScrollWidth()-17);
  $("all_lightbox").setStyle("height", window.getScrollHeight());
  
  $$("#all_lightbox, #all_lightbox_box").addEvent("click", function(event){
    $("all_lightbox").setStyle("display","none");
    $("all_lightbox_box").setStyle("display","none");
    return false;
  });
}


	/* input file */

$$('input[type=file]').filestyle();

});

function initAll() {
	var el, overFce = function(){
		this.addClass('hovered');
	}, outFce = function(){
		this.removeClass('hovered');
	}, clickFce = function(){
		$("kraj_id").value = this.rel;
		$("search_kraj").submit();
		return false;
	};

	el = $('hpPlaces');
	if (el) {
		el.addEvents({'mouseenter':overFce,'mouseleave':outFce});
		el.getElements("a").addEvent("click", clickFce);
	}
	elRotator = $('rotator');
	if (elRotator) {
		var overFce2 = function(){
			elRotator.set('class',this.id);
		}, outFce2 = function(){
			elRotator.set('class',elRotator.retrieve('puvClass'));
		};
		elRotator.getLast().getChildren().addEvents({'mouseenter':overFce2,'mouseleave':outFce2})
		elRotator.store('puvClass',elRotator.get('class'));
	}
	el = $('hpBoxes');
	if (el) {
		var overFce3 = function(){
			this.getFirst().fade('in');
		}, outFce3 = function(){
			this.getFirst().fade('out');
		};
		el.getChildren('div.bx').addEvents({'mouseenter':overFce3,'mouseleave':outFce3}).getFirst().set('opacity',0);
	}

	el = $$('input.labeled,textarea.labeled');
	if (el && el.length > 0) {
		el.each(function(el){
			el.addEvents({
				keyup:function(event){
					this.getPrevious().addClass('hide');
				},
				keydown:function(event){
					this.getPrevious().addClass('hide');
				},
				click:function(){
					if (this.get('value') != ''){
						this.getPrevious().addClass('hide');
					}
				},
				focus:function(){
					if (this.get('value') != ''){
						this.getPrevious().addClass('hide');
					}
					else if(this.get('value') == '') {
						this.getPrevious().addClass('hide');
					}
				},
				blur:function(){
					if (this.get('value') == ''){
						this.getPrevious().removeClass('hide');
					}
					else {
						this.getPrevious().addClass('hide');
					}
				}
			});
			if (el.get('value') != '') {
				el.getPrevious().addClass('hide');
			}
			el.getPrevious().addEvent('click',function(){
				this.addClass('hide');
			});
		});
	}
  el = $$("form.styledForm");
  if (el && el.length > 0) {
   el.addClass("styledFormJS");
   Custom.init();
  }
}

      /* input file */


Element.implement({
	filestyle : function(options) {
		var ex,_filename,_wrapper;

		this.setProperty('value','');								
		_wrapper = new Element("span",{ // vytvori span.wrapper-file.filestyle, ktery obali cely input[type=file]
			'class':'wrapper-file',
			styles:{
				'display': "inline",
				'position': "relative",
				'overflow':'hidden'
			}
		}).addClass('filestyle');

		_filename = new Element("input",{ // vytvory input[type=text].filetext
			'class': this.getProperty("class"),
			'type': 'text',
			styles:{
				display: "inline",
				background:'#ffffff url(/common/images/layout/background/input-file.png) no-repeat'
			}
		}).addClass('filetext');
	
		_filename.inject(this,'before'); // vlozi input (viz. vyse) pred originalni input[type=file]
		_wrapper.wraps(this);
	
		this.setStyles({
			position: "absolute",
			top: "0",
			fontSize:20,
			right:0,
			marginRight:25,
			display: "inline"
		}).set('opacity',0.05); // nastavi orig. input[type=file] opacity => je pruhledny, ale klikatelny

		this.addEvent("change", function(el) {
			el.set('value',this.get('value').split("\\").pop());
		}.bind(this,_filename));
		_filename.setStyle('visibility',"visible");
	}
});


  /* Form-Antispam readNumber function */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('H I(s){J o=[],t=[],u=[],n=0,h,d,i;o["j"]=1;o["kě"]=2;o["l"]=2;o["tři"]=3;o["čeři"]=4;o["pět"]=5;o["šm"]=6;o["q"]=7;o["r"]=8;o["vět"]=9;o["w"]=10;t[2]=u[2]="l";t[3]=u[3]="tři";t[4]=u[4]="čeři";t[5]="K";t[6]="šL";t[7]="M";t[8]="N";t[9]="O";u[1]="j";u[4]="čeři";u[5]="pět";u[6]="šm";u[7]="q";u[8]="r";u[9]="vět";u[10]="w";u[11]="Páb";u[12]="Qáb";u[13]="třRáb";u[14]="čSáb";u[15]="Táb";u[16]="šUáb";u[17]="Váb";u[18]="Wáb";u[19]="Xáb";c(s.a("x")>-1||s.a("yě")>-1||s.a("Y")>-1||s.a("z")>-1){c(s.a("x")>-1){n+=A}f c(s.a("yě")>-1){n+=Z}f c(s.a("třB")>-1){n+=1a}f c(s.a("čeřB")>-1){n+=1b}f{h=s.C(0,s.a("z"));c(o[h]){n+=o[h]*A}}}c(s.a("sát")>-1||s.a("D")>-1){d=(s.a("sát")>-1)?s.a("sát"):s.a("D");E(i=2;i<10;i++){c(s.C(d-t[i].g,d)==t[i]){n+=i*10;F}}}E(i=1;i<1c;i++){c(s.G(u[i])>-1&&s.G(u[i])==s.g-u[i].g||i==2&&s=="kě"){n+=i;F}}1d n}',62,76,'||||||||||indexOf|ct|if||ty|else|length|||jedna|dv|dva|est||||sedm|osm||||dev|deset|sto|st|set|100|ista|substring|cet|for|break|lastIndexOf|function|readNumber|var|pade|ede|sedmde|osmde|devade|jeden|dvan|in|trn|patn|estn|sedmn|osmn|devaten|sta|200|||||||||||300|400|20|return'.split('|'),0,{}));

