
$.metadata.setType("attr", "validate");

$.extend($.validator.messages, { required: "Please choose an answer for this question." });

$.fn.clearForm = function() {
	return this.each(function() {
	var type = this.type, tag = this.tagName.toLowerCase();
	if (tag == 'form')
		return $(':input',this).clearForm();
	if (type == 'text' || type == 'password' || tag == 'textarea')
		this.value = '';
	else if (type == 'checkbox' || type == 'radio')
		this.checked = false;
	else if (tag == 'select')
		this.selectedIndex = -1;
  });
};

function homeSlideShow() {
	// Background "1" would be the default background of the containing div.
	// These are faded up over it...
	setTimeout(function(){$('#background-02').fadeIn(2000); },6000);
	setTimeout(function(){$('#background-03').fadeIn(2000); },12000);
	setTimeout(function(){$('#background-04').fadeIn(2000); },18000);
	setTimeout(function(){$('#background-05').fadeIn(2000); },24000);
	setTimeout(function(){$('#background-02,#background-03,#background-04').hide(); }, 26000); // Hide the first three slides
	setTimeout(function(){$('#background-05').fadeOut(2000); },30000);
	setTimeout(homeSlideShow,30000);
};

$(document).ready(function()
{  

	homeSlideShow();

	$('.external').attr('target','_blank');
	
	// FORM VALIDATIONS
	$("#quiz-form").validate({
		errorPlacement:function(error, element) {
			error.appendTo( element.parent("div"));
		}
	});
	
	
	
	// DROPDOWNS & CTA MENUS
   $('.sub-menu').each(function(){
		$(this).parent().eq(0).hoverIntent({
			timeout: 100,
			over: function(){
				var current = $('.sub-menu:eq(0)',this);
				current.slideDown(100);
			},
			out: function(){
				var current = $('.sub-menu:eq(0)',this);
				current.fadeOut(200);
			}
		});
	});

   $('.dropdown').each(function(){
		$(this).parent().eq(0).hoverIntent({
			timeout: 100,
			over: function(){
				var current = $('.dropdown:eq(0)',this);
				current.slideDown(100);
			},
			out: function(){
				var current = $('.dropdown:eq(0)',this);
				current.fadeOut(200);
			}
		});
	});
	
	$('#language-menu').hover(
		function(){
			$(this).addClass('over');
		},
		function() {
			$(this).removeClass('over');
		}
	);
   
	$("ul#top-nav li:not(.current-menu-item)").not("ul#top-nav li ul li").not("ul#top-nav li.current-page-ancestor").hover(
		function(){
			$(this).next().append('<div class="neighbor-hover"></div>');
		},
		function(){
			$('.neighbor-hover').remove();
		}
	);
		
   $('.sub-menu, .dropdown').hover(function(){
		$(this).siblings("a, div").addClass('over');
	},
	function() {
		$(this).siblings("a, div").removeClass('over');
	});
   
   // IMAGE FADES ON MOUSEOVER
   $('.image-fade').hover(function() {
		var fade = $('> div', this);
		if(fade.is(':animated')) {
			fade.stop().fadeTo(250, 1);
		} else {
			fade.fadeIn(250);
		}
	}, function() {
		var fade = $('> div', this);
		if(fade.is(':animated')) {
			fade.stop().fadeTo(3000, 0);
		} else {
			fade.fadeOut(250);
		}
	});
   
	// DISTRIBUTOR MAP
	$("#world-map .continent").css("opacity","0");
	
	$("a.africa").hover(function(){
		$("#world-map #africa-map").stop().animate({
			opacity: 1
		}, '500'),
		$("#continent-list a.africa").stop().animate({
			color: '#ff0000'
		}, '500');
	},
	function() {
		$("#world-map #africa-map").stop().animate({
			opacity: 0
		}, '500'),
		$("#continent-list a.africa").stop().animate({
			color: '#000'
		}, '500');
	});

	$("a.asia").hover(function(){
		$("#world-map #asia-map").stop().animate({
			opacity: 1
		}, '500'),
		$("#continent-list a.asia").stop().animate({
			color: '#ff0000'
		}, '500');
	},
	function() {
		$("#world-map #asia-map").stop().animate({
			opacity: 0
		}, '500'),
		$("#continent-list a.asia").stop().animate({
			color: '#000'
		}, '500');
	});

	$("a.sasia").hover(function(){
		$("#world-map #sasia-map").stop().animate({
			opacity: 1
		}, '500'),
		$("#continent-list a.sasia").stop().animate({
			color: '#ff0000'
		}, '500');
	},
	function() {
		$("#world-map #sasia-map").stop().animate({
			opacity: 0
		}, '500'),
		$("#continent-list a.sasia").stop().animate({
			color: '#000'
		}, '500');
	});

	$("a.cent-south").hover(function(){
		$("#world-map #cent-south-map").stop().animate({
			opacity: 1
		}, '500'),
		$("#continent-list a.cent-south").stop().animate({
			color: '#ff0000'
		}, '500');
	},
	function() {
		$("#world-map #cent-south-map").stop().animate({
			opacity: 0
		}, '500'),
		$("#continent-list a.cent-south").stop().animate({
			color: '#000'
		}, '500');
	});

	$("a.north").hover(function(){
		$("#world-map #north-map").stop().animate({
			opacity: 1
		}, '500'),
		$("#continent-list a.north").stop().animate({
			color: '#ff0000'
		}, '500');
	},
	function() {
		$("#world-map #north-map").stop().animate({
			opacity: 0
		}, '500'),
		$("#continent-list a.north").stop().animate({
			color: '#000'
		}, '500');
	});

	$("a.europe").hover(function(){
		$("#world-map #europe-map").stop().animate({
			opacity: 1
		}, '500'),
		$("#continent-list a.europe").stop().animate({
			color: '#ff0000'
		}, '500');
	},
	function() {
		$("#world-map #europe-map").stop().animate({
			opacity: 0
		}, '500'),
		$("#continent-list a.europe").stop().animate({
			color: '#000'
		}, '500');
	});

	$("a.mideast").hover(function(){
		$("#world-map #mideast-map").stop().animate({
			opacity: 1
		}, '500'),
		$("#continent-list a.mideast").stop().animate({
			color: '#ff0000'
		}, '500');
	},
	function() {
		$("#world-map #mideast-map").stop().animate({
			opacity: 0
		}, '500'),
		$("#continent-list a.mideast").stop().animate({
			color: '#000'
		}, '500');
	});
	
	$("input#quiz-reset").click(function(){
		window.location.replace('turbo-iq-test');
	});

	$("form.cleared").attr('autocomplete','off');
	
	// Because IE6 doesn't support multiple class selectors. Blech.
	$("li.distributor-locator").attr('id','distributor-locator');


});
