﻿var MAP_CENTER_Y = 42.8;
var MAP_CENTER_X = 25.45;
var MAP_CENTER_ZOOM = 7;

var mapOptions;
var geocoder;
var map;
var markers = Array();

// Cookies
function getCookie(c_name){
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++){
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
		if (x==c_name){
			return unescape(y);
		}
	}
}

function setCookie(c_name,value,exdays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}

function checkCookie(name) {
	var cookie = getCookie(name);
	if (cookie != null && cookie != "")   {
		return false;
	}else {
		setCookie(name, "true");
		return true;
	}
}


function getFlashVersion(){
	// ie
	try {
		try {
			// avoid fp6 minor version lookup issues
			// see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
			var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
			try { axo.AllowScriptAccess = 'always'; }
			catch(e) { return '6,0,0'; }
		} catch(e) {}
			return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
		// other browsers
	} catch(e) {
		try {
			if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
				return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
			}
		} catch(e) {}
	}
	return '0,0,0';
}

function initializeGMap(flag){ 
	geocoder = new google.maps.Geocoder();
	mapOptions = {
		zoom: MAP_CENTER_ZOOM,
		center: new google.maps.LatLng(MAP_CENTER_Y, MAP_CENTER_X),
		disableDefaultUI: false,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	map = new google.maps.Map(document.getElementById("idMap"), mapOptions);
	
	for(var i in cities) {
		markers[i] = new google.maps.Marker({
			map: map,
			position: new google.maps.LatLng(cities[i].posY, cities[i].posX),
			title: cities[i].title
		});
		
		addMarkerListener(markers[i], cities[i]);
	}
}

function addMarkerListener(marker, city){
	google.maps.event.addListener(marker, 'click', function(event) {
		window.location.href = "./?id=" + city.id + '&page=' + city.page;
	});	
}


$(window).load(function() { 
	$("#nav li.cat").children().each(
		function() {
			if ($("ul", this).children().length > 0) {
				$("ul", this).repositionItem(this, $(this).height());
				
			}
		}
	);
	
	$("#nav li.cat").hoverIntent(function() {
		$("div.sub", this).fadeIn("fast");
	} , function() {
		$("div.sub", this).fadeOut("fast");
	});
});


$.fn.repositionItem = function(obj, objH) {
	var hPlus = 17;
	$(".left-shadow", obj).height (objH + hPlus);
	$(".right-shadow", obj).height (objH + hPlus);
};
