$(document).ready(function() {

	// separated this into functions so it's better organised
	buttons();
	loginform();
	testimonials();
	portfolio();
	headerlogo();

});

function buttons()
{
	$buttons = $('#navigation li a');

	$buttons.append('<span class="hover"></span>').css('zoom', 1);

	if($.browser.msie && $.browser.version >= 7)
	{
		$buttons.each(function() {
			$hover_element = $('.hover', this);
			$hover_element.stop().animate({'opacity': 0.00001}, 1);
			setTimeout(function() { $hover_element.stop().animate({'opacity': 0}, 1); }, 10);
		});
	}

	$buttons.hover(function()
	{
		$('.hover', this).stop().animate(
		{
			'opacity': 1
		}, 200)
	},function()
	{
		$('.hover', this).stop().animate(
		{
			'opacity': 0
		}, 200)
	});
}

function loginform()
{
	$('div#header_login input').focus(function() {
		$this = $(this);

		$this.removeClass('inactive');

		if($this.attr('value') == 'Email Address' || $this.attr('value') == 'xxxxxxxx')
		{
			$this.attr('value', '');
		}
	});

	$('div#header_login input').blur(function() {
		$this = $(this);

		if($this.attr('value') == '' && $this.attr('type') == 'text')
		{
			$this.attr('value', 'E-mail Address').addClass('inactive');
		}
	});
}

function testimonials()
{
	$('div#t_images').popeye();
}

function portfolio()
{
	$('div#portfolio_images').cycle({
		fx: 'fade',
		speed: 600,
		next: '#portfolio_button_next',
		prev: '#portfolio_button_prev',
		before: function() {
			$('span#portfolio_current').fadeOut(600);
		},
		after: function() {
			var link, href, id;
			id		= $(this).find('img').attr('id');
			href 	= 'http://' + id
			link 	= $('<a>').attr('href', href).attr('target', '_blank').html(id).addClass('nounderline');
			$('span#portfolio_current').fadeIn(100).html(link)
		}
	});
}

function headerlogo()
{
	$('div#header_logo').click(function() {
		document.location = 'index.php';
	}).css('cursor', 'pointer');
}