var addthis_config =
{
	data_use_flash: false
};


$ = jQuery;

$(document).ready(function(){
	ui.initialse();
});

var ui = 
{
	max_col_height: 0,

	ie6: ($.browser.msie && parseInt($.browser.version) == 6),

	initialse: function()
	{
		this.set_up_equal_height_columns();
		//this.set_up_radios_and_checkboxes();
		this.clear_and_recall('#full_name, #email_address, #s');
		this.mail_to_hyperlinks();
	},
	
	// Make sure the left and right columns stretch
	// to the height of the main content
	set_up_equal_height_columns: function()
	{
		var self = this;
		
		$(window).load(function()
		{			
			$('#middle .layout_column').each(function()
			{
				if ($(this).height() > self.max_col_height)
				{
					self.max_col_height = $(this).height();
				}
			});
			
			$('#middle .layout_column:not(.centre)').css(
			{
				'height':	self.max_col_height
			});
		});
	},
	
	// Mimic checking/unchecking of radios/checkboxes
	// using some images.
	set_up_radios_and_checkboxes: function()
	{
		if (this.ie6) return;
	
		$('input[type=radio], input[type=checkbox]').each(function()
		{
			var input = $(this);
			var label = input.next('label');
			input.hide();
			label.prepend('<span class="ir radio_button"></span>');
			var do_click = function()
			{
				label.children('span:first').toggleClass('on', input.attr('checked'));
			};
			input.click(do_click);
			do_click();
		});
		
	},
	
	// Clear text box value on click
	// Restore original value on blur	
	clear_and_recall: function(elements)
	{
		$(elements).each(function()
		{
			var field = $(this);
			var initial_value = field.val();
		
			field.click(function()
			{
				if ($(this).val() == initial_value) $(this).val('');
			});
			field.blur(function()
			{
				if (!$(this).val()) $(this).val(initial_value);
			});
		});
	},
	
	// Generate mailto hyperlinks
	// Convert " at " to "@" and " dot " to "
	mail_to_hyperlinks: function()
	{
		$('.email').each(function()
		{
			var email = $(this).text().replace(/ at /, '@').replace(/ dot /g, '.');
			$(this).html('<a href="mailto:'+email+'">'+email+'</a>');
		});
	}
};



$(function(){

    var config = { 
    	sensitivity: 5, // number = sensitivity threshold (must be 1 or higher)    
        interval: 200,  // number = milliseconds for onMouseOver polling interval    
        over: doOpen,   // function = onMouseOver callback (REQUIRED)    
        timeout: 200,   // number = milliseconds delay before onMouseOut    
        out: doClose    // function = onMouseOut callback (REQUIRED)    
    };
    
    function doOpen() {
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
       // alert($('ul:first',this).html());
    }
 
    function doClose() {
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');
    }

    $("ul.dropdown li").hoverIntent(config);
    
    $("ul.dropdown li ul li:has(ul)").find("a:first");//.append(" &raquo; ");

});


$(document).ready(function(){
	$('dt.gallery-icon a').colorbox();
});

