$(function() {
	
	// Logo
	$('h1#logo').hover(function() {
		$(this).css({ cursor: 'pointer' });
	}).click(function() {
		window.location = '/';
	});

	// XHTML-S Popups
	$('a[rel="external"]').click(function() {
		window.open(this.href);
		return false;
	});
	
	$('#product_finder').change(function() {
		$redirect_links = location.protocol + '//' + location.host + $(this).val();
		window.location = $redirect_links;
		return;
	});
	
	// Login Form
	$password_switch = function() {
		
		$new_input = $(this).clone().val('').attr('type', 'password').bind('blur', function() {
			if($(this).val() == '') {
				$(this).replaceWith($(this).clone().val('Password').attr('type', 'text').bind('focus', $password_switch));
			}
		});
		
		$(this).replaceWith($new_input);
		$new_input.focus();
	}
	
	$('#assessor_password').focus($password_switch);
	$('#assessor_username').focus(function() {
		if($(this).val() == 'Username') {
			$(this).val('');
		}
	}).blur(function() {
		if($(this).val() == '') {
			$(this).val('Username');
		}
	});
	
	var $timeout;
	
	// Dropdown Menu
	$('.element-product-catalogue a').mouseenter(function() {
		clearTimeout($timeout);
		$dropdown_menu = $(this).parent().find('ul');
		$dropdown_menu.not(':animated').slideDown({ queue: false, duration: 200, easing: 'easeOutQuad' });
	});
	
	$('.element-product-catalogue').mouseleave(function() {
		$dropdown_menu = $(this).find('ul.sub-nav');
		$timeout = setTimeout(function() { $dropdown_menu.not(':animated').slideUp({ queue: false, duration: 150, easing: 'easeInQuad' }); }, 500);
	});
	
	// Carousel
	$('#product-carousel').jac({
		childFixedSize: true
	});
	
	$('form .row.required label').append('<span>*</span>');
	$('form #captcha_link').click(function() { $(this).parent().find('input').focus(); });
	
	Cufon.replace('.vag-light, .custom-page-content h2, .home-page-content h2', { fontFamily: 'VAGLight', hover: true });
	Cufon.replace('.vag-light-shadow', { fontFamily: 'VAGLight' });
});
