/*

	ALL JOBS PLUS GLOBAL JAVASCRIPT

*/
$(document).ready(function() {
	
	/*
		TABS
	*/
	$('#tabs').Accordion({ 
		animated: false 
	}).activate(2);
	
	
	/*
		QUOTE
	*/
	$('blockquote #quote-holder, #quote-text-holder').cycle({ 
		fx:    'fade', 
		speed:  5000 
	 });
	
	
	/*
		FLASH TEXT REPLACE
	*/

	//H1
	$('h1').flashText({ 
		src: '/Common/flash/swfs/helveticaNeueCondensedBold.swf'
    });
	
	//Intro text
	$('#intro-text').flashText({ 
        src: '/Common/flash/swfs/helveticaNeueCondensed.swf'
    });
	
	//Side bar login
	$('#content #sub form#login-form fieldset h2.legend').flashText({ 
        src: '/Common/flash/swfs/helveticaNeueCondensedBold.swf'
    });
	
	//H2
	$('h2').flashText({ 
        src: '/Common/flash/swfs/helveticaNeueCondensed.swf'
    });
	
	//Side bar block quote
	$('#content #sub blockquote p').flashText({ 
        src: '/Common/flash/swfs/helvetica95BlackForcedSpaces.swf'
    });
	
	
	/*
		CONTACT FORM MAP
	*/
	$('a.show-map').click(function() {
		
		var $googleMapURL = $(this).attr('href');
		
		$.extend($.blockUI.defaults.overlayCSS, { backgroundColor: '#4B3B46', opacity: '0.7' });
		$.extend($.blockUI.defaults.pageMessageCSS = { border: '4px solid #4B3B46', width: '700px', height: '500px', marginLeft: '-350px', marginTop: '-250px', top:'50%', left:'50%' });
		
		//check if we are in the footscray office
		//if we are use the google maps api
		if($(this).attr('id') == 'footscray-link'){
			$.blockUI('<div id="footscray-office" style="width: 700px; height: 500px;"></div><a href="'+$googleMapURL+'" style="color:#FFF; font-weight: bold; padding-top: 20px; display: block; background: transparent; outline: none;" target="_blank">View Larger Map</a>');
			googleMapAPI();
		//else insert an iframe with the map in it
		} else {
			$.blockUI('<iframe width="700" height="500" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'+$googleMapURL+'"></iframe><a href="'+$googleMapURL+'" style="color:#FFF; font-weight: bold; padding-top: 20px; display: block; background: transparent; outline: none;" target="_blank">View Larger Map</a>');
		}
		
		$('div.blockUI').css({ cursor: 'pointer' });
		
		$('div.blockUI:not(.blockMsg)').attr('title','Click to close').click(function() {
			$.unblockUI();
		});
		
		return false;
	});
	
	
	function googleMapAPI() {      
		if (GBrowserIsCompatible()) {    
			//add map
			var map = new GMap2(document.getElementById('footscray-office'));    
			map.setCenter(new GLatLng(-37.804083,144.897424), 14);  
			//add marker
			var point = new GLatLng(-37.804083,144.897424)
			map.addOverlay(new GMarker(point));   	   
			//map controls
			map.addControl(new GMapTypeControl);
			map.addControl(new GLargeMapControl());
		}   
	} 
	
	
	/*
		CONTACT DETAILS
	*/
	$('.contact-extra-details').hide(); //hide what needs to be hidden
	$('.contact-extra-details').parent().parent().css('min-height','70px'); //set a min-height on the parent div to make the spacing look good for IE
	$('a.more-details').click(function(){
		var $sectionId = $(this).attr('href'); //grab the anchor tag to work out the appropriate ID to show / hide
		$(this).toggleClass('more-details-up');
		//deal with the text
		$('a.more-details').text('More details');
		$(this).text('Less details');
		//slide  up the current item if it is open
		if($($sectionId).is(':visible')) {
			$($sectionId).slideUp('slow');
			$('a.more-details').text('More details'); //change the text too
		} else {
			$('.contact-extra-details').slideUp('slow');
			$($sectionId).slideDown('slow');
		}
		return false;
	});
	
	
	
	/*
		CONTACT FORM
	*/
	//vars
	var $theForm = $('#contactform'); //Make sure we are using the right form
	var animationSpeed = 1500;
	
	function hideAllFormItems(){
		$theForm.find('.choose-type .radios-form-item input').removeClass('active');
		$theForm.find('.form-item:not(.always-show)').not('.buttons-form-item').hide();
		$theForm.find('fieldset').stop();
	}
	hideAllFormItems();
	
	//Contact by email
	$theForm.find('.choose-type .radios-form-item input:eq(0)').click(function(){
		if(!$(this).is('.active')){											  
			hideAllFormItems();
			$theForm.find('.error').hide();
			$theForm.find('.emailFields').fadeIn('slow');
			$(this).toggleClass('active');
			$theForm.find('fieldset').css('backgroundColor','#F7F5DE').animate({ backgroundColor: '#FFF' }, animationSpeed);
		}
	});
	
	//Contact by phone
	$theForm.find('.choose-type .radios-form-item input:eq(1)').click(function(){
		if(!$(this).is('.active')){
			hideAllFormItems();
			$theForm.find('.error').hide();
			$theForm.find('.phoneFields').fadeIn('slow');
			$(this).toggleClass('active');
			$theForm.find('fieldset').css('backgroundColor','#F7F5DE').animate({ backgroundColor: '#FFF' }, animationSpeed);
		}
	});
	
	//Contact by post
	$theForm.find('.choose-type .radios-form-item input:eq(2)').click(function(){
		if(!$(this).is('.active')){
			hideAllFormItems();
			$theForm.find('.error').hide();
			$theForm.find('.postFields').fadeIn('slow');
			$(this).toggleClass('active');
			$theForm.find('fieldset').css('backgroundColor','#F7F5DE').animate({ backgroundColor: '#FFF' }, animationSpeed);
		}
	});
	
	//find the selected element and make sure it is shown
	$theForm.find('.choose-type .radios-form-item input:checked').click();
	$theForm.find('.error').show();
	
	
	/*
		Feedback link, refering page title
	*/
	var pageTitle = escape(window.document.title);
	var $feedbackLink = $('#header-links li.last a');
	var $feedbackLinkHref = $feedbackLink.attr('href');

	if ((pageTitle != '') && (pageTitle != null)) {
		$feedbackLink.attr('href', $feedbackLinkHref+'?title='+pageTitle);
	}
	
	
});