$(document).ready(function(){
	
	function vertAlign() {
		var img_height = $('a.sponsor_logo img').height();
		var frame_height = 240 - img_height;
		var margin = Math.round(frame_height / 2);
		$('a.sponsor_logo img').css('margin-top', margin);
	}
	vertAlign();
	
	function mainNav() {
		$('ul.main_nav_left li:not(ul.main_nav_left li ul li)').mouseover(function(){
			$(this).children("div.nav_menu").show();
			$('ul.main_nav_left li:not(ul.main_nav_left li ul li)').mouseleave(function(){
				$('div.nav_menu').hide();
			});
		});
	}
	mainNav();
	
	$('div.rotational').cycle({
		fx: 'fade'
	});

	$('div.sponsor_slides').cycle({
		fx: 'fade'
	});
	
    $('#newsletter-form input').labelify({
        text: 'label',
        labelledClass: 'labelled'
    });
    $('#newsletter-form label').hide();
	
	function animateClouds() {
		var vp_width = $(window).width();
		$('.clouds_1').css('background-position', '-509px 120px');
		$('.clouds_2').css('background-position', vp_width + 'px 170px');
		$('.clouds_3').css('background-position', '-709px 30px');
		$('div.clouds_1').animate({backgroundPosition: vp_width + 'px 120px'},40000, 'linear');
		$('div.clouds_2').animate({backgroundPosition: '-553px 170px'},50000, 'linear');
		$('div.clouds_3').animate({backgroundPosition: vp_width + 'px 30px'},60000, 'linear', function(){ animateClouds(); });
	}
	if (!$.browser.msie || ($.browser.msie && $.browser.version.substr(0,1)>7)) {
	  animateClouds();
	}
	
	$('#increase').click(function(evt){
		if ($('body').hasClass('font_decrease')) {
			$('body').removeClass('font_decrease');
		} else {
			$('body').addClass('font_increase');
		}
		evt.preventDefault();
	});
	$('#decrease').click(function(evt){
		if ($('body').hasClass('font_increase')) {
			$('body').removeClass('font_increase');
		} else {
			$('body').addClass('font_decrease');
		}
		evt.preventDefault();
	});

});

$(window).load(function(){
	function vertAlign() {
		var old_display = $(this).parent().css('display');
        $(this).parent().css('display', 'block');
		var img_height = $(this).height();
        $(this).parent().css('display', old_display);
		var frame_height = 240 - img_height;
		var margin = Math.round(frame_height / 2);
		$(this).css('margin-top', margin);
	}
    $('a.sponsor_logo img').each(vertAlign);
});
