var requiredMajorVersion = 9;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 115;

var hasProductInstall = DetectFlashVer(6, 0, 65);

// Version check based upon the values defined in globals
var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

//cookie


    function setCookie(CookieName, CookieVal, CookieExp, CookiePath, CookieDomain, CookieSecure)

    {

 	    var CookieText = escape(CookieName) + '=' + escape(CookieVal); //escape() : Encodes the String

	    CookieText += (CookieExp ? '; EXPIRES=' + CookieExp.toGMTString() : '');

	    CookieText += (CookiePath ? '; PATH=' + CookiePath : '');

	    CookieText += (CookieDomain ? '; DOMAIN=' + CookieDomain : '');

	    CookieText += (CookieSecure ? '; SECURE' : '');

    	

	    document.cookie = CookieText;

    }



    // This functions reads & returns the cookie value of the specified cookie (by cookie name) 

    function getCookie(CookieName)

    {

 	    var CookieVal = null;

	    if(document.cookie)	   //only if exists

	    {

       	    var arr = document.cookie.split((escape(CookieName) + '=')); 

       	    if(arr.length >= 2)

       	    {

           	    var arr2 = arr[1].split(';');

       		    CookieVal  = unescape(arr2[0]); //unescape() : Decodes the String

       	    }

	    }

	    return CookieVal;

    }



    // To delete a cookie, pass name of the cookie to be deleted

    function deleteCookie(CookieName)

    {

 	    var tmp = getCookie(CookieName);

	    if(tmp) 

	    { 

	        setCookie(CookieName,tmp,(new Date(1))); //Used for Expire 

	    }

    }
    
    
    

// end cookie


    if(document.location.hash == '#noflash') {
    	alert('flash mapy jsou deaktivovany');
		setCookie('noflash', true);   
    }
    if(document.location.hash == '#flash') {
    	alert('flash mapy jsou aktivovany');
		deleteCookie('noflash');   
    }



function embedFlash(){
	
    if(document.location.hash == '#noflash') {
		return false;    
    }

    if (hasRequestedVersion) {
        // if we've detected an acceptable version
        // embed the Flash Content SWF when all tests are passed
        AC_FL_RunContent.apply(this, arguments);
    }
    else 
        if (hasProductInstall && !hasRequestedVersion) {
        
            // MMdoctitle is the stored document.title value used by the installation process to close the window that started the process
            // This is necessary in order to close browser windows that are still utilizing the older version of the player after installation has completed
            // DO NOT MODIFY THE FOLLOWING FOUR LINES
            // Location visited after installation is complete if installation is required
            var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
            var MMredirectURL = window.location;
            document.title = document.title.slice(0, 47) + " - Flash Player Installation";
            var MMdoctitle = document.title;
            
            AC_FL_RunContent("src", "playerProductInstall", "FlashVars", "MMredirectURL=" + MMredirectURL + '&MMplayerType=' + MMPlayerType + '&MMdoctitle=' + MMdoctitle + "", "width", "100%", "height", "100%", "align", "middle", "id", "ggg", "quality", "high", "bgcolor", "#ffffff", "name", "ggg", "allowScriptAccess", "sameDomain", "type", "application/x-shockwave-flash", "pluginspage", "http://www.adobe.com/go/getflashplayer");
            return true;
            
        }
        else { // flash is too old or we can't detect the plugin
            var alternateContent = 'Tento aktivní prvek nelze zobrazit.<br/> ' +
            'Pro jeho zobrazení potřebujete Adobe Flash Player 9.  ' +
            '<a href=http://www.adobe.com/go/getflash/>Získat Flash nyní!</a>';
          //  document.write(alternateContent); // insert non-flash content
            return false;
        }
    
}

function flashVars(o){
    var v = '';
    for (var item in o) {
        v += item + '=' + o[item] + '&';
    }
    return v;
}

var PriceChartOld = {
	show: function(params){
		 embedFlash("src", "http://charts.false.cz/price-chart?x=" + Math.random(),
			"width", "420",
			"height", "300",
			"align", "middle",
			"id", "hotel-graph",
			"quality", "high",
			"bgcolor", "#ffffff",
			"allowscriptaccess","always",
			"type", "application/x-shockwave-flash",
			"pluginspage", "http://www.adobe.com/go/getflashplayer",
			"flashvars", flashVars(params)); 
	},
	show2: function(params){
		return;
		params.baseUrl = 'http://charts.false.cz/';
		
		embedFlash("src", "http://charts.false.cz/price-chart-v2",

		//embedFlash("src", "http://charts.false.cz/price-chart-v2?x=" + Math.random(),
			"width", "520",
			"height", "320",
			"align", "middle",
			"id", "hotel-graph",
			"quality", "high",
			"bgcolor", "#ffffff",
			"allowscriptaccess","always",
			"type", "application/x-shockwave-flash",
			"pluginspage", "http://www.adobe.com/go/getflashplayer",
			"flashvars", flashVars(params)); 
	},
	showHistory: function(params) {
		params.type = 'history';
		PriceChart.show2(params);
	},
	showFuture: function(params) {
		params.type = 'future';
		PriceChart.show2(params);
	}
};


var PriceChart = {
	show: function(params){
		params.baseUrl = 'http://static.ncore.cz/charts/';
		
		embedFlash("src", "http://static.ncore.cz/charts/price-chart-v2",

		//embedFlash("src", "http://charts.false.cz/price-chart-v2?x=" + Math.random(),
			"width", "520",
			"height", "320",
			"align", "middle",
			"id", "hotel-graph",
			"quality", "high",
			"bgcolor", "#ffffff",
			"allowscriptaccess","always",
			"type", "application/x-shockwave-flash",
			"pluginspage", "http://www.adobe.com/go/getflashplayer",
			"flashvars", flashVars(params)); 
	},
	showHistory: function(params) {
		params.type = 'history';
		PriceChart.show(params);
	},
	showFuture: function(params) {
		params.type = 'future';
		PriceChart.show(params);
	}
};


var Maps = {
	regionShow: function(params, noflash){

	
		params.apiKey = 'ABQIAAAAfdaAp0Kld0lAIGZqsvXbhxQmz9k-q3sREFh1NLlWxNl896FCEhQzwOh6FCaGh4zgg-dGApDN0G5aZQ';
		
		
		var ret = false;
		
		if(! noflash	) {  // || ! getCookie('noflash')) {
		
			ret = embedFlash("src", "http://charts.false.cz/regionmap?x=1", // + Math.random(),
				"width", "535",
				"height", "260",
				"align", "middle",
				"id", "hotel-graph",
				"quality", "high",
				"bgcolor", "#ffffff",
				"allowscriptaccess","always",
				"wmode", "transparent",
				"style", "z-index:10",
	
				"allowFullScreen", "true",
				"type", "application/x-shockwave-flash",
				"pluginspage", "http://www.adobe.com/go/getflashplayer",
				"flashvars", flashVars(params)); 
		}
		
			
		if(ret == false ){
//			document.write('x');
			document.write('<script type="text/javascript" src="http://static.ncore.cz/maps/js/?v=1"></script>');
			

			var extendPopup = false;
			if(document.location.search.indexOf('giataId') > 0) {
				extendPopup = true;
			}
			
			var width = 520;
			var height = 260;

			var pc = parent.document.getElementById('popupContainer');

			if(extendPopup && pc) {
				var nv = 800;
				var nh = 400;
				

				var left = parseInt(pc.style.left);
				var top = parseInt(pc.style.top);

				left -= (nv - width) / 2
				top -= (nh - height) / 2

				width = nv;
				height = nh;
				
				
				pc.style.width = width+'px';
				pc.style.height = height+'px';
//				pc.style.left = left + 'px';
//				pc.style.top = top + 'px';
				var ifr = pc.getElementsByTagName('iframe');
				ifr[0].style.width = width + 'px';
				ifr[0].style.height = height + 'px';
				$ = parent.window.jQuery;
				parent.window.centerPopup($('#popupContainer'), $('popupContainerBack'), "button_close_group");
				
			}
			
			document.write('<div id="map_canvas" style="width:'+width+'px; height:'+height+'px"></div>');
			params.data = decodeURIComponent(params.data);
//			var data = JSON.parse(params.data);
			var data = eval('('+params.data+')');
			
			NCMapsLoaded = function() {
				var nmap = new NC.Map();
				nmap.renderMap(data, params.exchange );
			}

		
			
		}	


	},
	regionShowWide: function(params){

	
		params.apiKey = 'ABQIAAAAfdaAp0Kld0lAIGZqsvXbhxQmz9k-q3sREFh1NLlWxNl896FCEhQzwOh6FCaGh4zgg-dGApDN0G5aZQ';
		 embedFlash("src", "http://charts.false.cz/regionmap?x=1", // + Math.random(),
			"width", "728",
			"height", "260",
			"align", "middle",
			"id", "hotel-graph",
			"quality", "high",
			"bgcolor", "#ffffff",
			"allowscriptaccess","always",
			"wmode", "transparent",
			"style", "z-index:10",

			"allowFullScreen", "true",
			"type", "application/x-shockwave-flash",
			"pluginspage", "http://www.adobe.com/go/getflashplayer",
			"flashvars", flashVars(params)); 


	},
	hotelShow: function(params){
		params.type = 'hotel';
		Maps.regionShow(params, true);
		phxx(params);
	}

};

function phxx(params) {
//	if(document.location.href == "#bender") {
/*
var x = unescape(params.data);
var o = x.split('"');
var lng = o[11];
var lat = o[15];
document.write('<script src="http://bender/panoramio/?lat='  + lat + '&lng=' + lng+'">');
*/
}

//document.write('<!--[if lt IE 7]>');
//document.write('<script src="http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE7.js" type="text/javascript"></script>');
//document.write('<![endif]-->');
