$(document).ready(function(){


	$("a[rel*=external]").attr('target','_blank');

	$('.contrast').click(function(){
		$('body').toggleClass('hiContrast');
		return false;
	});

	$('.printer').click(function(){
		window.print();
		return false;
	});

	$('a.confirm').click(function() {
	    var answer = confirm("Are you sure you want to delete this item?")
	    if (answer){
	        return true;
	    } else {
	        return false;
	    };
	});
	
	$('li:first-child').addClass('first');
	$('li:last-child').addClass('last');
	
	$('#searchfield').labelsInInputs({
		top: '4px',
		left: '13px',
		color : '#999',
		blur_color: '#DDD',
		font_size : '1em'
	});
	
	// claim form
	
	if($('#country option:selected').text() != 'Australia (+61)') {
		$('#state-box').hide();
	}

	$('#country').change(function() {
		if($('option:selected', this).text() != 'Australia (+61)') {
			$('#state-box').slideUp();
			$('input#which-state').attr('value', 'N/A');
		} else {
			$('#state-box').slideDown();
			$('input#which-state').attr('value', '');
		}
	});


	// menus
	$('#top-nav ul#primary').superfish({
			animation: {height:'show'},
			speed: 'slow',
			delay: 1200
	});
	
	
	$('div#top-nav ul#secondary li:last-child').css({'border' : 'none'});
	$('div#footer div#footer-nav ul li').prepend('&raquo; ');

	// transparent menus for decent browsers
	if(!$.browser.msie){
    	$('body#home div#top-nav ul#primary ul').css({'background' : 'rgba(193,0,34,.95)'});
	} else {
		$('body#make-a-claim-lp div#top-nav ul#primary ul').remove();
		$('body#video-lp div#top-nav ul#primary ul').remove();
		$('div#main div.main-split:last-child').css({'background' : '#F7F7F7', 'margin-right' : '0'});
	}

	// fancybox
	$("a#viewlarge").fancybox({
		'frameWidth':  560,	
		'frameHeight': 340,
		'zoomSpeedIn': 50,
		'zoomSpeedOut':	50,
		'overlayColor': '#000',
		'overlayOpacity': .9,
		'enableEscapeButton': true
	});
	
	// innerfade
	$('div#ticker ul').innerfade({
		timeout : 8000
	});


	$('p#p-death-date span.jq-replace').replaceWith('<input type="text" name="death-date" id="death-date" />');
	$('p#p-grant-date span.jq-replace').replaceWith('<input type="text" name="grant-date" id="grant-date" />');
	$('#death-date, #grant-date').datepicker({dateFormat: 'dd/mm/yy'});
	
	$('div#main h3:first').css({'border' : 'none', 'padding-top' : '0'});
	


	// activate certain form elements according to
	// what user selects	
	$('p#p-legal-specify, p#p-specify').hide();
	$('#legal-yes').click(function () {
		if ( $(this).is(':checked') ) { 
			$('p#p-legal-specify').show();
		} else {
			$('p#p-legal-specify').hide();
		}
	});
	$('#legal-no').click(function () {
		if ( $(this).is(':checked') ) { 
			$('p#p-legal-specify').hide();
		} else {
			$('p#p-legal-specify').show();
		}
	});
	
	$('#hear').change(function () {
		var heard = $('#hear').val();
			if( (heard == 'Other Lawyer') || (heard == 'TV') ) {
				$('p#p-specify').show();
			} else {
				$('p#p-specify').hide();
			}
	});

	
	$('div#expand-info').hide();
	
	var expand_text = $('p#expand-box').text();
	
	$('p#expand-box').toggle(
		function() {
			$('div#expand-info').slideDown(1100, function() {
				$('p#expand-box').text('Click here to hide this information');
			});
		},
		function() {
			$('div#expand-info').slideUp(500, function () {
				$('p#expand-box').text(expand_text);
			});
			
		}	
	);

	$('#main form').submit(function() {
		$('button', this).css({'background' : 'url(' + WWWROOT + 'images/sending.gif) top left no-repeat'}).attr('disabled', 'disabled');
	}).after('<div style="display:none"><img src="'+ WWWROOT + 'images/sending.gif' + '"></div>'); //<-- hack to preload image

	$('#home #deco h1 a').append('<span id="cta" style="">Contact Us Now!</span>').hover(
		function() {
			$('span', this).animate({left: '200px'});
		},
		function() {
			$('span', this).animate({left: '707px'});		
		}
	);


});






