jQuery(function($){
	$(".jsmap-content li").hide();
	$(".jsmap-content").find("li:first").show();
	
	$('.jsmap area').mouseenter(function(){
		var map = $(this).parents(".jsmap");
		if(map.hasClass("zoom"))
			return;
		
		map.find(".jsmap-content li").hide();
		map.find("#"+$(this).attr("id")+"-map, #"+$(this).attr("id")+"-cnt").show();
		map.find(".jsmap-nav li").removeClass("active");
		map.find("#"+$(this).attr("id")+"-nav").addClass("active");
	}).mouseleave(function(){
		var map = $(this).parents(".jsmap");
		map.find(".jsmap-areas > li, .jsmap-content li").hide();
		map.find(".jsmap-content li:first").show();
		map.find(".jsmap-nav li").removeClass("active");
	});
	
	$('.jsmap-big .jsmap-nav li').mouseenter(function(){
		var map = $(this).parents(".jsmap");
		if(map.hasClass("zoom"))
			return;
		
		var mapid = $(this).attr("id");
		mapid = mapid.split('-');
		mapid = mapid[0];
		map.find("#"+mapid+"-map").show();
	}).mouseleave(function(){
		var map = $(this).parents(".jsmap");
		if(map.hasClass("zoom"))
			return;
		
		map.find(".jsmap-areas > li").hide();
	});
	
	$('.jsmap-show-all').click(function(e){
		e.preventDefault();
		var map = $(this).parents('.jsmap');
		if( ! map.hasClass("zoom"))
			return;
		
		map.find(".jsmap-areas>li").hide();
		map.find(".jsmap-places").removeClass("show-places").find(">li").show();
		//map.find(".jsmap-overlay").show();
		
		map.find(".jsmap-map-wrapper").animate({
			height: 318,
			width: 718,
			top: 0,
			left: 0
		}, function(){
			map.removeClass("zoom").find(".zoom").removeClass("zoom");
		});
	});
	
	$('.jsmap-show-places').click(function(e){
		e.preventDefault();
		var map = $(this).parents('.jsmap');
		map.find('.jsmap-places').toggleClass('show-places');
	});
	
	if($(".jsmap-big").hasClass("zoom"))
	{
		var map = $(this);
		//map.find(".jsmap-overlay").hide();
		var area = $(".jsmap-big .jsmap-nav").find(".zoom:first");
		area.addClass("active");
		var area_id = area.attr("id").split('-')[0];
		var w, h, x, y;
		
		switch(area_id)
		{
			case "porec3":
				w = 3000;
				h = 1328;
				y = -341;
				x = -290;
			break;
			case "umag3":
				w = 3000;
				h = 1328;
				x = -224;
				y = -105;
			break;
			case "vrsar3":
				w = 4000;
				h = 1771;
				x = -450;
				y = -700;
			break;
			case "rovinj3":
				w = 3000;
				h = 1328;
				x = -355;
				y = -620;
			break;
			case "labin3":
				w = 1756;
				h = 778;
				x = -385;
				y = -260;
			break;
			case "central3":
				w = 1332;
				h = 590;
				x = -106;
				y = -62;
			break;
			case "pula3":
				w = 1471;
				h = 652;
				x = -180;
				y = -315;
			break;
		}
		
		map.find(".jsmap-map-wrapper").animate({
			width: w,
			height: h,
			top: y,
			left: x
		}, function(){
			map.find("#"+area_id+"-map").fadeIn();
			map.find(".jsmap-places").addClass("show-places").find(">li:not(#"+area_id+"-places)").hide();
		});
		
		map.find('.jsmap-places ul li').click(function(){
			window.location.href = $(this).find("a").attr("href");
		});
	}
});
