$(function() {
$("div.map-point").hover(function() {
	$("#map-point-popup").hide().remove();
	$(this).append("<div class='map-content-popup alpha' id='map-point-popup'></div>");
	$("#map-point-popup").html($(this).find("div.map-point-content").html());
}, function() {
	$("#map-point-popup").hide().remove();
}
);


$("#photogallery img.gallery-photo").click(function() {
	index = $("img.gallery-photo").index($(this))+1;
	var arrPageScroll = ___getPageScroll();
	var arrPageSizes = ___getPageSize();
	$("<div id='blacker'></div>").appendTo("body").css("height", $(document).height());
	$("<div id='photo-container'><img src='img/preloader.gif' id='preloader' /><a href='#' id='photo-close' class='alpha'></a><div class='sh tl'></div><div class='sh tr'></div><div class='sh bl'></div><div class='sh br'></div></div>").appendTo("body").css({top: arrPageScroll[1] + (arrPageSizes[3])/2, marginTop: $("#photo-container").outerHeight()/2*-1});
	newimgsrc = $(this).attr('rel');
	newimgalt = $(this).attr('alt');
	if($.browser.opera) {
		$newimg = $(new Image());
		$newimg.attr({src: newimgsrc, alt: newimgalt});
	}
	else $newimg = $("<img src='"+newimgsrc+"' alt='"+newimgalt+"' />");
	$newimg.load(function() {
		$("#preloader").remove();
		$("#photo-container").prepend("<div id='photo-heading'>"+$(this).attr('alt')+"</div><div id='photo-content'></div><div id='photo-count'>"+index+"</div>");
		$(this).appendTo("#photo-content");
		$("#photo-container").css({width: $(this).outerWidth()+100, height: $(this).innerHeight()+110, marginLeft: ($(this).innerWidth()+100)/2*-1, marginTop: ($(this).innerHeight()+110)/2*-1});
		jQuery(".tl, .tr").css("height", jQuery("#photo-container").innerHeight());
	});
	images = $("img.gallery-photo");
	if(images.length>1) {
		$("#photo-container").append("<a href='#' id='photo-left' class='photo-switcher'></a><a href='#' id='photo-right' class='photo-switcher'></a>");
		switch(index) {
			case 1:
				$("#photo-left").addClass("disable");
			break;
			case images.length:
				$("#photo-right").addClass("disable");
			break;
		}
	}
});

$("a.photo-switcher").live("click", function() {
	$(".tl, .tr").css("height", "auto");
	$("#photo-container").css({width: 300, height: 200, marginLeft: -150, marginTop: -100});
	$("a.photo-switcher").removeClass("disable");
	$("#photo-container").find("#photo-heading, #photo-content, #photo-count").remove().end().prepend("<img src='img/preloader.gif' id='preloader' />");
	if($(this).attr("id")=="photo-left") {
		index -= 1;
	}
	else {
		index += 1;
	}
	switch(index) {
		case 1:
			$("#photo-left").addClass("disable");
		break;
		case images.length:
			$("#photo-right").addClass("disable");
		break;
	};
	newimgsrc = images.eq(index-1).attr('rel');
	newimgalt = images.eq(index-1).attr('alt');
	if($.browser.opera) {
		$newimg = $(new Image());
		$newimg.attr({src: newimgsrc, alt: newimgalt});
	}
	else $newimg = $("<img src='"+newimgsrc+"' alt='"+newimgalt+"' />");
	$newimg.load(function() {
		$("#preloader").remove();
		$("#photo-container").prepend("<div id='photo-heading'>"+$(this).attr('alt')+"</div><div id='photo-content'></div><div id='photo-count'>"+index+"</div>");
		$(this).appendTo("#photo-content");
		$("#photo-container").css({width: $(this).outerWidth()+100, height: $(this).innerHeight()+110, marginLeft: ($(this).innerWidth()+100)/2*-1, marginTop: ($(this).innerHeight()+110)/2*-1});
		jQuery(".tl, .tr").css("height", jQuery("#photo-container").innerHeight());
	});
	return false;
});

$("#photo-close").live("click", function() {
	$("#photo-container, #blacker").hide().remove();
	return false;
});

$("body").append("<div style='position: absolute; top: 0; left: 0; visibility: hidden'><img src='img/preloader.gif' /><img src='img/photo-close.jpg' /><img src='img/photo-sprite.png' /></div>");





function ___getPageScroll() {
			var xScroll, yScroll;
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;	
			}
			arrayPageScroll = new Array(xScroll,yScroll);
			return arrayPageScroll;
		};

	function ___getPageSize() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		};
});
