
$(document).ready(function(){
	if($("#map").length > 0) {
		loadmap();
	}
	
	tooltip();
	selectSubmit();
	lightboxes();
});


function loadmap() {
  if(GBrowserIsCompatible()) {
	var map = new GMap2(document.getElementById("map"));
	map.setCenter(new GLatLng(50.107152,14.485244), 14);
	var marker = new GMarker(new GLatLng(50.108752, 14.487244));
	map.addOverlay(marker);
	GEvent.addListener(map, "click", function() {
		location.href = 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=arena+sparta,+Podvinn%C3%BD+Ml%C3%BDn&sll=50.107148,14.485281&sspn=0.011202,0.027874&ie=UTF8&hq=arena+sparta,+Podvinn%C3%BD+Ml%C3%BDn&hnear=&cid=7204379364555328797&ll=50.107506,14.485195&spn=0.040075,0.111322&z=14'
	});
	var mapControl = new GSmallMapControl();
	map.addControl(mapControl);
  }
}

function tooltip(){	
	/* CONFIG */		
		xOffset = 20;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$(".existingBlockTooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";
		this.anchor = this.href.substring(this.href.lastIndexOf("#"));
		$("body").append("<div id='tooltip'></div>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.show();
		if($(this.anchor).length > 0) {
			$(this.anchor).clone().appendTo($("#tooltip"));
		} else {
			$("#tooltip").text(this.t);
		}

		return false;
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$(".existingBlockTooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

function selectSubmit() {

	$(".selectSubmit").change(function(){
			$(this).parents("form").submit();
	});

}

this.lightboxes = function() {
	
	// lb musi byt <a rel="lightbox-galerie"..
	
	str = '';
	$('a[rel^=lightbox]').each(function(){
		uq = $(this).attr("rel").substr(9);
		if(str.indexOf("<" + uq + ">") == -1) {
			str += "<" + uq + ">";
		}
	});
	gals = str.substr(1, str.length-2).split("><");
	for(i = 0; i < gals.length; i++) {
		$("a[rel=lightbox-" + gals[i] + "]").lightBox({
			containerResizeSpeed: 400,
			txtImage: "Obrázek / Image :",
			txtOf: "/",
			imageLoading: "/img/lb-loading.gif",
			imageBtnClose: "/img/lb-btn-close.gif",
			imageBtnPrev: "/img/lb-btn-prev.gif",
			imageBtnNext: "/img/lb-btn-next.gif"
		});
	}

}
