$(document).ready(function(){
	$(window).scroll(function(){ backgroundScroll(); });
});

function backgroundScroll() {
	var topOffset = $(window).scrollTop();
	var headerHeight = $('#header').height();
	//var windowHeight = $(window).height();
	//var pageHeight = $(document).height();
	//var footerHeight = $('#footer').height();
	//$('.seal').css('margin-top', headerHeight + (topOffset / 2));
	$('.seal').animate({marginTop: headerHeight + (topOffset / 2)},50);
	/*
	if(topOffset < (pageHeight - windowHeight - footerHeight)) {
		$('.content').css('background-position-y', headerHeight - (topOffset / 2));
	} else {
		//alert('Page: '+pageHeight+'     Window: '+windowHeight);
	}
	*/
}

function changeLocation(id,location_id) {
	$.ajax({
		type: "GET",
		url: "/location.php",
		data: ({id : id, location: location_id}),
		dataType: "html",
		success: function(data) {
			$('#locations-box').html(data);
			loadMap();
		}
	});
}

function loadMap() {
	google.load("maps", "2.x", {callback : initializeMap});
}

function initializeMap() {
	var latitude = $('#map_latitude').val();
	var longitude = $('#map_longitude').val();
	var map = new google.maps.Map2(document.getElementById("googlemap"));
	map.setCenter(new google.maps.LatLng(latitude, longitude), 15);
	map.addControl(new GSmallZoomControl()); 
	var marker = new GMarker(map.getCenter(), G_DEFAULT_ICON, {clickable: true});
	
	map.addOverlay(marker); 
}

function galleryLoad(galleryType,galleryID) {
	$.ajax({
		type: "GET",
		url: "/includes/gallery.php",
		data: ({id : galleryID, type: galleryType}),
		dataType: "html",
		success: function(data) {
			$('.gallery .preload').html(data);
			if(galleryType=='image'){
				$('.gallery .preload img').load(function(){
					$('.gallery .active').fadeOut(function(){
						$('.gallery .active').html(data);
						$('.gallery .active').show();
					});
				});
			} else {
				$('.gallery .active').hide();
				$('.gallery .preload').show();
				$('.gallery .active').html(data);
				$('.gallery .preload').hide();
				$('.gallery .active').show();
			}
		}
	});
}
