function generate_fotogallery(){
    $$('.fotos_list').each(function(list){
        list.getElements('a').each(function(anchor){
            anchor.setStyles({
                height: 75,
                width:75,
              //  overflow: 'hidden',
                display: 'block',
                float: 'left'
               // border: '2px solid white' 
            })
            
            var img = anchor.getElement('img');
            img.setStyle('position','relative');
            if (img.width >= 75){ img.setStyle('left',(-1)*((img.width-75)/2)) } 
            if (img.height >= 75){ 
                img.setStyle('top',(-1)*((img.height-75)/2)) 
            } else {
                /*
                new_src = img.src.replace("small", 'normal');
                var tmp_img = new Image();
                tmp_img.addEvent('load', function(){
                    
                    img.setProperty('src',new_src);
                    img.setStyle('top',(-1)*((tmp_img.height-75)/2));
                    img.setStyle('left',(-1)*((tmp_img.width-75)/2));
                });
                tmp_img.src= new_src;
                */
            } 
        })
    });
}


function filebrowser_preloader() {
	el=$('filebrowser_preloader').style;
	el.display=(el.display == 'block')?'none':'block';

}

// hide newsletter box
function hide_newsletters(){
$('cancel_newsletters_form').fade('hide');

$('cancel_newsletter_link').addEvent('click', function(e) {
	new Event(e).stop();
	$('newsletters_form').fade(0);
	$('cancel_newsletters_form').fade(1);
});

$('newsletters_link').addEvent('click', function(e) {
	new Event(e).stop();
	$('cancel_newsletters_form').fade(0);
	$('newsletters_form').fade(1);
});
}


function addSearchEngine($cesta,$title,$desc) {
  if ((typeof window.sidebar == "object") &&
      (typeof window.sidebar.addSearchEngine == "function")) {

    window.sidebar.addSearchEngine(
      $cesta+"/search-ff.src",
      //$cesta+"/articles/search_addon",
      $cesta+"/css/fastest/icons/favicon.ico",
      $title,
      $desc);

  } else
    alert("Váš prohlížeč nepodporuje tuto funkci. Zkuste Mozillu.");

}



// tooltips
function footer_tooltips(){
window.addEvent('domready', function(){
		var Tips_help = new Tips($$('.tip_win'),{
			showDelay: 400,
			hideDelay: 8500,
			className: 'tip_win',
			offsets: {'x': -149, 'y': -80},
			fixed: true
	}); 
});
}


// mapa tooltips
function mapa_tooltips(){
window.addEvent('domready', function(){
		var Tips_help = new Tips($$('.tip_win_mapa'),{
			showDelay: 400,
			hideDelay: 400,
			className: 'tip_win_mapa',
			offsets: {'x': 50, 'y': 50},
			fixed: true
	});  
});
}


// skryvani zapomenuteho hesla
function hide_lost_password(){
$('forgot_passwords_form').fade('hide');
$('forgot_password_link').addEvent('click', function(e) {
	new Event(e).stop();
	$('logins_form').fade(0);
	$('forgot_passwords_form').fade(1);
});

$('login_link').addEvent('click', function(e) {
	new Event(e).stop();
	$('forgot_passwords_form').fade(0);
	$('logins_form').fade(1);
});
}

// doporuceni domwin
function doporuceni_win(title){
	domwin.newWindow({
		id			: 'doporuceni_win',
		sizes		: [500,220],
		scrollbars	: false,
		defined_lang: ['cz'],
		languages	: false,
		title		: title,
		ajax_url	: this.href,
		closeConfirm: false,
		max_minBtn	: false,
		modal_close	: true
	}); 
}

// minimalni delka search pole
function min_delka_search(id,text,alert_text,lang){
	
	if (($(id).value == text) || ($(id).value.length < 3))
		alert(alert_text);
	else
		window.location.href =  lang + '/search/' + id.value;
			
}



function getHighestIndex(){				
		var allElems = document.getElementsByTagName?document.getElementsByTagName("*"): document.all; 
		var maxZIndex = 0;
		for(var i=0;i<allElems.length;i++) {
			var elem = allElems[i];
			var cStyle = null;
			if (elem.currentStyle) {cStyle = elem.currentStyle;
			} else if (document.defaultView && document.defaultView.getComputedStyle){
				cStyle = document.defaultView.getComputedStyle(elem,"");
			}
			var sNum;
			if (cStyle) {
				sNum = Number(cStyle.zIndex);
			} else {
				sNum = Number(elem.style.zIndex);
			}
			if (!isNaN(sNum)) {
				maxZIndex = Math.max(maxZIndex,sNum);
			}
		}
		return maxZIndex;
} 

Element.implement({
	inputLimit: function(){
		if (this.hasClass('float')){
			this.addEvent('keypress',function(e){
				var event = new Event(e); 
				var allow_key = ['1','2','3','4','5','6','7','8','9','0',',','backspace','left','right','tab','f5'];	
				if (allow_key.indexOf(event.key) != -1) 
					return true; 
				else 
					return false;			
			});
		} else if (this.hasClass('integer')){
			this.addEvent('keypress',function(e){
				var event = new Event(e); 
				var allow_key = ['1','2','3','4','5','6','7','8','9','0','backspace','left','right','tab','f5'];	
				if (allow_key.indexOf(event.key) != -1) 
					return true; 
				else 
					return false;			
			});
		}
	},
	
	ajaxLoad: function(url, children){
		var empty_value = '--- Zvolte hodnotu ---'
		this.addEvent('change', function(){
			new Request.JSON({
				url: url + this.value,
				onComplete: (function(json){
					children.each(function(obj){
						$(obj).empty();
						new Element('option', {title:empty_value, value:''}).setHTML(empty_value).inject($(obj));
					});
					child = children[0];
					$each(json, function(value, id){
						new Element('option', {title:value, value:id}).setHTML(value).inject($(child));
					}, this);
				}).bind(this)
			}).send();
		});
	},
	
	getOptionText: function(){
		return this.options[this.selectedIndex].getHTML();
	}
});
String.implement({
	camelCase2: function(){
		return this.replace(/_\D/g, function(match){
			return match.charAt(1).toUpperCase();
		});
	}
});

function tisk(){
window.print();
return false;
}

function button_preloader(id){
		id.addClass('button_preloader');
		id.setProperty('disabled');
}

function button_preloader_disable(id){
		id.removeClass('button_preloader');
		id.removeProperty('disabled');
}

// zmena pisma ve clankach
function init_font_changer(){
	Cookie.get("fontType");
	switchFont(Cookie.get("fontType"));

	if ($('switch_f1'))$('switch_f1').addEvent('click',function(e){new Event(e).stop();switchFont(1);setFontSize(1)})
	if ($('switch_f2'))$('switch_f2').addEvent('click',function(e){new Event(e).stop();switchFont(2);setFontSize(2)})
	if ($('switch_f3'))$('switch_f3').addEvent('click',function(e){new Event(e).stop();switchFont(3);setFontSize(3)})



	function switchFont(typ)
	{
		if (typ==1){
		
		$('obal').getElements('.article_text').removeClass('large_font').addClass('small_font');
		$('obal').getElements('.article_anotace').removeClass('large_font').addClass('small_font');				
		$('obal').getElements('.f1').addClass('active');				
		$('obal').getElements('.f2').removeClass('active');				
		$('obal').getElements('.f3').removeClass('active');				
		}
		
		if (typ==2){
		$('obal').getElements('.article_text').removeClass('small_font').removeClass('large_font');				
		$('obal').getElements('.article_anotace').removeClass('small_font').removeClass('large_font');				
		$('obal').getElements('.f1').removeClass('active');				
		$('obal').getElements('.f2').addClass('active');				
		$('obal').getElements('.f3').removeClass('active');				
		}

		if (typ==3){
		$('obal').getElements('.article_text').removeClass('small_font').addClass('large_font');
		$('obal').getElements('.article_anotace').removeClass('small_font').addClass('large_font');				
		$('obal').getElements('.f1').removeClass('active');				
		$('obal').getElements('.f2').removeClass('active');				
		$('obal').getElements('.f3').addClass('active');				
		}
		

	  }
	function setFontSize(typ){
		Cookie.remove('fontType');
		var myCookie  =  Cookie.set('fontType', typ,{path: '/'});

	}
}

 function html_entity_decode (string, quote_style) {
        var hash_map = {}, symbol = '', tmp_str = '', entity = '';
        tmp_str = string.toString();
        
        if (false === (hash_map = this.get_html_translation_table('HTML_ENTITIES', quote_style))) {
            return false;
        }
    
        delete(hash_map['&']);
        hash_map['&'] = '&amp;';
    
        for (symbol in hash_map) {
            entity = hash_map[symbol];
            tmp_str = tmp_str.split(entity).join(symbol);
        }
        tmp_str = tmp_str.split('&#039;').join("'");
        
        return tmp_str;
    }
    
    function get_html_translation_table (table, quote_style) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: noname
    // +   bugfixed by: Alex
    // +   bugfixed by: Marco
    // +   bugfixed by: madipta
    // +   improved by: KELAN
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Frank Forte
    // +   bugfixed by: T.Wild
    // +      input by: Ratheous
    // %          note: It has been decided that we're not going to add global
    // %          note: dependencies to php.js, meaning the constants are not
    // %          note: real constants, but strings instead. Integers are also supported if someone
    // %          note: chooses to create the constants themselves.
    // *     example 1: get_html_translation_table('HTML_SPECIALCHARS');
    // *     returns 1: {'"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;'}
    
    var entities = {}, hash_map = {}, decimal = 0, symbol = '';
    var constMappingTable = {}, constMappingQuoteStyle = {};
    var useTable = {}, useQuoteStyle = {};
    
    // Translate arguments
    constMappingTable[0]      = 'HTML_SPECIALCHARS';
    constMappingTable[1]      = 'HTML_ENTITIES';
    constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
    constMappingQuoteStyle[2] = 'ENT_COMPAT';
    constMappingQuoteStyle[3] = 'ENT_QUOTES';

    useTable       = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS';
    useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT';

    if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') {
        throw new Error("Table: "+useTable+' not supported');
        // return false;
    }

    entities['38'] = '&amp;';
    if (useTable === 'HTML_ENTITIES') {
        entities['160'] = '&nbsp;';
        entities['161'] = '&iexcl;';
        entities['162'] = '&cent;';
        entities['163'] = '&pound;';
        entities['164'] = '&curren;';
        entities['165'] = '&yen;';
        entities['166'] = '&brvbar;';
        entities['167'] = '&sect;';
        entities['168'] = '&uml;';
        entities['169'] = '&copy;';
        entities['170'] = '&ordf;';
        entities['171'] = '&laquo;';
        entities['172'] = '&not;';
        entities['173'] = '&shy;';
        entities['174'] = '&reg;';
        entities['175'] = '&macr;';
        entities['176'] = '&deg;';
        entities['177'] = '&plusmn;';
        entities['178'] = '&sup2;';
        entities['179'] = '&sup3;';
        entities['180'] = '&acute;';
        entities['181'] = '&micro;';
        entities['182'] = '&para;';
        entities['183'] = '&middot;';
        entities['184'] = '&cedil;';
        entities['185'] = '&sup1;';
        entities['186'] = '&ordm;';
        entities['187'] = '&raquo;';
        entities['188'] = '&frac14;';
        entities['189'] = '&frac12;';
        entities['190'] = '&frac34;';
        entities['191'] = '&iquest;';
        entities['192'] = '&Agrave;';
        entities['193'] = '&Aacute;';
        entities['194'] = '&Acirc;';
        entities['195'] = '&Atilde;';
        entities['196'] = '&Auml;';
        entities['197'] = '&Aring;';
        entities['198'] = '&AElig;';
        entities['199'] = '&Ccedil;';
        entities['200'] = '&Egrave;';
        entities['201'] = '&Eacute;';
        entities['202'] = '&Ecirc;';
        entities['203'] = '&Euml;';
        entities['204'] = '&Igrave;';
        entities['205'] = '&Iacute;';
        entities['206'] = '&Icirc;';
        entities['207'] = '&Iuml;';
        entities['208'] = '&ETH;';
        entities['209'] = '&Ntilde;';
        entities['210'] = '&Ograve;';
        entities['211'] = '&Oacute;';
        entities['212'] = '&Ocirc;';
        entities['213'] = '&Otilde;';
        entities['214'] = '&Ouml;';
        entities['215'] = '&times;';
        entities['216'] = '&Oslash;';
        entities['217'] = '&Ugrave;';
        entities['218'] = '&Uacute;';
        entities['219'] = '&Ucirc;';
        entities['220'] = '&Uuml;';
        entities['221'] = '&Yacute;';
        entities['222'] = '&THORN;';
        entities['223'] = '&szlig;';
        entities['224'] = '&agrave;';
        entities['225'] = '&aacute;';
        entities['226'] = '&acirc;';
        entities['227'] = '&atilde;';
        entities['228'] = '&auml;';
        entities['229'] = '&aring;';
        entities['230'] = '&aelig;';
        entities['231'] = '&ccedil;';
        entities['232'] = '&egrave;';
        entities['233'] = '&eacute;';
        entities['234'] = '&ecirc;';
        entities['235'] = '&euml;';
        entities['236'] = '&igrave;';
        entities['237'] = '&iacute;';
        entities['238'] = '&icirc;';
        entities['239'] = '&iuml;';
        entities['240'] = '&eth;';
        entities['241'] = '&ntilde;';
        entities['242'] = '&ograve;';
        entities['243'] = '&oacute;';
        entities['244'] = '&ocirc;';
        entities['245'] = '&otilde;';
        entities['246'] = '&ouml;';
        entities['247'] = '&divide;';
        entities['248'] = '&oslash;';
        entities['249'] = '&ugrave;';
        entities['250'] = '&uacute;';
        entities['251'] = '&ucirc;';
        entities['252'] = '&uuml;';
        entities['253'] = '&yacute;';
        entities['254'] = '&thorn;';
        entities['255'] = '&yuml;';
    }

    if (useQuoteStyle !== 'ENT_NOQUOTES') {
        entities['34'] = '&quot;';
    }
    if (useQuoteStyle === 'ENT_QUOTES') {
        entities['39'] = '&#39;';
    }
    entities['60'] = '&lt;';
    entities['62'] = '&gt;';


    // ascii decimals to real symbols
    for (decimal in entities) {
        symbol = String.fromCharCode(decimal);
        hash_map[symbol] = entities[decimal];
    }
    
    return hash_map;
}

function call_search_count(lang){
	var str = location.href;
var is_sk = str.indexOf("sk");
if (is_sk != -1){
	var lang_pref = '/sk';
} else {
	var lang_pref = '';
}
	new Request.JSON({
        
		url: lang_pref+'/finds-kongress-count/',
        onComplete: function(json){
            if (json && json.result === true){
                $('search_count').removeClass('hidden');
                $('search_count').getElement('span').setHTML(json.count);
            } else {
               // alert('Chyba během komunikace s DB.')
            }
        }
    }).get($('search_hotel_form'))
}


window.addEvent('domready', function(){
var str = location.href;
var is_sk = str.indexOf("sk");
if (is_sk != -1){
	var lang_pref = '/sk';
} else {
	var lang_pref = '';
}
$('search_hotel_form').getElements('.checkbox').addEvent('click',call_search_count);
$('search_hotel_form').getElements('.no_select').addEvent('change',call_search_count);
$('search_hotel_form').getElements('.text').addEvent('change',call_search_count);

$('SearchHotel').addEvent('click', function(e){
    e.stop();
    
    switch($('SearchTypeObject').value){
        case '1':
        case '1|1':
        case '1|2':
        case '1|3':
        case '1|4':
        case '1|5':
            var link = lang_pref+'/kongresove-saly/';
            break;
        case '2':
            var link = lang_pref+'/penziony/';
            break;
    }    
    $('search_hotel_form').setProperty('action',link);
    $('search_hotel_form').submit();
    return true;
});



$('SearchKrajId').ajaxLoad('/kongres_hotels/load_okres/', ['SearchOkresId']);

if ($('search_more_desc'))
	$('search_more_desc').getElement('.close').addClass('none');

$('search_more').addEvent('click', function(){
		if ($('search_more').hasClass('up')){
			
			$('search_more').removeClass('up');
			if ($('search_more_desc')){
				$('search_more_desc').getElement('.open').removeClass('none');
                if ($('m_search'))
                $('m_search').removeClass('block');
				
                $('search_more_desc').getElement('.close').addClass('none');
			}
            //alert(window.location);
                if(window.location != 'http://www.kongrespark.cz/'){
                    $('kongres_search').tween('height', 44);
                } else {
                    $('kongres_search').tween('height', 190);
                }
		} else {
			$('search_more').addClass('up');
			
			if ($('search_more_desc')){
				$('search_more_desc').getElement('.open').addClass('none');
                if ($('m_search'))
                    $('m_search').addClass('block');
				$('search_more_desc').getElement('.close').removeClass('none');
			}
			
			$('kongres_search').tween('height', 640); 
		}
		return false; 
	});
    
    if ($('SearchTypeObject')){
        $('SearchTypeObject').addEvent('change', function(){
            if (this.value == 2){
                $('salonky_search').addClass('none');
                $('change_label').setHTML('Vybavení penzionu');
            } else {
                $('salonky_search').removeClass('none');
                $('change_label').setHTML('Vybavení hotelu');
            }
        })
    }
})



	var MapHotel = new Class({
		name: 'MapHotel',
		Implements: [Options, Events],
		options: {
			key: '',
			url: 'http://www.google.com/jsapi?key=',
			adr: '',
			maps_items:[]
		},
		markers:[],
		points:[],
		adrs:[],
		adrs_p:[],
        ikony:[],
		k : 0,
		initialize: function(element,options){
			this.setOptions(options);
			this.element = $(element);
			var script = document.createElement("script");
			script.src = this.options.url + this.options.key + "&callback=MapHotelMapa.script_load";
			script.type = "text/javascript";
			document.getElementsByTagName("head")[0].appendChild(script);	
		},
		
		script_load: function(){
			google.load("maps", "2", {"callback" : 
				(function(){
					this.map = new google.maps.Map2(this.element);
					this.geocoder = new GClientGeocoder();
					this.bounds = new GLatLngBounds();
					var customUI = this.map.getDefaultUI();
					this.map.setUI(customUI);

					this.map.setCenter(new GLatLng(0,0),12);
					this.map.removeMapType(G_HYBRID_MAP);
					this.map.disableScrollWheelZoom();
					
					
					$each(this.options.maps_items, function(obj, index){
						this.adrs[index] = obj.adresa;
						this.adrs_p[index] = html_entity_decode(obj.popis);
						this.ikony[index] = obj.icon;
					},this);
					//alert(this.options.maps_items[0]);;
					this.showAddress();
					
				}).bind(this)
			});
			
			$(document.body).addEvent('unload',function(){GUnload()});
		},
						
		showAddress: function(){
			if (this.geocoder) {
				map = this.map;
				var adr = this.adrs[this.k];
				var popis = this.adrs_p[this.k];
				var ikona = this.ikony[this.k];
				this.geocoder.getLatLng(adr, (function(point){
					if (!point) {
						//if (console) 
						//	console.log('Nenalezeno: '+adr);
					} else {	
					   var blueIcon = new GIcon(G_DEFAULT_ICON);
                        blueIcon.iconSize = new GSize(20, 34);

                        blueIcon.image = ikona;
	               		markerOptions = { icon:blueIcon };

						this.points[this.k] = {point:point,title:popis};
						this.markers[this.k] = new GMarker(point, markerOptions);
						this.markers[this.k].popis = popis;
						GEvent.addListener(this.markers[this.k], "click", function() {
							map.openInfoWindowHtml(point,this.popis);
						});
						this.bounds.extend(point);
						this.map.addOverlay(this.markers[this.k]);
						this.map.setZoom(this.map.getBoundsZoomLevel(this.bounds));
						this.map.setCenter(this.bounds.getCenter(),8); 
					}
					
					var w = this.k * 100 / this.options.maps_items.length;
					$('preloader_mapa_progress').setStyle('width',w + '%');
					$('preloader_mapa_text').setHTML('Načteno ' + this.k + ' z ' + this.options.maps_items.length);
					
					if (this.k < this.options.maps_items.length-1) {
						this.k++;
						this.showAddress();
						
					} else {
						$('preloader_mapa').addClass('none')
					}
				}).bind(this));
			}
		}
	});




