function setMask(I,M){
	function R(s){return new RegExp('('+s.replace(/\(/g,'\\(').replace(/\)/g,'\\)').replace(/\//g,'\\/').replace(/9/g,'\\d').replace(/a/g,'[a-zā-˙¸]').replace(/\*/g,'[a-zā-˙¸0-9]')+')','gi')}
	function N(c,j,x){
		for(var k=0,s='';k<L;k++)s+=$[k]||c||'_';
		I.value=s;
		x?0:I.sC(!j?i:0)
	}
	function D(e,p,i){
		p=I.gC();
		if (p[0]==p[1]) {
			if(e)p[1]++;
			else p[0]--
		}
		for(i=p[0];i<p[1];i++)
			if(!S[i]&&$[i]){
				$[i]=0;
				j--
			}
		return p
	}
	function V(){
		setTimeout(function(k){
				if (R(M).test(I.value)) {
					I.value=RegExp.$1;
					$=I.value.split('');
					for(k=j=0;k<L;k++)if(!S[k])j++
				}
				else N()
			},0)
	}
	function P(c){
		if (c<35&&c!=8&&c!=32||c==45) return 1;
		switch(c){
			case 8:		i=D()[0]; return 0;
			case 46:	i=D(1)[1]; return 0;
			case 35:    i = L; return 1;
			case 36:    i = 1;
			case 37:    if (i-=2<-1) i=-1;
			case 39:    if (++i>L) i=L; return 1;
			default:    i=I.gC()[0];
						while(i<L&&S[i]){i++}
						if (i==L) return 0;

						c = String.fromCharCode(c)
						if (R(M.charAt(i)).test(c)) {
							D(1);
							$[i++] = c;
							j++;
							while(i<L&&S[i]){i++}
						}
						return 0
		}
	}

	var d=document, c='character', y=-100000, L=M.length, G=!c, i=0, j=0, $=M.split(''), S=M.split('');

	for (var k=0;k<L;k++) if (/a|9|\*/.test($[k])) $[k]=S[k]=0;
	I = typeof I=='string' ? d.getElementById(I) : I;
 
	I.sC = function(l,g){
		if(this.setSelectionRange) this.setSelectionRange(l,l);
		else {
			g = this.createTextRange();
			g.collapse(true);
			g.moveStart(c,y);
			g.move(c,l);
			g.select();
		}
	}
	I.gC = function(r,b){
		if (this.setSelectionRange) return [this.selectionStart,this.selectionEnd];
		else {
			r = d['selection'].createRange();
			b = 0-r.duplicate().moveStart(c,y)
			return [b,b+r.text.length]
		}
	}
	I.onfocus = function(){
		setTimeout(function(){N(0,!j)},0)
	}
	I.onblur = function(){
		j ? N(' ',0,1) : this.value=''
	}
	I.onkeydown = function(e,c){
		e = e||event;
		c = e.keyCode||e.charCode;

		if (c==8||c==46) {
			G = true;
			P(c);
			N();
			return !G
		}
		else if (!window.netscape&&(c>34&&c<38||c==39)) P(c)
	}
	I.onkeypress = function(e){
		if (G) return G=!G;

		e = e||event;

		if (P(e.keyCode||e.charCode)) return !G;

		N();

		return G
	}

	if (d.all&&!window.opera) I.onpaste=V;
	else I.addEventListener('input',V,false)
}

function fireEvent(element,event){
if (document.createEventObject){
// dispatch for IE
var evt = document.createEventObject();
return element.fireEvent('on'+event,evt)
}
else{
// dispatch for firefox + others
var evt = document.createEvent("HTMLEvents");
evt.initEvent(event, true, true ); // event type,bubbling,cancelable

return !element.dispatchEvent(evt);
}
}


var mapareas = [];
var auto;

var mapballooncoords = [
	[[244],[174]],
	[[272],[103]],
	[[357],[82]],
	[[233],[166]],
	[[302],[169]],
	[[367],[157]],
	//[[415],[183]],
	//[[486],[188]],
	[[208],[218]],
	[[246],[234]],
	[[295],[220]]
]

tooltip = function(target_items, name, prefix) {
	if (!prefix) prefix = "default";
	body = $$("body").first();

	$$(target_items).each(function(item, index) {
		body.insert("<div class='" + name + "' id='" + prefix + name + index + "'><span><span><span><span>" + item.readAttribute("title") + "</span></span></span></span></div>");
		var my_tooltip = $(prefix + name + index);
		item.writeAttribute("title", false);
		item.onmouseover = function() {
			my_tooltip.appear({
				duration: 0.2
			});
		}
		item.onmousemove = function(event) {
			delta = $(document.body).getDimensions().width - (Event.pointerX(event) + my_tooltip.getWidth() / 2) - 10;
			if (delta > 0) delta = 0;
			my_tooltip.setStyle({
				left: parseInt(Event.pointerX(event) - 50 + delta) + "px",
				top: parseInt(Event.pointerY(event) + 10) + "px"
			});
		}
		item.onmouseout = function() {
			my_tooltip.fade({
				duration: 0.2
			});
		}
	});
}

tooltip2 = function(target_items, name, prefix) {
	if (!prefix) prefix = "default";
	body = $$("body").first();

	$$(target_items).each(function(item, index) {
		body.insert("<div class='" + name + "' id='" + prefix + name + index + "'><span><span><span><span>" + item.readAttribute("title") + "</span></span></span></span><div class='pointer'><!-- --></div></div>");
		var my_tooltip = $(prefix + name + index);
		item.writeAttribute("title", false);

		my_tooltip.setStyle({
			left: parseInt(Position.page(item)[0]) + 40 + "px",
			top: parseInt(Position.page(item)[1]) - my_tooltip.offsetHeight - 5 + "px"
		});

		Event.observe(window, "resize", function() {
			my_tooltip.setStyle({
				left: parseInt(Position.page(item)[0]) + 40 + "px",
				top: parseInt(Position.page(item)[1]) - my_tooltip.offsetHeight - 5 + "px"
			});
		});
	});
}

mapballoon = function(target_items, name) {
	//mapid = $("mapid");

	$$(target_items).each(function(item, index) {
		$("mapid").insert("<div class='" + name + "' style='display: none;' id='" + name + index + "'><div class='left'>" + item.readAttribute("title") + "</div><div class='right'><!-- --></div></div>");
		var my_balloon = $(name + index);

		my_balloon.setStyle({
			left: mapballooncoords[index][0] + "px",
			top: mapballooncoords[index][1] + "px"
		});
		item.writeAttribute("title", false);

		item.observe("mouseover", function(e) {
			my_balloon.show();
		});

		item.observe("mouseout", function(e) {
			my_balloon.hide();
		});
	});
}

FancyZoomBox.directory = "/project/imgs/fancyzoom";

Event.observe(window, "load", function() {
	tooltip(".wb","balloon");
	tooltip2(".wb2","balloon", "t");

	mapballoon("area","mballoon");

	mapareas = $$(".areas img");
	$$("area").each(function(item, index) {
		item.onmouseover = function() {
			mapareas[index].setStyle({
				display: "block"
			});
		}
		item.onmouseout = function() {
			if (!mapareas[index].hasClassName("active")) {
				mapareas[index].setStyle({
					display: "none"
				});
			}
		}
	});

	$$("a.variant-button").each(function(item) {
		new FancyZoom(item);
	});
	$$("a.photolink").each(function(item) {
		new FancyZoom(item);
	});
	$$("a.calphotolink").each(function(item) {
		new FancyZoom2(item);
	});
	$$("a.calcell").each(function(item) {
		new FancyZoom2(item);
	});
	$$(".calendars a.zoom").each(function(item) {
		auto = new FancyZoom2(item);
		if(item.hasClassName('autoshow')) {
			fireEvent(item, 'click');
		}
	});
	$$("a.period").each(function(item) {
		new FancyZoom(item);
	});
	$$("a.period-button").each(function(item) {
		new FancyZoom(item);
	});
/*
	$$("a.red-button").each(function(item) {
		new FancyMessage(item);
	});
*/
	G =  new k.Growler();

}, false);

var G = {};

/*
Message = function(text) {
	$('message_content').innerHTML = text;
}
*/

/*
var FancyMessage=Class.create({initialize:function(A){
	this.options=arguments.length>1?arguments[1]:{};
	FancyZoomBox.init();
	this.element=$(A);
	if(this.element){
		this.element.content_div=$('message');
		this.element.content_div.hide();
		this.element.zoom_width=this.options.width;
		this.element.zoom_height=this.options.height;
		this.element.observe("click",FancyZoomBox.show)
	}
}});
*/
