$(function() {
	
	$(".slidetabs").tabs(".images > div", {
		effect: 'fade',
		fadeOutSpeed: "slow",
		rotate: true
	}).slideshow();
	
	$(".slidetabs_big").tabs(".images_big > div", {
		effect: 'fade',
		fadeOutSpeed: "slow",
		rotate: true
	}).slideshow();
	
	$("div.tabs").tabs("div.panes > div");
	$("div.awards_tabs").tabs("div.awards_panes > div");
	
	$(".scrollable").scrollable({
		circular: true, 
		vertical: true, 
		mousewheel: false
	}).navigator().autoscroll({
		interval: 3000
	});
	
	// Gallery
	$("a[rel]").overlay({
		mask: {
			color: '#000',
			loadSpeed: 200,
			opacity: 0.5
		}
	});
});

function myMM(e) {  
  var small_div = $("#small");
  var big_div = $("#big");
  var big_img = $("#big img");
  var glass = $("#glass");
  var xs = e.pageX - small_div.offset().left;
  var ys = e.pageY - small_div.offset().top;
  var bx = big_img.width()/2 - xs*W/w;
  var by = big_img.height()/2 - ys*H/h;
  //glass.css("left", e.pageX-126 +"px").css("top", e.pageY-126 +"px"); 
	glass.css("left", (xs-88) +"px").css("top", (ys+33) +"px"); /* FIX for LIVIKO*/
	big_div.css("background-position", (bx+126) +"px "+ (by+126) +"px");
  /*if (bx<-W || by<-H || bx>240 || by>240) {
  	small_div.unbind('mousemove', myMM);
  	glass.fadeOut('fast');
  }*/
	check_map(by, bx);
} 

// name img padding-top padding-left width height img-pagging-top img-pagging-left
function check_map(top, left) {
	top = top*(-1);
	left = left*(-1);
	var show = false;
	for (x in map) {
		if (top > map[x][2] && left > map[x][3] && top < (map[x][2]+map[x][5]) && left < (map[x][3]+map[x][4])) {
			$("#country_box").show().css({
				'background': 'url(http://www.liviko.ee/public/index/map/'+map[x][1]+') left top no-repeat',
				'background-position': (map[x][7]-left)+'px '+(map[x][6]-top)+'px'
			});
			$("#infobox").show();
			$("#infobox").html(map[x][0]);
			show = true;
		}
	}
	if (show == false) {
	 $("#infobox").hide();
	 $("#country_box").hide();
	}
}
