$(document).ready(
function()
{
$('#toplogohost a.menu.about').hover(function() { $('#toplogo').attr('src', imgroot + 'toplogo_state1.gif'); }, function() { $('#toplogo').attr('src', imgroot + 'toplogo.gif'); });
$('#toplogohost a.menu.about').click(function() { $('#panevideo').children().remove(); $('#toplogohost').animate({'left' : '-20px'}); $('#header').animate({'height' : '270px'}); return false; });
$('#toplogohost a.menu.video').hover(function() { $('#toplogo').attr('src', imgroot + 'toplogo_state2.gif'); }, function() { $('#toplogo').attr('src', imgroot + 'toplogo.gif'); });
$('#toplogohost a.menu.video').click(function() { $('#toplogohost').animate({'left' : '370px'}, 'normal', 'linear',
	function() {
		$('#panevideo').append('<object width="350" height="200">	<param name="allowfullscreen" value="true" />	<param name="allowscriptaccess" value="always" />	<param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=1925571&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" />	<embed src="http://vimeo.com/moogaloop.swf?clip_id=1925571&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="350" height="200"></embed></object><div>[<a href="#" class="returnheader">close</a>]</div>');
		$('#panevideo a.returnheader').click(function() { $('#panevideo').children().remove(); $('#toplogohost').animate({'left' : '170px'}); $('#header').animate({'height' : '240px'}); return false; });
	}); $('#header').animate({'height' : '300px'}); return false; });
$('#toplogohost a.menu').hover(function() { $(this).children('span.title').fadeIn(); }, function() { $(this).children('span.title').fadeOut(); });
var curr = null;
$('#toplogohost a.menu, #toplogohost a.returnheader').click(function() { curr = this; $("#toplogohost a.menu").parent().contents('a.menu').not(this).next('.pane').fadeOut('fast', function() { $(curr).next('.pane').fadeIn('slow'); }); });

$('#toplogohost a.returnheader').click(function() { $('#toplogohost').animate({'left' : '170px'}); $('#header').animate({'height' : '240px'}); return false; });

var host;
var src;
var dest;
var clicked;
var img;

	$('ul.thumbs a').click(
		function()
		{
			host = $(this).parents('div.agrealhost').find('div.aghost');
			src = host.find('img.feature');
			
			img = new Image();
			$(img).load(
			function()
			{
				$(this).addClass('feature');
				host.find('.agbig img.feature').replaceWith(this);
				$(this).hide();
				host.animate({'height' : ($(this).height() + 20) + 'px'});
				if ($(this).height() > $(this).width())
				{
					$(this).css('left', (40 + Math.round((host.width() / 2) - ($(this).width() / 2))) + 'px');
				}
				else { $(this).css('left', '40px'); }
				$(this).fadeIn('def');
				host.find('.agbig').removeClass('preload');
				if ($(window).scrollTop() > host.position().top || ($(window).scrollTop() + $(window).height()) < (host.position().top + 80 + $(img).height()+20))
				{
					$.scrollTo(host.position().top-30, 200);
				}
			});
			
			clicked = $(this);
			host.find('.agbig').addClass('preload');
			src.fadeOut('def', function() { $(img).attr('src', clicked.attr('href')); });

			$(this).siblings().removeClass('selected');
			$(this).addClass('selected');

			return false;
		});
	
	$('.action a').click(function() { var action = $(this).parents('.action'); action.fadeOut('def', function() { action.prev('.commentform').fadeIn(); }); return false; });

	$('img.feature.off').fadeOut('fast');
	$('div.aghost').each(
		function() 
		{
			if ($(this).find('img.feature:not(.off)').height() > 0)
			{
				$(this).css('height', ($(this).find('img.feature:not(.off)').height() + 20) + 'px');
			}
			dest = $(this).find('img.feature:not(.off)');
			if (dest.height() > dest.width())
			{
				dest.css('left', (40 + Math.round(($(this).width() / 2) - (dest.width() / 2))) + 'px');
			}
			else
			{
				dest.css('left', '40px');
			}
		}
	);

	$('#search input').focus(function() { if (this.value == 'Search now!') { this.value = ''; $(this).css('color', '#333'); } });
	$('#search input').blur(function() { if (this.value == '') { this.value = 'Search now!'; $(this).css('color', '#aaa'); } });
});
