var site = {};

site.base =
{
	initialised : false,

	init : function()
	{
		if (this.initialised === true)
			return true;

		//Code here etc
		this.setup_hooks();

		this.initialised = true;

		return true;
	},

	setup_hooks : function()
	{
		this.setup_contact_form();
		this.setup_newsletter_form();
		this.setup_accordion();
		return true;
	},

	setup_contact_form : function()
	{
		$("form input[type='text'], form textarea").live("focus", function()
		{
			if ($(this).val() == site.base.get_original_contact_value($(this).attr("id")))
			$(this).val("");
		});
		$("form input[type='text'], form textarea").live("blur", function()
		{
			if (jQuery.trim($(this).val()) == "")
			$(this).val(site.base.get_original_contact_value($(this).attr("id")));
		});
		$("form .error + input + .input").css('border-color', $(".error").eq(0).css('color'));
	},

	setup_newsletter_form : function()
	{
		$("#newsletter form").live("submit", function()
		{
			$.post("newsletter", $(this).serialize(), function(data)
			{
				$("#newsletter").parent().html(data);
			});
			return false;
		});
	},

	get_original_contact_value : function(field)
	{
		orig_field = "#" + field + "_default";
		return $(orig_field).val();
	},

	setup_accordion : function() {
		var get = this.getUrlVars();
		var select = 0;

		if (get["select"]) {
			select = parseInt(get["select"]);
		}

		$(".accordion").accordion({header: ".header", autoHeight: false, active: select});
	},

	getUrlVars : function() 
	{
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

		for(var i = 0; i < hashes.length; i++) 
		{
			hash = hashes[i].split('=');
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		}

		return vars;
	}
};


//Dom ready
$(document).ready(function(){
	site.base.init();
    

    $('.outside-link').bind('click', function() 
    {
        window.open($(this).attr("href"));
        return false;
    });

   
});

