function SelectState(id){
	$('#state_'+id+'_base').hide();
	$('#state_'+id+'_over').show();
}
function RestoreMap(){
	$('.state_over').hide();
	$('.state_base').show();
}

function showFeatured(id){
	//$('#sb_text').html(id+'::'+id_curr+'::'+id_prev);
	
	if (id!==undefined){
		stop_timer = 1;
		//if (id==id_curr) return;
		if (id_curr!=id){
			id_prev = id_curr;
		}else{
			clearTimeout(iTimer);
			iTimer = 0;
			return;
		}
		id_curr = id;
		
	}
	else{
		stop_timer = 0;
		id_prev = id_curr;
		++id_curr;
		if (id_curr>num_images-1)id_curr=0;
		id=id_curr;
	}
	if (iTimer) {
		clearTimeout(iTimer);
		iTimer = 0;
	}
	
	if (!stop_timer){
		
		$('#h_bi_'+id).css('z-index','1').addClass('curr').css('opacity',1);
		$('.hf_link').removeClass('curr');
		$('#hf_link_'+id).addClass('curr');
		$('#h_bi_'+id_prev).css('z-index','2').animate({opacity: 0}, 1000, function() {
			$(this).removeClass('curr');
			
		});

		iTimer = setTimeout("showFeatured()", gal_delay);
	}else{
		/*$('.h_bi').removeClass('curr').css('z-index','2').css('opacity',0);
		$('#h_bi_'+id).css('z-index','1').addClass('curr').css('opacity',1);
		$('.hf_link').removeClass('curr');
		$('#hf_link_'+id).addClass('curr');
		*/
		$('#h_bi_'+id).css('z-index','1').addClass('curr').css('opacity',1);
		$('.hf_link').removeClass('curr');
		$('#hf_link_'+id).addClass('curr');
		$('#h_bi_'+id_prev).css('z-index','2').animate({opacity: 0}, 500, function() {
			$(this).removeClass('curr');
			
		});
		
	}



}
function hideFeatured(id){
	id_curr = id;
	iTimer = setTimeout("showFeatured()", gal_delay);

}

function doLoad() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		//map.setCenter(centerPoint, 16);
		map.addControl(new GScaleControl());
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
	}
}

function addMarkers() {
	if (mArray.length) {
		var bounds = new GLatLngBounds();
		for (n=0 ; n < mArray.length ; n++ ) {
			var mData = mArray[n].split(';');
			var point = new GLatLng(mData[0],mData[1]);
			bounds.extend(point);
			var marker = createMarker(point, mData[2]);
				
			map.addOverlay(marker);
			//map.openExtInfoWindow(point,
               //           '<div style="width:100px;font-size:0.8em;">' + mData[2]+  '</div>');
		   map.openInfoWindow(point,
				'<div style="width:170px;font-size:0.8em;">' + mData[2]+  '</div>', {maxWidth:150});
		}
		map.setCenter(bounds.getCenter(), 13/*map.getBoundsZoomLevel(bounds)*/); 
	}
}
	
function createMarker(point, title) {
	var marker = new GMarker(point,{title:title});
	GEvent.addListener(marker, "click", function() {
	marker.openInfoWindow(
		'<div style="width:100px;font-size:0.8em;">' + title+  '</div>',{maxWidth:150});
	});
	return marker;
}

$(function() {
	inputPlaceholder(document.getElementById('sp_input'),'#6d6d6d');
	//initialize cross-browser HTML-Video-Tag
	$('video, audio').jmeEmbed();

	
	$(".overlay[rel]").overlay({
			/*close: '.close',*/
			top: 60,
			mask: {
				color: '#000',
				loadSpeed: 200,
				opacity: 0.7
			},
			fixed: false,
			onBeforeLoad: function() {
				window.scrollTo(0,0);
				// clear all messages
				//this.getOverlay().find(".over_message").html('');
			}
			/*closeOnClick: false,*/
			/*effect: "apple"*/
	});
	
	
	$(".fancybox").fancybox({
		overlayShow	: true,
		overlayOpacity: 0.8,
		padding: 0,
		margin: 0
	});
	
	$('#fancybox-img, .fg_thumb, #gallery_image a').live("contextmenu",function(e){
		var alert_text = '';
		if (typeof user_logged === "undefined") {
			alert_text = '<div>Our images are provided free of charge, <a href="/registration.html" style="text-decoration:underline;">sign up now</a> to download high resolution images</div>';
			//alert_text = '<div><a class="overlay" href="javascript://" rel="#over_login"  style="text-decoration:underline;">Login</a> or <a href="/registration.html" style="text-decoration:underline;">register</a> to download hi-resolution images</div>';
		} else {
			alert_text = '<div>Please click the "Download High Res" button below this image</div>';
		}
		$.fancybox(
			alert_text,
			{
				'padding'		: 20,
				'autoScale'		: false,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none',
				'width'		: 150
			}
		);
		return false;
	});
	
});
