/*----------------------------------------------------

	JSONLOAD.JS

----------------------------------------------------*/

$(document).ready(function(){

	var bodyid = $('body').attr('id');
	
	// A. Close Response Messages
	//------------------------------------------------------------------------------------------

	$('#msg_response').bind("click", function(){
		if($('#msg_response').is(':visible')){
			$("#msg_response").slideUp();
		}
	});
	
	// B. Google Maps
	//------------------------------------------------------------------------------------------
	if(bodyid == 'location'){
		$('#banner').html('<div id="map"></div>');
		googlemap();
		$('body').attr('onunload','GUnload()');
	}
	
	// C. Tab Lists
	//------------------------------------------------------------------------------------------

	$('.section').hide(); 
	$('#location .section:first').show(); 
	$('#tab_links li:first a').addClass('current');
	$('#tab_links li a').bind('click', toggleSideTabs);

	// D. Initiate Colorbox
	//------------------------------------------------------------------------------------------
	
	if(bodyid == 'gallery'){
		$(".colorbox").colorbox();
	}


});


// 01. toggleInputbox
//------------------------------------------------------------------------------------------

function toggleInputbox(id,text,userevent){

	var obj = document.getElementById(id);
	if(obj.value == text && userevent != "blur"){
		obj.value = "";
		obj.className = obj.className + " input_box_active";
	}else if(obj.value == text){
		obj.className = obj.className.replace("input_box_active","");
	}else if(trim(obj.value) == ""){
		obj.value = text;
		obj.className = obj.className.replace("input_box_active","");
	}else{
		obj.value = trim(obj.value);
	}
	
}

// 02. trim
//------------------------------------------------------------------------------------------

function trim(str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}

// 03. googlemap
//------------------------------------------------------------------------------------------

function googlemap(){
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map"));
      	map.setCenter(new GLatLng(54.18717, -1.6647), 12);
		var point = new GLatLng(54.18717, -1.6647);
		map.addOverlay(new GMarker(point));
		
		map.addControl(new GMapTypeControl());
		//map.addControl(mapControl);
		map.addControl(new GLargeMapControl3D());
		map.addControl(new GOverviewMapControl());
		map.addMapType(G_PHYSICAL_MAP)
	}
}

// 03. toggleSideTabs
//------------------------------------------------------------------------------------------

function toggleSideTabs(){
	
	var id = $(this).attr('id');
	id = id.replace("tab_","");
	$('.section').hide(); 
	$('#'+id).show();
	$('#tab_links li a').removeClass('current');
	$(this).addClass('current');

}