if(!window.console){window.console = {};window.console.log = function(){}}

$(document).ready(function(){
	hint.init();
	$("#map").click(function(e){
		console.log("x",e.offsetX,"y",e.offsetY);
	});
	fillPositions();
	
	$("#blog").delegate(".link","click",function(e){
		window.open( $(this).attr("href") );
		return false;
	});

	$("#map").delegate(".mapIcon","mouseover",function(e){
		console.log(e);
		var t = $(e.target), to = t.offset();
		hint.show(to.left+25,to.top,t.attr("title"));
	});
	$("#map").delegate(".mapIcon","mouseout",function(e){
		hint.hide();
	});		
	$("#map").delegate(".mapIcon","click",function(e){
		//var st = $("#shops").offset().top;
		var st = $(".shop-"+$(this).attr("rel")).offset().top;

		$("body,html").animate({scrollTop:st},200);
	});		

});

var hint = {
	dom : -1,
	init : function(){
		hint.dom = $("#hint");
	},
	show : function(x,y,title){
		hint.dom
			.text(title)
			.css({
				opacity : 1,
				left: x + "px",
				top: y + "px"
			});
	},
	hide : function(){
		hint.dom.css("opacity",0);
	}
}

function fillPositions(){
	if(window.positions){
		var n = positions.length;
		for(var i = 0; i<n; i++){
			if(positions[i].mapPosition){
				$("<div></div>")
					.addClass("mapIcon")
					.attr("title",positions[i].name)
					.attr("rel",i)
					.css({
						"left" : positions[i].mapPosition.x - 10 + "px",
						"top" : positions[i].mapPosition.y - 10 + "px"
					})
					.data("shop",i)
					.appendTo("#map");				
			}
		}
	}
}
