function checkAllStateChange(la, state) {
	if (la.hasClassName('checkuncheck')) {
		$$('.filter .kvl').each(function(el) {
			if (!el.hasClassName('checkuncheck')) {
				if (!state) {
					el.down('.real').checked = false;
					el.down('.input').removeClassName('checked');
				}
				else {
					el.down('.real').checked = true;
					el.down('.input').addClassName('checked');
				}
			}
		});
	}
}

function checkStates() {
	$$('.kvl').each(function(la) {
		if (la.down('input').readAttribute('type') == 'checkbox') {

			la.insert({ top : new Element('span', { 'class' : 'input' }) });
			la.down('.real').setStyle({ 'display' : 'none' });

			if (la.down('input').checked == true) la.down('.input').addClassName('checked');

			la.down('.input').observe('mouseup', function(ev) {
				el = ev.element();
				if(la.down('input').disabled) {
					ev.stop();
					return;
				}
				
				if (la.down('input').checked == true) {
					la.down('.real').click();
					la.down('.input').removeClassName('checked');
					checkAllStateChange(la, false);
				}
				else if (la.down('input').checked == false) {
					la.down('.real').click();
					la.down('.input').addClassName('checked');
					checkAllStateChange(la, true);
				}
			});
		}
	});
	
}

document.observe('dom:loaded', checkStates);

function ShowCountry(country)
{
	$('map').hide();
	$('country').writeAttribute('style', 'background: url(img/country/'+country+'.jpg) no-repeat 0 0; display: block;');
}
function BackGlobal()
{
	$('map').show();
	$('country').hide();
}

document.observe('dom:loaded', function(){
	if ($$(".model_3d").size()) {
		$$('.model_3d .menu li a').each(function(el, index){
			el.observe('click', function(ev){
				var sel = index + 1;
				$$('.model_3d .pop').each(function(el){
					el.hide();
				});
				$$('.model_3d .menu li a').each(function(el){
					el.removeClassName('sel');
				});
				$('pop0'+ sel).show();
				el.addClassName('sel');
			});
		});
	}	
});

function openPopup(url,name,height,width,opt_show_scrollbars){
	var scrollbar_param=opt_show_scrollbars?",scrollbars=1":"";
	var newwindow=window.open(url,name,'height='+height+',width='+width+scrollbar_param);
	if(newwindow&&!newwindow.opener){newwindow.opener=window;}
	if(window.focus){newwindow.focus()}
	return false;
}

//
//	Trieda pre mazanie defaultnych textov v inputoch
//	 pri zanechani prazdneho inputu sa naspet vrati hodnota na podovnu
//
var InputCleaner = Class.create({
	inputId: '',
	input: null,
	oldValue: '',
	initialize: function(inputId) {
		this.inputId = inputId;
		this.input = $(this.inputId);
		if (this.input != null) {
			this.oldValue = this.input.getValue();
			this.input.observe('focus', this.onActivate.bindAsEventListener(this));
			this.input.observe('blur', this.onDeactivate.bindAsEventListener(this));
		}
	},
	onActivate: function(event) {
		if (this.input.getValue() == this.oldValue) {
			this.input.setValue('');
		}
	},
	onDeactivate: function(event) {
		if (this.input.getValue() == '') {
			this.input.setValue(this.oldValue);
		}
	}
});
