/*----------------------------------------------------

	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. Bounce
	//------------------------------------------------------------------------------------------
	
	if(bodyid == "index"){
		$("#services li").hover(function(){
		  $(this).animate({ 
			marginTop: "-10px"
		  }, 500 );
		},
		function(){
		$(this).animate({ 
			marginTop: "3px"
		  }, 300 );
		$(this).animate({ 
			marginTop: "0px"
		  }, 300 );
		});
	}
		
	// C. Google Maps
	//------------------------------------------------------------------------------------------
	if(bodyid == 'location'){
		//$('#banner').html('<div id="map"></div>');
		googlemap();
		$('body').attr('onunload','GUnload()');
	}

	// D. People
	//------------------------------------------------------------------------------------------

	if(bodyid == 'meet-our-people'){
		$('.people div').hide();
		$('.people div').each(function(){
			$(this).before('<a>Read more about '+ $(this).siblings('h3').html() +'</a>');
		});
		$('.people a').bind("click", function(){
			if($(this).siblings('div').is(':visible')){
				$(this).siblings('div').slideUp();
				$(this).html('Read more about '+ $(this).siblings('h3').html());
			}else{
				$(this).siblings('div').slideDown();
				var str = $(this).siblings('h3').html();
				str.substring(0, str.length - 1);
				if(str.substring(str.length - 1, str.length) == 's'){
					$(this).html("Hide "+ $(this).siblings('h3').html() +"' profile");
				}else{
					$(this).html("Hide "+ $(this).siblings('h3').html() +"'s profile");
				}
			}
		});
	}
	
	// G. Rental Tabs
	//------------------------------------------------------------------------------------------	

	var foo = jQuery('#tab_container').children().map(function(){return jQuery(this).attr('title');}).get();
	$('#tab_container').prepend('<ul id="tab_navigation"></ul>');
	$.each(foo, function(intIndex, objValue){
		$('#tab_navigation').append($( '<li><a>' + objValue + '</a></li>' ));
 	});
	$('#tab_navigation li:first-child').addClass('current');
	$('#tab_container > div').hide();
	$('#tab_container > div:first').show();
	
	$('#tab_navigation li a').bind('click', function(){
		var current = $(this).html();
		$('.current').removeClass('current');
		$(this).parent().addClass('current');
		$('#tab_container > div').hide();
		$('#tab_container > div[title="'+current+'"]').show();
	});

});


// 01. toggleInputbox
//------------------------------------------------------------------------------------------

function toggleInputbox(id,text,userevent){

	var obj = document.getElementById(id);
	if(obj.value == text && userevent != "blur"){
		obj.value = "";
		$('#'+id).addClass("active");
	}else if(obj.value == text){
		$('#'+id).removeClass("active");
	}else if(trim(obj.value) == ""){
		obj.value = text;
		$('#'+id).removeClass("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("ripon-map"));
      	map.setCenter(new GLatLng(54.13637, -1.52543), 14);
		var point = new GLatLng(54.13637, -1.52543);
		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)
	}
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("bedale-map"));
      	map.setCenter(new GLatLng(54.28787, -1.59066), 14);
		var point = new GLatLng(54.28787, -1.59066);
		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)
	}
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("thirsk-map"));
      	map.setCenter(new GLatLng(54.23205, -1.34308), 14);
		var point = new GLatLng(54.23205, -1.34308);
		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)
	}
}