/*
 * Copyright (c) ${year}, Inmite s.r.o. (www.inmite.eu).
 *
 * All rights reserved. This source code can be used only for purposes specified
 * by the given license contract signed by the rightful deputy of Inmite s.r.o.
 * This source code can be used only by the owner of the license.
 *
 * Any disputes arising in respect of this agreement (license) shall be brought
 * before the Municipal Court of Prague.
 */

var Supermap = {
    menusCount: 0,

    timeouts: [],// is given menu in timeout waiting to be hidden?
	items: null,
	menus:[-1,-1,-1,-1],
	speed: 200,
	fisheyeMenu: [
		{imgurl:'img/J-big.png', imgalt:'Praha', name:'Praha'},
		{imgurl:'img/J-big.png', imgalt:'Brno', name:'Brno'},
		{imgurl:'img/J-big.png', imgalt:'Ostrava', name:'Ostrava'},
		{imgurl:'img/J-big.png', imgalt:'Plze\u0148', name:'Plze\u0148'},
		{imgurl:'img/J-big.png', imgalt:'Olomouc', name:'Olomouc'}
	],
	weatherIcons: {
		'J': { name: 'Jasno' },
		'SJ': { name: 'Skoro jasno'},
		'P': {name: 'Polojasno'},
		'O': {name: 'Obla\u010dno'},
		'Z': {name: 'Zata\u017eeno'},
		'M': { name: 'Mlha'},
		'PDP': {name: 'Polojasno de\u0161\u0165ov\u00e1 p\u0159eh\u00e1\u0148ka'},
		'ODP': {name: 'Obla\u010dno de\u0161\u0165ov\u00e1 p\u0159eh\u00e1\u0148ka'},
		'ZDP': {name: 'Zata\u017eeno de\u0161\u0165ov\u00e1 p\u0159eh\u00e1\u0148ka'},
		'PD': {name: 'Polojasno d\u00e9\u0161\u0165'},
		'OD': {name: 'Obla\u010dno d\u00e9\u0161\u0165'},
		'ZD': {name: 'Zata\u017eeno d\u00e9\u0161\u0165'},
		'PB': {name: 'Polojasno bou\u0159ka'},
		'OB': {name: 'Obla\u010dno bou\u0159ka'},
		'ZB': {name: 'Zata\u017eeno bou\u0159ka'},
		'PDSP': {name :'Polojasno p\u0159eh\u00e1\u0148ka de\u0161t\u011b se sn\u011bhem'},
		'ODSP': {name: 'Obla\u010dno p\u0159eh\u00e1\u0148ka de\u0161t\u011b se sn\u011bhem'},
		'ZDSP': {name: 'Zata\u017eeno p\u0159eh\u00e1\u0148ka de\u0161t\u011b se sn\u011bhem'},
		'PDS': {name: 'Polojasno d\u00e9\u0161\u0165 se sn\u011bhem'},
		'ODS': {name: 'Obla\u010dno d\u00e9\u0161\u0165 se sn\u011bhem'},
		'ZDS': {name: 'Zata\u017eeno d\u00e9\u0161\u0165 se sn\u011bhem'},
		'PSP': {name: 'Polojasno sn\u011bhov\u00e1 p\u0159eh\u00e1\u0148ka'},
		'OSP': {name: 'Obla\u010dno sn\u011bhov\u00e1 p\u0159eh\u00e1\u0148ka'},
		'ZSP': {name: 'Zata\u017eeno sn\u011bhov\u00e1 p\u0159eh\u00e1\u0148ka'},
		'PS': {name: 'Polojasno sn\u011b\u017een\u00ed'},
		'OS': {name: 'Obla\u010dno sn\u011b\u017een\u00ed'},
		'ZS': { name: 'Zata\u017eeno sn\u011b\u017een\u00ed'}
	},	
	dummyMeteogramData: {
		location: 'Praha',
		startDate: "07:00 13.5.2010",
		endDate: "06:59 14.5.2010",
		hours:[
			{hrs:07, temp:16.3, rain: 2.7, iconId: 'J'},
			{hrs:08, temp:15.7, rain: 1.7, iconId: 'M'},
			{hrs:09, temp:18.1, rain: 0, iconId: 'ZS'},
			{hrs:10, temp:16.9, rain: 0, iconId:'O'},
			{hrs:11, temp:16.6, rain: 1.7, iconId:'OB'},
			{hrs:12, temp:15.8, rain: 5.7, iconId:'OD'},
			{hrs:13, temp:15.5, rain: 0, iconId:'ODP'},
			{hrs:14, temp:17.8, rain: 0, iconId:'ODS'},
			{hrs:15, temp:18.5, rain: 3.2, iconId:'ODSP'},
			{hrs:16, temp:19.8, rain: 2.4, iconId:'OS'},
			{hrs:17, temp:21.5, rain: 0.1, iconId:'OSP'},
			{hrs:18, temp:15.7, rain: 4.9, iconId:'P'},
			{hrs:19, temp:18.1, rain: 5, iconId:'PB'},
			{hrs:20, temp:16.9, rain: 5.1, iconId:'PD'},
			{hrs:21, temp:20, rain: 0, iconId:'PDP'},
			{hrs:22, temp:15, rain: 0, iconId:'PDS'},
			{hrs:23, temp:25.5, rain: 2.4, iconId:'PS'},
			{hrs:00, temp:23.8, rain: 0, iconId:'PSP'},
			{hrs:01, temp:18.5, rain: 0, iconId:'SJ'},
			{hrs:02, temp:19.8, rain: 0, iconId:'Z'},
			{hrs:03, temp:16.5, rain: 0, iconId:'ZB'},
			{hrs:04, temp:15.3, rain: 0, iconId:'ZD'},
			{hrs:05, temp:18.1, rain: 5.3, iconId:'ZDS'},
			{hrs:06, temp:16.9, rain: 4.1, iconId:'ZDSP'}
		]
	},

    init: function(startPath, params, json) {
		this.menuAnimationDist = 500;
		this.URLroot = $('script[src$="Supermap.js"]')[0].src.replace('js/Supermap.js','');
		this.items = json.items;
        this.menusCount = json.items.length;
		Supermap.previousSupemapItemId='sm-image-init';
		this.baseURL = "http://meteopress.cz/pictures2/";
		if(json.baseURL) {
			this.baseURL = json.baseURL;
		}
		this.smHistory = [{sm:'1', femg: '0'},{sm:'1', femg: '0'}];
        this.loadMenu(0, startPath, params);
    },

    loadMenu: function(depth, path, params) {
		var npath = path;
		var savepath = this._getSavePath(path, depth);
		npath = savepath.path;

//		$('#debug-log').append('path: ' + path + ' npath: ' + npath + ' depth: ' + depth + '<br/>');
		var pathlen = this._getPathLen(path);

		var items = this._getItems(npath);
		if(!items) {
			var sel = this._getItem(npath);
			for (k = depth+1; k <= 2; k ++) {
				$('#sm-select-'+k).hide();
			}
			this.show(npath, sel, params);
			return;
		}

//		$('#debug-log').append('depth: ' + depth + " depthOrig: " + depth2 + " path: " + path + "<br/>");
		$('#sm-menu-outer-'+depth).append('<div id="sm-menu-'+depth+'" class="sm-menu"></div>');
		
        var h = (items.length * 22) + 40;
		var outerHeight;
		var innerHeight;
		var sb = false;
		var t = 400-h;
		if(h > 400) {
			h = 360;
			t = 0;
			sb = true;
			outerHeight = (items.length*22);
			innerHeight = h;
			$('#sm-menu-'+depth).append('<div id="sm-menu-bghelp-'+depth+'" class="sm-menu-bghelp" style="top: 400px;height: '+(outerHeight-400)+'px;"></div>')
		}
		$('#sm-menu-'+depth).append('<ul style="z-index: 101;"></ul>');
		var width = 184;
        $('#sm-menu-'+depth).css('height', h+'px');
        $('#sm-menu-'+depth).css('top', t+'px');
		$('#sm-menu-outer-'+depth).css('height', h+'px');
		$('#sm-menu-outer-'+depth).css('top', t+'px');

		var bOmit = true;
		if(pathlen > depth) {
			var pathitems = path.split('-');
			selid = pathitems[depth];
			sel = items[selid];
			if(!sel) {
				bOmit = false;
			}
		}

        var sel = false;
		var selid = 0;
        for (k = 0; k < items.length; k++) {
			var itpath = npath;
			if(itpath.length>0)
				itpath = itpath.concat('-');
			itpath = itpath.concat(k);
            var onclick = '';
			onclick = ' onclick="Supermap.changeCurrentMapMenu(\''+itpath+'\', \''+depth+'\');" ';
            $('#sm-menu-'+depth+' UL').append('<li '+onclick+' id="sm-li-'+depth+'-'+k+'"><div>'+items[k].caption+'</div></li>');
			if(pathlen <= depth || !bOmit) {
				if (items[k].selected) {
					sel = items[k];
					selid = k;
				}
			}
        }
		if(sb) {

//			$('#sm-menu-'+depth+' UL').css('background-image', 'url('+this.URLroot+'img/sm_menu_bg_long.png)');
			$('#sm-menu-'+depth).jScrollPane({arrowSize: 10}, innerHeight, outerHeight, width);
		}

		if(pathlen > depth && bOmit) {
			var pathitems = path.split('-');
			selid = pathitems[depth];
			sel = items[selid];
		}

        // select 1st item if nothing marked as selected
        if ((pathlen <= depth || !bOmit) && !sel ) {
            sel = items[0];
			selid = 0;
        }

		var selectElem = $('#sm-select-'+depth);
        selectElem.css('height: ');
		selectElem.show();
		this.menus[depth] = selid;



       	var selectMenu = $('#sm-select-'+depth+' .sm-select-content-txt');
		this._restoreMenu( selectMenu );
		selectMenu.text( sel ? sel.caption : '');
		this._checkAndShortenMenu( selectMenu );

		selectElem.animate({left:'-='+Supermap.menuAnimationDist}, this.speed,'linear',function() {
		});				
		

		if(sb) { // long lists
			var posTo = selid*22;
//			var tmp = items.length*22 - 360;
//			$('#debug-log').append('posTo=' + posTo + ' tmp=' + tmp + '<br/>');
//			if(posTo > tmp)
//				posTo = tmp;
			$('#sm-menu-'+depth)[0].scrollTo(posTo, true);		
		}

		if(!bOmit) {
			path = this._constructPath(path, depth);
			if(depth>0)
				path = path.concat('-');
			path = path.concat(selid);
			params = {};
		}

        if (sel && (sel.items || pathlen>depth)) {
			if(pathlen <= depth) {
				npath = path;
				if(path.length>0)
					npath = npath.concat('-'+selid);
				else
					npath = npath.concat(selid);
				this.loadMenu(depth+1, npath, params);
			} else {
				this.loadMenu(depth+1, path, params);
			}
        } else {
			if(pathlen <= depth) {
				for (k = depth+1; k <= 2; k ++) {
					$('#sm-select-'+k).hide();
				}
				var npath = path.concat('-'+selid);
				this.show(npath, sel, params);
			} else {
				this.show(path, sel, params);
			}

        }
    },

	completelyHideMenu: function() {
		$('#sm-toolbar-txt').hide();
		var tmpDone = 0;
		for(var i=0; i<3; i++) {
			var actSelect = $('#sm-select-'+i);
			if(actSelect.css('display') == 'block') {
				actSelect.animate({ left: '+='+Supermap.menuAnimationDist}, this.speed, 'linear',function() {
						$(this).hide();
						var idx = $(this)[0].id.replace('sm-select-','');
						Supermap._clearElement( $('#sm-menu-outer-'+idx)[0] );
//						$('#debug-log').append('cleared: '+idx+'<br/>');
						tmpDone++;
						if(tmpDone >= 3) {
							Supermap.showStopPlayback();
						}
					});
			} else {
				tmpDone++;
				if(tmpDone >= 3) {
					Supermap.showStopPlayback();
				}
			}
		}
//		$('#sm-select-0').animate({ left: '+='+Supermap.menuAnimationDist}, this.speed, 'linear',function() {
//					$(this).hide();
//				});
//		$('#sm-select-1').animate({ left: '+='+Supermap.menuAnimationDist}, this.speed, 'linear',function() {
//					$(this).hide();
//				});
//		$('#sm-select-2').animate({ left: '+='+Supermap.menuAnimationDist}, this.speed, 'linear',function() {
//					$(this).hide();
//				});
//		$('#sm-select-0').hide();
//		$('#sm-select-1').hide();
//		$('#sm-select-2').hide();
	},

	completelyShowMenu: function()  {
		$('#sm-toolbar-txt').show();
		$('#sm-select-0').show();
		$('#sm-select-1').show();
		$('#sm-select-2').show();
	},

	showStopPlayback: function() {
		$('#sm-stop-playback').show();
//		$('#sm-stop-playback').fadeIn("slow");
		$('#sm-stop-playback').animate({left: '-='+Supermap.menuAnimationDist}, this.speed, 'linear');
	},

	hideStopPlayback: function() {
		$('#sm-stop-playback').animate({left: '+='+Supermap.menuAnimationDist}, this.speed, 'linear', function() {
			$(this).hide();
		});
	},

	stopPlayback: function() {
		this.hideStopPlayback();
		this.completelyShowMenu();
		this.goBackHistory();
	},

	goBackHistory: function() {
		Supermap.loadMenu(0, Supermap.smHistory[1].sm, Supermap.smHistory[1]);
//		Supermap.changeCurrentMap(Supermap.smHistory[1].sm);
	},

	updateSmHistory: function(sm, femg) {
		Supermap.smHistory[1] = Supermap.smHistory[0];
		Supermap.smHistory[0] = {sm:sm, femg: femg};
//		for(var i=0; i<2; i++)
//			$('#debug-log').append(i+':sm=' + Supermap.smHistory[i].sm + ";femg=" + Supermap.smHistory[i].femg + '<br/>');
	},

    toggleMenu: function(id) {
        if ($('#sm-menu-outer-'+id).css('display') != 'block') {
            this.menuShow(id);
            for (k = 1; k <= this.menusCount; k ++) {
                if (k != id) {
                    this.menuHide(k);
                }
            }
        }
    },

    menuShow: function(id) {
        $('#sm-menu-outer-'+id).fadeIn("fast");
        $('#sm-select-btn-'+id).addClass('up');

        $('#sm-menu-outer-'+id).mouseleave(function() {
            clearTimeout(Supermap.timeouts[id]);
            Supermap.timeouts[id] = setTimeout("Supermap.menuHide("+id+");", 200);
        });
        $('#sm-menu-outer-'+id).mouseenter(function() {
            clearTimeout(Supermap.timeouts[id]);
        });
    },

    menuHide: function(id) {
        $('#sm-menu-outer-'+id).fadeOut("fast");
        $('#sm-select-btn-'+id).removeClass('up');
    },

    show: function(path, itemOld, params) {
		this.currentPath = path;

		if(!itemOld)
			return;

		var par = {sm:path};
//		if(params && params['sm']) {
//			par = params;
//		}

		if(params) {
//			$('#debug-log').append('params: sm=' + params['sm'] + ' femg=' + params['femg'] + '<br/>');
		}


		
		var item = this._getItem(path);
		var type = item.type;
		var url = item.url;
		var id = 'it'+path;
        if ($('#'+id)) {
            $('#'+id).remove();
        }

		this.flvPlayerId = null;
		this.youtubePlayerId = null;


		if(params && params['femg'] && params['femg']!=0) {
			$('#supermap').append('<div id="'+id+'" class="sm-image" style="left: 675px; "></div>');
			this._loadMeteogramInner(id, path);
			return;
		}

		var saveCookies = true;
		
		if(type == 'image') {
        	$('#supermap').append('<div id="'+id+'" class="sm-image" style="left: 675px; "></div>');
			var absURL = url;
			if(absURL.indexOf("http://")==-1) {
				var imageurl = this._getHereditaryParameter(path, "imageurl");
				if(!imageurl) {
					imageurl = this.baseURL;
				}
				absURL = imageurl + url;
			}
        	$('#'+id).css('background-image', 'url('+absURL+')');
		} else if(type == 'youtube') {
			saveCookies = false;
			$('#supermap').append('<div id="'+id+'" class="sm-image" style="left: 675px; "></div>');
//			$('#'+id).append('<div id="sm-youtube-'+id+'"><object width="670" height="360"><param name="wmode" value="transparent" /><param name="movie" value="'+url+'"/><param name="allowFullScreen" value="false"/><param name="allowscriptaccess" value="always"/><embed src="'+url+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="false" width="670" height="360" wmode="transparent"></embed></object></div>');

			$('#'+id).append('<div id="inner-youtube-'+id+'"></div>');
			this.youtubePlayerId = 'youtube-player-'+id;
			var params = { allowScriptAccess: "always", bgcolor: "#cccccc", wmode:'transparent'};
			var atts = { id: this.youtubePlayerId };
			var flashvars = { };
			swfobject.embedSWF(url, "inner-youtube-"+id,
					"670", "360", "9", null, flashvars, params, atts);


		} else if(type == 'fisheye') {
			this.addFisheyeMenuOld(id, this.fisheyeMenu);
		} else if(type == 'meteogram') {
			$('#supermap').append('<div id="'+id+'" class="sm-meteogram" style="left: 675px; "></div>');
			this.createMeteogram(id, this.dummyMeteogramData);
		} else if(type == 'flv-transparent') {
			saveCookies = false;
			var absURL = url;
			if(absURL.indexOf("http://")==-1)
				absURL = this.URLroot + url;
		    $('#supermap').append('<div id="'+id+'" class="sm-image" style="left: 675px; z-index: 51;"></div>');
			if(item.bgurl) {
				var bgURL = item.bgurl;
				if(bgURL.indexOf("http://")==-1)
					bgURL = this.URLroot + bgURL;
				$('#'+id).css('background-image', 'url(' + bgURL + ')');
			}

			$('#'+id).append('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="670" height="360" id="FLVPlayer" >');
			var ido = $('#'+id+' object');
  			ido.append('<param name="movie" value="'+this.URLroot+'img/video/FLVPlayer_Progressive.swf" />');
  			ido.append('<param name="quality" value="high" />');
			ido.append('<param name="wmode" value="transparent" />');
  			ido.append('<param name="scale" value="noscale" />');
  			ido.append('<param name="salign" value="lt" />');
  			ido.append('<param name="FlashVars" value="&amp;MM_ComponentVersion=1&amp;skinName='+this.URLroot+'img/video/Clear_Skin_1&amp;streamName='+absURL+'&amp;autoPlay=false&amp;autoRewind=false" />');
  			ido.append('<param name="swfversion" value="8,0,0,0" />');
  			ido.append('<param name="expressinstall" value="'+this.URLroot+'img/video/expressInstall.swf" />');
			if(!$.browser.msie) {
				ido.append('<object type="application/x-shockwave-flash" data="'+this.URLroot+'img/video/FLVPlayer_Progressive.swf" width="670" height="360">');
				$('#'+id+' object object').append('<param name="quality" value="high" />');
				$('#'+id+' object object').append('<param name="wmode" value="transparent" />');
				$('#'+id+' object object').append('<param name="scale" value="noscale" />');
				$('#'+id+' object object').append('<param name="salign" value="lt" />');
				$('#'+id+' object object').append('<param name="flashvars" value="&amp;MM_ComponentVersion=1&amp;skinName='+this.URLroot+'img/video/Clear_Skin_1&amp;streamName='+absURL+'&amp;autoPlay=false&amp;autoRewind=false" />');
				$('#'+id+' object object').append('<param name="swfversion" value="8,0,0,0" />');
				$('#'+id+' object object').append('<param name="expressinstall" value="'+this.URLroot+'img/video/expressInstall.swf" />');				
				$('#'+id+' object object').append('<div><h4>Content on this page requires a newer version of Adobe Flash Player.</h4><p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p></div>');
			} else {
				$('#'+id+' object').append('<div><h4>Content on this page requires a newer version of Adobe Flash Player.</h4><p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p></div>');
			}

		} else if(type == 'mov') {
			saveCookies = false;
			$('#supermap').append('<div id="'+id+'" class="sm-image" style="left: 675px; z-index: 51;"></div>');
			
			$('#'+id).append('<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="360" width="670">');
			var ido = $('#'+id+' object');
  			ido.append('<param name="src" value="'+url+'" />');
  			ido.append('<param name="autoplay" value="false" />');
			ido.append('<param name="type" value="video/quicktime" width="670" height="360" />');
  			ido.append('<embed src="'+url+'" height="360" width="670" autoplay="false" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/">');

			this.completelyHideMenu();
		} else if(type == 'stream') {
			saveCookies = false;
			$('#supermap').append('<div id="'+id+'" class="sm-image" style="left: 675px; z-index: 51;"></div>');//			

			$('#'+id).append('<object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" height="360" width="670" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject">');
			var ido = $('#'+id+' object');
  			ido.append('<param name="fileName" value="'+url+'" />');
  			ido.append('<param name="animationatStart" value="true" />');
			ido.append('<param name="transparentatStart" value="true" />');
			ido.append('<param name="autoStart" value="true">');
			ido.append('<param name="showControls" value="true">');
			ido.append('<param name="loop" value="true">');
			ido.append('<param name="type" value="application/x-oleobject" width="670" height="360" />');
  			ido.append('<embed src="'+url+'" height="360" width="670" autostart="true" type="application/x-mplayer2" pluginspage="http://microsoft.com/windows/mediaplayer/en/download/"  displaysize="4" autosize="-1" bgcolor="darkblue" showcontrols="true" showtracker="-1" showdisplay="0" showstatusbar="-1" videoborder3d="-1"  designtimesp="5311" loop="true" >');

			this.completelyHideMenu();
		} else if(type == 'flv-old') {
			saveCookies = false;
			var absURL = url;
			if(absURL.indexOf("http://")==-1)
				absURL = this.URLroot + url;
		    $('#supermap').append('<div id="'+id+'" class="sm-image" style="left: 675px; z-index: 51;"></div>');

			$('#'+id).append('<div id="inner-flv-'+id+'"></div>');
			this.swfPlayerId = 'swf-player-'+id;
			var params = { allowScriptAccess: "always", bgcolor: "#cccccc", wmode: "transparent" };
			var atts = { id: this.swfPlayerId };
			var flashvars = {file:absURL};
			swfobject.embedSWF(this.URLroot + 'img/video/player.swf', 'inner-flv-'+id, "670", "360", "9", null, flashvars, params, atts);
		} else if(type == 'flv') {
			saveCookies = false;
			var absURL = url;
			if(absURL.indexOf("http://")==-1)
				absURL = this.URLroot + url;
		    $('#supermap').append('<div id="'+id+'" class="sm-image" style="left: 675px; z-index: 51;"></div>');

			$('#'+id).append('<div id="inner-flv-'+id+'"></div>');
			$('#inner-flv-'+id).append('<a href="'+absURL+'" style="position:absolute;top:0;left:0;display:block;width:670px;height:360px;z-index:51;" id="player-'+id+'">');
			flowplayer("player-"+id,
					{
						src: this.URLroot + 'img/video/flowplayer-3.2.2.swf',
						wmode: 'transparent'
					},
					{
			  			// player config
						clip: {
							// common clip properties
							scaling: "fit"
						}
					}
			);

		}


		var fisheyeType = this._getHereditaryParameter(path, 'fisheyetype');
		if(fisheyeType) {
			this.addFisheyeMenu(id,path,fisheyeType);
		}

		if(type == 'flv' || type == 'stream' || type=='mov') {
			$('#'+id).css('left', '0');
			$.setUrlVar(par);
			// set cookie 14 days to expire
//			$.setCookieVars(par, 14);
			if(Supermap.previousSupemapItemId)
				$('#'+Supermap.previousSupemapItemId).remove();
			Supermap.previousSupemapItemId=id;
			Supermap.updateSmHistory(par.sm, par.femg);
		} else if(type == 'youtube' || type == 'flv-transparent') {
			var timeout = 1000;
			if(type=='flv')
				timeout = 500;
			setTimeout(function() {
				$('#'+id).animate({ left: 0 }, {
					complete: function() {
						$.setUrlVar(par);
//						// set cookie 14 days to expire
//						$.setCookieVars(par, 14);
						if(Supermap.previousSupemapItemId)
							$('#'+Supermap.previousSupemapItemId).remove();
						Supermap.previousSupemapItemId=id;
						Supermap.updateSmHistory(par.sm, par.femg);
					}
				});
			}, timeout);
		} else {
			$('#'+id).animate({ left: 0 }, {
				complete: function() {
					$.setUrlVar(par);
					if(saveCookies) {
						// set cookie 14 days to expire
						$.setCookieVars(par, 14);
					}
					if(Supermap.previousSupemapItemId)
						$('#'+Supermap.previousSupemapItemId).remove();
					Supermap.previousSupemapItemId=id;
					Supermap.updateSmHistory(par.sm, par.femg);
				}
			});
		}

    },

	setSupermapTo: function(path) {
		if($('#supermap').length == 0)
			return;
		$('body').scrollTo($('#supermap')[0], 800, function() {
			Supermap.changeCurrentMap(path);
		});				
	},

	changeCurrentMapMenu: function(path, id) {
		this.menuHide(id);
		this.changeCurrentMap(path);
	},

	changeCurrentMap: function(path) {

//		if(this.flvPlayerId) {
//			var player = document.getElementById(this.flvPlayerId);
//			player.stop();
//		}
//		var player = null;
//		if(this.youtubePlayerId) {
//			player = swfobject.getObjectById(this.youtubePlayerId);
//			player.stopVideo();
//			this.youtubePlayerId = null;
//		}
//		var items = this._getItems(depth+1, path);

		var refresh = this._getHereditaryParameter(path, 'refresh');
		if(refresh) {
			var param = {sm:path};
			$.setUrlVar(param);
			$.setCookieVars(param);
			this.refreshSite();
			return;
		}
//		var depth = this._getDepth(path)-1;
		var depth = this._getChangeDepth(path);
		var npath = this._getSavePath(path, depth).path;
		var items = this._getItems(npath);
		var isTheSame = this._isTheSame(depth+1, path);
		if(items) {
			if(!isTheSame || this.menus[3]>0)
				this._clearMenuElement(depth, path, true);
		}
		else {
			this._clearMenuElement(depth, path);
		}
	},

	refreshSite: function() {
		window.location.reload();  	
	},

	addFisheyeMenu: function(id, path, fisheyeType) {
		if(!fisheyeType)
			return;
		var feItems = [];

		var items = this._getParentItems(path);
		var item = this._getItem(path);
		var mgenabled = this._getHereditaryParameter(path,'meteogramenabled');
		var predefImg = this.URLroot + 'img/fisheye/vil.png';//J-big.png';
		var pathitems = path.split('-');
		var idx = pathitems[pathitems.length-1];
		var npath = this._constructPath(path, pathitems.length-1);

		// first element of fish eye - meteogram/go back
		if(fisheyeType != 'fe-meteogram') {
			if(mgenabled && mgenabled != 'false') {
				feItems.push({
					imgurl:this.URLroot + 'img/fisheye/gra.png',
					name: item.caption + ' - meteogram',
					onclick: 'Supermap.loadMeteogram(\''+id+'\', \''+path+'\');',
					path: path
				})
			}
		} else {
			// current city
			var itpath = npath.concat('-'+idx);
			feItems.push({
				imgurl: predefImg,
				name: item.caption + ' - tabulka',
				onclick: 'Supermap.changeCurrentMap(\''+itpath+'\');',
					path: itpath
			});
		}

		// other elements - according to configuration json
		fisheyeType = this._getHereditaryParameter(path, 'fisheyetype');
		if(fisheyeType == 'fe-mg-basic') {
			for(var i=0; i<items.length; i++) {
				if(i==idx)
					continue;
				var itpath = npath.concat('-'+i);
				feItems.push({
					imgurl: predefImg,
					name: items[i].caption,
					onclick: 'Supermap.changeCurrentMap(\''+itpath+'\');',
					path: itpath
				})
			}
		} if(fisheyeType == 'fe-mg-specific') {
			var fei = this._getHereditaryParameter(path, 'feitems');
			for(var i=0; i<fei.length; i++) {
				var ico = predefImg;
				if(fei[i].icon) {
					var icon = fei[i].icon;
					if(icon.indexOf('http://')==0)
						ico = icon;
					else
						ico = this.URLroot + icon;
				}
				var onclick = 'Supermap.changeCurrentMap(\''+fei[i].path+'\');';
				var url = '';
				if(fei[i].url) {
					onclick = '';
					url = fei[i].url;//'window.location.replace(\'' + feitems[i].url + '\');';
				}
				feItems.push({
					imgurl: ico,
					name: fei[i].caption,
					onclick: onclick,
					path: fei[i].path,
					url: url
				})
			}
		}

		this._appendFisheyeMenu(id, feItems);
	},

	loadMeteogram: function(id, path) {
		var refresh = this._getHereditaryParameter(path, 'refresh');
		if(refresh) {
			var param = {sm:path,femg:1};
			$.setUrlVar(param);
			$.setCookieVars(param);
			this.refreshSite();
			return;
		}
		this._loadMeteogramInner(id, path);
	},

	_loadMeteogramInner: function(id, path) {

		var item = this._getItem(path);
		var url = item.url.substring(0, item.url.length-7);
		var absURL = url;
		if(absURL.indexOf("http://")==-1) {
			var imageurl = this._getHereditaryParameter(path, "imageurl");
			if(!imageurl) {
				imageurl = this.baseURL;
			}
			absURL = imageurl + url;
		}
		absURL = absURL.concat('meteogram.js');
		$('#'+id).append('<script type="text/javascript" src="'+absURL+'"></script>');
		// ugly!!!
		this.meteogramId = id;
		this.meteogramPath = path;
	},

//	_getItems: function(depth, path) {
//		var pathitems = path.split('-');
//		var items = this.items;
//		for(var i=0; i<depth; i++)
//			if(pathitems[i])
//				items = items[pathitems[i]].items;
//		return items;
//	},

	_constructPathStub: function(path, depth) {
		if(depth==0)
			return '';
		var pathitems = path.split('-');
		var npath = pathitems[0];
		for(var i=1; i<depth; i++)
			npath = npath.concat('-'+pathitems[i]);
		return npath;
	},


	_handleMeteogramCallback: function(data) {
		var id = this.meteogramId + '-mg';
		var path = this.meteogramPath;
		var par = {'sm': path, 'femg': '1'};
		if ($('#'+id)) {
            $('#'+id).remove();
        }
		this.menus[3] = 1;
		$('#supermap').append('<div id="'+id+'" class="sm-meteogram" style="left: 675px; "></div>');
		this.createMeteogram(id, data);

		this.addFisheyeMenu(id,path,'fe-meteogram');

		$('#'+id).animate({ left: 0 }, {
			complete: function() {
				$.setUrlVar(par);
				$.setCookieVars(par, 14);
				if(Supermap.previousSupemapItemId)
					$('#'+Supermap.previousSupemapItemId).remove();
				Supermap.previousSupemapItemId=id;
				Supermap.updateSmHistory(par.sm, par.femg);
			}
		});
	},


	_getHereditaryParameter: function(path, parameterName) {
		var pathitems = path.split('-');
		var items = this.items;
		var paramVal = null;
		for(var i=0; i<pathitems.length-1; i++)
			if(pathitems[i]) {
				var tmpitem = items[pathitems[i]];
				if(tmpitem[parameterName] != undefined)
					paramVal = tmpitem[parameterName];
				items = tmpitem.items;
			}
		var tmpitem = items[pathitems[pathitems.length-1]];
		if(!tmpitem)
			return paramVal;
		if(tmpitem[parameterName] != undefined)
			paramVal = tmpitem[parameterName];
		return paramVal;
	},

	_getPathLen: function(path) {
		var pathitems = path.split('-');
		if(pathitems.length==1 && !pathitems[0])
			return 0;
		return pathitems.length;
	},

	_getSavePath: function(path, initDepth) {
		var pathitems = path.split('-');
		var items = this.items;
		var npath = '';
		if(initDepth == 0)
			return {path:'', safe: false};
		if(pathitems.length>0 && initDepth>0) {
			var it = items[pathitems[0]];
			if(!it) {
				return {path:'', safe: false};
			}
			else {
				npath = pathitems[0];
				items = it.items;
			}
		}
		for(var i=1; i<pathitems.length && i<initDepth; i++) {
			if(pathitems[i]) {
				var it = items[pathitems[i]];
				if(!it)
					return {path:npath, safe: false};
				else {
					npath = npath.concat('-'+pathitems[i]);
				}
				items = it.items;
			}
		}
//		if(pathitems.length < initDepth) {
//			return {path:npath, safe: false};
//		}
		return {path: npath, safe: true};
	},

	_constructPath: function(path, len) {
		var pathitems = path.split('-');
		var npath = '';
		if(pathitems.length>0 && len>0)
			npath = npath.concat(pathitems[0]);
		for(var i=1; i<len; i++) {
			npath = npath.concat('-'+pathitems[i]);
		}
		return npath;
	},

	_getDepth: function(path) {
		if(!path)
			return 0;
		return path.split('-').length;
	},

	_getChangeDepth: function(path) {
		var pi = path.split('-');
		var cpi = this.currentPath.split('-');
		var len = pi.length > cpi.length ? cpi.length : pi.length;
		for(var i=0; i<len; i++) {
			if(pi[i] != cpi[i])
				return i;
		}
		return len-1;
	},

	_getItem: function(path) {
		var pathitems = path.split('-');
		var items = this.items;
		for(var i=0; i<pathitems.length-1; i++)
			if(pathitems[i])
				items = items[pathitems[i]].items;
		return items[pathitems[pathitems.length-1]];
	},

	_getItems: function(path) {
		var pathitems = path.split('-');
		var items = this.items;
		for(var i=0; i<pathitems.length; i++)
			if(pathitems[i]) {
				if(!items)
					return undefined;
				var it = items[pathitems[i]];
				if(!it)
					return undefined;
				items = it.items;
			}
		return items;
	},

	_getParentItems: function(path) {
		var pathitems = path.split('-');
		var items = this.items;
		for(var i=0; i<pathitems.length-1; i++)
			if(pathitems[i])
				items = items[pathitems[i]].items;
		return items;
	},

	_getCurrItem: function(depth, path) {
		var pathitems = path.split('-');
		var items = this.items;
		for(var i=0; i<depth; i++)
			if(pathitems[i])
				items = items[pathitems[i]].items;
		return items[pathitems[depth]];
	},

	_isTheSame: function(depth, path) {
		var pathitems = path.split('-');
		for(var i=0; i<depth; i++) {
			if(this.menus[i] != pathitems[i])
				return false;
		}
		return true;
	},

	_restoreMenu: function(jqelem) {
		var classes = ['sm-content-toolong1a', 'sm-content-toolong1b', 'sm-content-toolong2'];
		for(var i=0; i<classes.length; i++) {
			if(jqelem.hasClass( classes[i] ))
				jqelem.removeClass( classes[i] );
		}		
	},

	_checkAndShortenMenu: function(jqelem) {
		// too long captions - smaller font
		if(jqelem.height() > 15) {
			jqelem.addClass('sm-content-toolong1a');
			jqelem.addClass('sm-content-toolong1b');
		}
		// still too long - two rows
		if(jqelem.height() > 15) {
			jqelem.removeClass('sm-content-toolong1b');
			jqelem.addClass('sm-content-toolong2');
		}
	},

	_clearMenuElement: function(depth, path, add) {
		var me = this;
		var pathitems = path.split('-');
//		var itemsO = this._getItems(depth, path);
		var npath = this._getSavePath(path, depth).path;
//		var items = this._getParentItems(npath);
		var items = this._getItems(npath);
		var idx = pathitems[depth];
		var item = items[idx];

		var menuSelect = $('#sm-select-'+depth+' .sm-select-content-txt');
		this._restoreMenu( menuSelect );
		menuSelect.text(item.caption);
		this._checkAndShortenMenu( menuSelect );

//		if(!item.items) {
//			this.show(path, item);
//			return;
//		}
		this.menus[3] = -1;
		this.menus[depth] = idx;

		var done = depth;
		for (k = depth+1; k <= 2; k ++) {
			var elem = $('#sm-select-'+k);
			if(this.menus[k]>=0) {
				elem.animate({ left: '+='+Supermap.menuAnimationDist}, this.speed, 'linear',function() {
					$(this).hide();
					var idx = $(this)[0].id.replace('sm-select-','');
					done++;
					if(done>=2 && add) {
						me.loadMenu(depth+1, path);
					}
				});
			} else {
				done++;
				if(done>=2 && add) {
					this.loadMenu(depth+1, path);
				}
			}
			this.menus[k] = -1;
			this._clearElement( $('#sm-menu-outer-'+k)[0] );
		}
		// no menu change occured
		if(depth >= 2) {
			this.show(path, item);
		}

	},

	_clearElement: function(el) {
		if (el) {
			while(el.childNodes.length > 0) {
				el.removeChild(el.childNodes[0]);
			}
		}
	},

	addFisheyeMenuOld: function(id, itemsList) {
		$('#supermap').append('<div id="'+id+'" class="sm-image" style="left: 675px; "></div>');
		$('#'+id).append('<div id="sm-fisheye" class="sm-fisheye"></div>');
		$('#sm-fisheye').append('<ul id="fisheye_menu"></ul>');
		for(var i=0; i<itemsList.length; i++) {
			$('#fisheye_menu').append('<li class="fisheye_menu"><a href="#1"><img src="'+this.URLroot+itemsList[i].imgurl+'" alt="'+itemsList[i].imgalt+'" /><span>'+itemsList[i].name+'</span></a></li>');
		}
		fisheyemenu.init('fisheye_menu');
	},

	_appendFisheyeMenu: function(id, feItems) {
		$('#'+id).append('<div id="sm-fisheye-'+id+'" class="sm-fisheye"></div>');
		$('#sm-fisheye-'+id).append('<ul id="fisheye_menu-'+id+'"></ul>');
		for(var i=0; i<feItems.length; i++) {
			var params = {sm:feItems[i].path};
			if(feItems[i].name == 'meteogram') {
				params['femg'] = '1';
			}
			var localUrl = '#' + $.getLocalUrlParamsForMany(params);
			if(feItems[i].url && feItems[i].url != '') {
				localUrl = feItems[i].url;
			}
			$('#fisheye_menu-'+id).append('<li class="fisheye_menu"><a href="'+localUrl+'" onclick="'+feItems[i].onclick+'"><img src="'+feItems[i].imgurl+'" alt="'+feItems[i].name+'" /><span>'+feItems[i].name+'</span></a></li>');
		}
		fisheyemenu.init('fisheye_menu-'+id);
	},

	/** returns list of items - every item must have: imgurl, name, onclick, [imgalt] 
	 *
	 * @param item from configuration json
	 */
	getFisheyeItemsList: function(item) {
		// TODO
	},

	createMeteogram: function(parentDivId, data) {
		var id = parentDivId + '-sm-meteogram';
		$('#'+parentDivId).append('<div id="'+id+'" class="sm-meteogram" ></div>');
		var minTemp = 200;
		var maxTemp = -100;
		var maxRain = 0;
		for(var i=0; i<data.hours.length; i++) {
			var curr = data.hours[i];
			// solving IE problems
			if(!curr)
				continue;			
			if(curr.temp < minTemp) {
				minTemp = curr.temp;
			}
			if(curr.temp > maxTemp) {
				maxTemp = curr.temp;
			}
			if(curr.rain > maxRain) {
				maxRain = curr.rain;
			}
		}

		$('#'+id).append('<div id="sm-mg-headline-'+id+'" class="sm-mg-headline"><span>'+data.location+'</span></div>');		

		// 20�C
		var times = Math.ceil((maxTemp-minTemp) / 20);
		var below = (times*20 - (maxTemp-minTemp))/2;
		var bottom = minTemp-below;
		var granularity = 5;
		bottom = Math.floor(bottom/granularity)*granularity;
		if(minTemp - bottom > 2*below) {
			times+=1;
			below = (times*20 - (maxTemp-minTemp))/2;
			bottom = minTemp-below;
			bottom = Math.floor(bottom/granularity)*granularity;
		}
		var above = 2*below - (minTemp-bottom);
		above += granularity/10;
//		above = Math.round(above * 1000)/1000;
		var baseTop = 330;
		var baseLeft = 127;
		$('#'+id).append('<div id="sm-mg-cont-'+id+'" class="meteogram-container" ></div>'); //onmouseover="Supermap._mgContMouseOut();"

		// horizontal lines and labels
		var steps = Math.floor((maxTemp+above-Math.ceil(bottom/granularity)*granularity)/granularity);
		var rainStep = Math.ceil(maxRain/granularity)*granularity/steps;
		for(var i=Math.ceil(bottom/granularity)*granularity,j=0; i<=maxTemp+above; i+=granularity,j++) {
			var lTop = baseTop - 3*(i-bottom)/0.25/times;
			$('#'+id).append('<div id="sm-mg-bg-line-hor-'+i+'" class="bg-line-hor" style="top: '+lTop+'px;"></div>');
			var labTop = lTop-5;
			$('#'+id).append('<div id="sm-mg-label-temp-'+i+'" class="mg-temp-label" style="top:'+labTop+'px;"><span>'+i+'</span></div>');
			var raini = Math.round(j*rainStep*10)/10;
			var tmpr = Math.round(j*rainStep*100);
			if(tmpr%10 == 5)
				raini = tmpr/100;
			$('#'+id).append('<div id="sm-mg-label-rain-'+i+'" class="mg-rain-label" style="top:'+labTop+'px;"><span>'+raini+'</span></div>');
		}

		$('#'+id).append('<div id="mg-bubble-'+id+'" class="mg-bubble" style="display:none;"></div>');
		$('#mg-bubble-'+id).append('<div id="mg-bubble-content-'+id+'" class="mg-bubble-content"></div>');
		$('#mg-bubble-content-'+id).append('<ul id="mg-bubble-stats-'+id+'" class="mg-bubble-stats"></ul>');

		var dlen = 0;
		// graphs
		for(var i=0; i<data.hours.length; i++) {
			var curr = data.hours[i];
			// solving 	IE problems
			if(!curr)
				continue;
			dlen ++;
			var left = baseLeft+i*20;
			var top = Math.round(baseTop - 3*(curr.temp-bottom)/0.25/times)-4;
			$('#'+id).append('<div id="sm-mg-temp-'+i+'" class="meteogram-temp" style="left:'+left+'px; top:'+top+'px;"></div>')
			if(i>0) {
				var prev = data.hours[i-1];
				var prevLeft = left-20;
				var prevTop = Math.round(baseTop - 3*(prev.temp-bottom)/0.25/times)-4;
				var lineLeft = prevLeft + 6;
				var lineTop = top<prevTop ? top : prevTop;
				var lineType = 3*Math.round((curr.temp-prev.temp)/0.25/times);
				var lineTypeStr = lineType >= 0 ? '+'+lineType : lineType;
				var height = Math.abs(lineType)+3;//Math.ceil(Math.abs(top-prevTop));				
				lineTop += 3;
				$('#'+id).append('<div id="sm-mg-line-'+(i-1)+'-'+i+'" class="meteogram-line" style="left:'+lineLeft+'px; top:'+lineTop+'px; height: '+height+'px; background-image: url(\''+ this.URLroot +'img/mg/lines/line'+lineTypeStr+'.png\');"></div>');
			}
			var betLeft = left-6;
			$('#'+id).append('<div id="sm-mg-bg-line-vert-'+i+'" class="bg-line-vert" style="left: '+betLeft+'px;"></div>');
			var boxLeft = left-5;

//			var date = data.startDate.replace(' [0-9]{1,2}.[0-9]{1,2}.[0-9]{2,4}','');

			var date = data.startDate.replace(/[0-9]{1,2}:[0-9]{1,2} /,'');
			var hour = new Number( data.startDate.replace(/:[0-9]{1,2} [0-9]{1,2}.[0-9]{1,2}.[0-9]{2,4}/,'') );
	//			hour += new Number(curr.hrs);
	//			if(hour >= 24) {
	//				hour %= 24;
	//				date = data.endDate.replace(/[0-9]{1,2}:[0-9]{1,2} /,'');
	//			}
			var min = new Number( data.startDate.replace(/ [0-9]{1,2}.[0-9]{1,2}.[0-9]{2,4}/,'').replace(/[0-9]{1,2}:/,'') );

			if(hour > new Number(curr.hrs)) {
				date = data.endDate.replace(/[0-9]{1,2}:[0-9]{1,2} /,'');
			}
			var hour = curr.hrs;
			var time = (hour<10? '0'+hour : hour) + ':' + (min<10? '0'+min : min);

			var state = this._getMeteogramIconName(curr.iconId);
			var mouseover = 'Supermap._meteogramMouseOver('+baseTop+', '+i+', \''+id+'\', '+left+', '+curr.temp+', '+curr.rain+', \''+date+'\', \''+time+'\', \''+state+'\');';
			var mouseout = 'Supermap._meteogramMouseOut('+i+', \''+id+'\');';
			$('#'+id).append('<div id="sm-mg-bg-box-vert-'+i+'-'+id+'" class="mg-bg-box-vert" style="left: '+boxLeft+'px;" ></div>');
			$('#'+id).append('<div id="sm-mg-opaq-box-vert-'+i+'-'+id+'" class="mg-opaq-box-vert" style="left: '+boxLeft+'px;" onmouseover="'+mouseover+'" onmouseout="'+mouseout+'" ></div>');

			var rainHeight = Math.round(granularity*(12/times)*curr.rain/rainStep);
			var rainLeft = left-1;
			var rainTop = baseTop-rainHeight;
			$('#'+id).append('<div id="sm-mg-rain-box-'+i+'" class="mg-rain-column" style="left:'+rainLeft+'px; top:'+rainTop+'px; height:'+rainHeight+'px;"></div>');

			// icon
			var iconLeft = left-5;
			$('#'+id).append('<div id="sm-mg-icon-'+i+'" class="mg-icon" style="left:'+iconLeft+'px;"><img src="'+this._getMeteogramIconURL(curr.iconId)+'" class="mg-img-ico" alt="'+this._getMeteogramIconName(curr.iconId)+'"></img></div>');
		}		
		var betLeft = baseLeft+dlen*20-6;
		$('#'+id).append('<div id="sm-mg-bg-line-vert-'+dlen+'" class="bg-line-vert" style="left: '+betLeft+'px;"></div>');

		// temp/rain labels
		$('#'+id).append('<div id="sm-mg-lbl-temp"><span class="lbl-text">Teplota [\u00B0C]</span></div>');
		$('#'+id).append('<div id="sm-mg-lbl-rain"><span class="lbl-text">Sr\u00E1\u017Eky [mm]</span></div>');

		// time from-to label
		var hour = new Number( data.startDate.replace(/:[0-9]{1,2} [0-9]{1,2}.[0-9]{1,2}.[0-9]{2,4}/,'') );
		var date0 = data.startDate.replace(/[0-9]{1,2}:[0-9]{1,2} /,'');
		var date23 = date0;
		var hour0 = data.hours[0].hrs;
		var time0 = (hour0<10? '0'+hour0 : hour0) + ':' + (min<10? '0'+min : min);
		var hour23 = data.hours[23].hrs;
		var time23 = (hour23<10? '0'+hour23 : hour23) + ':' + (min<10? '0'+min : min);
		if(hour > new Number(data.hours[0].hrs)) {
			date0 = data.endDate.replace(/[0-9]{1,2}:[0-9]{1,2} /,'');
		}
		if(hour > new Number(data.hours[23].hrs)) {
			date23 = data.endDate.replace(/[0-9]{1,2}:[0-9]{1,2} /,'');
		}
		$('#'+id).append('<div id="sm-mg-lbl-time-from"><span class="lbl-time">'+time0+' '+date0+'</span></div>');
		$('#'+id).append('<div id="sm-mg-lbl-time-to"><span class="lbl-time">'+time23+' '+date23+'</span></div>');
	},

	_getMeteogramIconURL: function(iconId) {
		var iconData = this.weatherIcons[iconId];
		if(!iconData)
			return;
		return this.URLroot +'img/mg/weather-icons/'+iconId+'.png';
	},

	_getMeteogramIconName: function(iconId) {
		var iconData = this.weatherIcons[iconId];
		if(!iconData)
			return;
		return iconData.name;
	},

	_meteogramMouseOver: function(baseTop, idx, id, left, temp, rain, date, time, state) {
		var top = baseTop - 136;
		left -= 40;
		$('#mg-bubble-'+id).attr('style','left:'+left+'px; top:'+top+'px;');
		this._clearElement($('#mg-bubble-stats-'+id)[0]);
		$('#mg-bubble-stats'+'-'+id).append(this._getBubbleItem('Datum',date));
		$('#mg-bubble-stats'+'-'+id).append(this._getBubbleItem('\u010cas',time));
		$('#mg-bubble-stats'+'-'+id).append(this._getBubbleItem('Teplota',temp + ' \u00B0C'));
		$('#mg-bubble-stats'+'-'+id).append(this._getBubbleItem('Sr\u00E1\u017Eky',rain + ' mm'));
		$('#mg-bubble-stats'+'-'+id).append(this._getBubbleItem('Stav', state));
		$('#sm-mg-bg-box-vert-'+idx+'-'+id).toggleClass('mg-bg-box-vert-hover',true);
		$('#sm-mg-bg-box-vert-'+idx+'-'+id).toggleClass('mg-bg-box-vert',false);
	},

	_getBubbleItem: function(name, value) {
		return '<li><strong>'+name+': </strong><span>'+value+'</span></li>';
	},

	_meteogramMouseOut: function(idx, id) {
		$('#mg-bubble-'+id).attr('style','display: none;');
		$('#sm-mg-bg-box-vert-'+idx+'-'+id).toggleClass('mg-bg-box-vert-hover',false);
		$('#sm-mg-bg-box-vert-'+idx+'-'+id).toggleClass('mg-bg-box-vert',true);
	},

	_mgContMouseOut: function() {
		$('#mg-bubble').attr('style','display: none;');
	}
};


function selItem(items) {
    for (k = 0; k < items.length; k ++) {
        if (items[k].selected) {
            return items[k];
        }
    }
    if (items.length >= 1) {
        return items[0];
    } else {
        return {caption:'UNDEFINED'};
    }
};


/* Fisheye Menu v1.0
   Written by Marc Grabanski (m@marcgrabanski.com)

   Copyright (c) 2007 Marc Grabanski (http://marcgrabanski.com/code/fisheye-menu)
   Dual licensed under the GPL (http://www.gnu.org/licenses/gpl-3.0.txt) and
   CC (http://creativecommons.org/licenses/by/3.0/) licenses. "Share or Remix it but please Attribute the authors."
   Date: 10-05-2007  */

var fisheyemenu = {
	startSize : 30,
	endSize : 50,
	imgType : ".png",
	init : function (itemId) {
		var animElements = document.getElementById(itemId).getElementsByTagName("img");
		var titleElements = document.getElementById(itemId).getElementsByTagName("span");
		for(var j=0; j<titleElements.length; j++) {
			titleElements[j].style.display = 'none';
		}
		for(var i=0; i<animElements.length; i++) {
			var y = animElements[i];			
			y.style.width = fisheyemenu.startSize+'px';
			y.style.height = fisheyemenu.startSize+'px';
			fisheyemenu.imgSmall(y);
			animElements[i].onmouseover = changeSize;
			animElements[i].onmouseout = restoreSize;
		}
		function changeSize() {
			fisheyemenu.imgLarge(this);
			var x = this.parentNode.getElementsByTagName("span");
			x[0].style.display = 'block';
			if (!this.currentWidth) this.currentWidth = fisheyemenu.startSize;
			fisheyemenu.resizeAnimation(this,this.currentWidth,fisheyemenu.endSize,15,10,0.333);
		}
		function restoreSize() {
			var x = this.parentNode.getElementsByTagName("span");
			x[0].style.display = 'none';
			if (!this.currentWidth) return;
			fisheyemenu.resizeAnimation(this,this.currentWidth,fisheyemenu.startSize,15,10,0.5);
			fisheyemenu.imgSmall(this);
		}
	},
	resizeAnimation : function (elem,startWidth,endWidth,steps,intervals,powr) {
		if (elem.widthChangeMemInt) window.clearInterval(elem.widthChangeMemInt);
		var actStep = 0;
		elem.widthChangeMemInt = window.setInterval(
			function() {
				elem.currentWidth = fisheyemenu.easeInOut(startWidth,endWidth,steps,actStep,powr);				
				elem.style.width = elem.currentWidth+"px";
				elem.style.height = elem.currentWidth+"px";
				actStep++;
				if (actStep > steps) window.clearInterval(elem.widthChangeMemInt);
			}
			,intervals)
	},
	easeInOut : function (minValue,maxValue,totalSteps,actualStep,powr) {
	//Generic Animation Step Value Generator By www.hesido.com
		var delta = maxValue - minValue;
		var stepp = minValue+(Math.pow(((1 / totalSteps)*actualStep),powr)*delta);
		return Math.ceil(stepp)
	},
	imgSmall : function (obj) {
		imgSrc = obj.getAttribute("src");
		var typePos = imgSrc.indexOf(fisheyemenu.imgType, 0);
		var imgName = imgSrc.substr(0, typePos);
//		obj.setAttribute("src", imgName+fisheyemenu.imgType);
		obj.setAttribute("src", imgName+"_small"+fisheyemenu.imgType);
	},
	imgLarge : function (obj) {
		imgSrc = obj.getAttribute("src");
		var typePos = imgSrc.indexOf("_small", 0);
		var imgName = imgSrc.substr(0, typePos);
		obj.setAttribute("src", imgName+fisheyemenu.imgType);
	}
};



// TODO necessary for youtube created using swfobject
function onYouTubePlayerReady(playerId) {
	Supermap.youtube = document.getElementById(Supermap.youtubePlayerId);	
};


/** callback function for loading meteograms
 *
 * @param data
 */
function callbackFunction(data) {
	Supermap._handleMeteogramCallback(data);		
};


$.extend({
  getUrlVars: function(){
    var vars = {}, hash;
	if(window.location.href.indexOf('#')<0)
		return vars;
	var params = window.location.href.slice(window.location.href.indexOf('#') + 1);
//	if(params.indexOf('#')>=0)
//		params = params.substring(0, params.indexOf('#'));
    var hashes = params.split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
//      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});

$.extend({
	setUrlVar: function(params) {
		var nurl = window.location.href;
		if(window.location.href.indexOf('#')>=0) {
			nurl = window.location.href.slice(0, window.location.href.indexOf('#')+1);
		} else {
			nurl = nurl.concat('#');
		}
		nurl = nurl.concat( $.getLocalUrlParamsForMany(params) );
		window.location.replace(nurl);
	},
	getLocalUrlParams: function(name, val) {
		var added = false;
		var nurl = '';
		if(window.location.href.indexOf('#')>=0) {
			var params = window.location.href.slice(window.location.href.indexOf('#') + 1);
			var hashes = params.split('&');
			var bFound = false;
			for(var i = 0; i < hashes.length; i++)
			{
				if(!hashes[i])
					continue;
				var hash = hashes[i].split('=');
				if(hash[0] == name) {
					bFound = true;
					hash[1] = val;
				}
				if(added)
					nurl = nurl.concat('&');
				nurl=nurl.concat(hash[0]+'='+hash[1]);
				added = true;
			}
		}
		if(!bFound) {
			if(added)
				nurl = nurl.concat('&');
			nurl=nurl.concat(name+'='+val);
		}
		return nurl;
	},
	getLocalUrlParamsForMany: function(params) {
		var toDelNames = ['sm','femg'];
		var omit = [];
		for(var i=0; i<toDelNames.length; i++) {
			if(!params[toDelNames[i]])
				omit.push(toDelNames[i]);
		}

		var nurl = '';
		var k = 0;
		for(var name in params) {
			if(k>0)
				nurl = nurl.concat('&');
			nurl = nurl.concat(name+'='+params[name]);
			k++;
		}
		if(window.location.href.indexOf('#')>=0) {
			var link = window.location.href.slice(window.location.href.indexOf('#') + 1);
			var hashes = link.split('&');
			for(var i = 0; i < hashes.length; i++)
			{
				if(!hashes[i])
					continue;
				var hash = hashes[i].split('=');
				var skip = false;
				if(params[hash[0]])
					skip = true;
				for(var j=0; j<omit.length; j++)
					if(omit[j]==hash[0]) {
						skip = true;
						break;
					}
				if(skip)
					continue;
				if(k>0)
					nurl = nurl.concat('&');
				nurl=nurl.concat(hash[0]+'='+hash[1]);
				k++;
			}
		}
		return nurl;
	}
});

$.extend({
	getName: function(c_name) {
		return c_name+'_'+escape(document.location.pathname);
	},
	parseName: function(name) {
		var path = '_'+escape(document.location.pathname);
		if(name.indexOf(path)>=0) {
			return name.replace(path,'');
		}
		return null;
	},
	setCookie: function(c_name,value,expiredays) {
		var exdate=new Date();//((new Date()).getTime()+14*86400000);
		exdate.setDate(exdate.getDate()+expiredays);
		var name = $.getName(c_name);
		document.cookie=name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toUTCString()) + ";path="+document.location.pathname;
//		$('#debug-log').append(escape(document.location.pathname) + '<br/>');
	},
	getCookie: function(c_name) {
		if (document.cookie.length>0) {
			var name = $.getName(c_name);
			var c_start=document.cookie.indexOf(name + "=");
			if (c_start!=-1) {
				c_start=c_start + name.length+1;
				var c_end=document.cookie.indexOf(";",c_start);
				if (c_end==-1)
					c_end=document.cookie.length;
				return unescape(document.cookie.substring(c_start,c_end));
			}
		}
		return "";
	},
	getCookieVars: function() {
		var vars = {};
		var smParams = {sm:1,femg:1};
		var cv = document.cookie.split('; ');
		for(var i=0; i<cv.length; i++) {
//			$('#debug-log').append(cv[i]);
			var cvp = cv[i].split('=');
			var name = $.parseName(cvp[0]);
			if(!name)
				continue;
			if(smParams[name])
				vars[name] = unescape(cvp[1]);
		}
		return vars;
	},
	setCookieVars: function(params, expiredays) {
		$.deleteCookies({'sm':0,'femg':0});
		for(var x in params) {
			$.setCookie(x, escape(params[x]), expiredays);
//			$('#debug-log').append('add: ' + x + '=' + params[x] + '<br/>');
		}
	},
	deleteCookies: function( params ) {
		for(var name in params) {
			if ( $.getCookie( name ) ) {
				var n = $.getName(name);
				document.cookie = n + "=" +
				";expires=Thu, 01-Jan-1970 00:00:01 GMT" +
				";path=" + document.location.pathname;
			}
		}
	}
});
