$(document).ready(function(){
	//menu hover
	$("#menu li").hover(
		function(){
			$(this).addClass('hover');
			$(this).children('.sub').toggle();
		}, 
		function(){
			$(this).removeAttr('class');
			$(this).children('.sub').toggle();
		}
	)
	
	//sub menu hover
	$(".sub li").hover(
		function(){
			$(this).addClass('hover');
			$(this).children('.subsub').toggle();
		}, 
		function(){
			$(this).removeAttr('class');
			$(this).children('.subsub').toggle();
		}
	)
	
	$('a').bind('click', function(){
		$(this).blur();
	})
	
	//h1 text color changing
	$('#content-wrapper h1').each(function(){
		text = $(this).text();
		found = text.indexOf(' ');
		
		if(found != -1){
			end = text.substring((found + 1), text.length);
			
			$(this).highlight(end);
		}
	})
	
	//funds our people select
	$('#our-people-wrapper select').bind('change', function(){
		$('#form').submit();
	})
	
	//our people read more
	$('#our-people-wrapper tr').each(function(i){
		if((i % 4) == 1){
			$(this).children('td').addClass('hide-copy');
			$(this).children('td').attr('id', 'copy' + i);
		}
		
		if((i % 4) == 2){
			$(this).children('td').append('<a href="#copy' + i + '" class="more show' + (i - 1) + '">read more</a>').css('padding', '5px 0 5px 0');
			
			$(this).children('td').attr('class', 'read-more-block');
			
			$('.show' + (i - 1)).bind('click',
				{id: (i - 1)},
				
				function(event){
					$('#copy' + event.data.id).css('width', '0').show();
					$(this).css('display', 'none');
				}
			);
		}
		
		if((i % 4) == 3){
			$(this).children('td').css('height', '20px').addClass('seperator');
		}
	})
	
	$('#our-people-wrapper').css('display', 'block');
	
	$('#slideshow ul').billy({
		transition: 'fade',
		slidePause: 5000,
		indicators: $('#fade_indicators')
	})
	
	
	$('#toAddress').attr('disabled', true);
	
	var fromAdd = $("#fromAddress").val();
	var toAdd = $("#toAddress").val();
	var slcLang = $("#locale").val();
	
	$.fn.gMap(fromAdd,toAdd,slcLang);
	
	
	$('#getDirections').bind('mouseup',function(event){
		var fromAdd = $("#fromAddress").val();
		var toAdd = $("#toAddress").val();
		var slcLang = $("#locale").val();
		
		if(fromAdd==""){
			alert("Please enter a From location.");
		} else {		
			$.fn.gMap(fromAdd,toAdd,slcLang);
		}
	})
	
	if($('h2').html() == 'Log In'){
		$('#content-block h2').hide();
		$('#content-block li').css('list-style', 'none');
		$('#wp-submit1').attr('value', 'Submit');
	}
})

$.fn.gMap = function(strFrom,strTo,strLanguage){
	if($('#map-canvas').text() != ''){
		var map;
		var gdir;
		var geocoder = null;
		var addressMarker;
		
		$('#map-canvas').text('');
		$('#map-directions').text('');
		
		map = new GMap2(document.getElementById("map-canvas"));
		map.addControl(new GSmallMapControl());
		
		gdir = new GDirections(map, document.getElementById("map-directions"));
		gdir.load('from: '+strFrom+' to: '+strTo, {'locale': strLanguage});
		
		//google street view
		$('#street-view-canvas').text('');
		var streetView = new GLatLng(-26.115018,28.053552);
		driverPOV = {yaw:380,pitch:10};
		panoramaOptions = { latlng:streetView, pov:driverPOV };
		var myPano = new GStreetviewPanorama(document.getElementById('street-view-canvas'), panoramaOptions);
	}
}
