/*TABLE OF CONTENTS for init.js
--------------------------------------------
- Site search default value
- Printer friendly
- Cufon replace introduction text
- Hover state for ie6
- First child for ie6
- Fade linked images on hover
- Equal heights of columns
- Animate back to top link
- Default value for What's news if no current events
*/
$(document).ready(function() {	

	//Site search default value
	$('#search .search-background input[type=text]').defaultValue('Enter keyword');

	//Printer friendly
	$('#content-main').prepend('<a id="printer-friendly" title="Printer Friendly" href="#">Printer Friendly</a>');
	$('#printer-friendly').click(function() {
		window.print();
		return false;
	});
	//Cufon replace introduction text
	Cufon.replace('#introduction h3');
    
	//Hover state for ie6
	$("#navigation-main ul li").hover(
	  function () {
		$(this).addClass("hover");
	  },
	  function () {
		$(this).removeClass("hover");
	  }
	);
	$("div.important").hover(
	  function () {
		$(this).addClass("hover");
	  },
	  function () {
		$(this).removeClass("hover");
	  }
	);
	
	//First child for ie6
	$("#navigation-main ul ul li:first-child").addClass("first-child");
	$("#whats-new .panel ul li:first-child").addClass("first-child");
	
	// Fade linked images on hover
	 var imageLinks = $("#panel-quicklinks a img");
	 imageLinks.hover(
	  function() {
	   $(this)
		.stop(true, true)
		.fadeTo('fast', 0.8);
	  },
	  function() {
	   $(this)
		.stop(true, true)
		.fadeTo('fast', 1)
	  }
	 );
	 
	//Equal heights of columns
	function equalHeight(group) {
	tallest = 0;
	group.each(function() {
	thisHeight = $(this).height();
	if(thisHeight > tallest) {
		tallest = thisHeight;
		}
	});
	group.height(tallest);
	}
	$("#whats-new .panel").addClass("equal-height");
	$("#latest-news .panel").addClass("equal-height");
	equalHeight($(".equal-height"));
	
	//Animate back to top link
	$('.back-to-top a').click(function(){
     $('html, body').animate({scrollTop: '0px'}, 1000);
     return false;
	});
	
	//Default value for What's news if no current events
	if ( $('#whats-new ul').children().size() == 0 ) {
		$('#whats-new div.important').remove();
		$('#whats-new ul').remove();
		$('.ezjax').ezjax({	
					container: '#whats-new div.panel',
					initial: 'http://www.australianoilseeds.com/home_v2/whats_new_-_no_events/'
		});
	}


});
