/* Author: Dan Almeida */
$(document).ready(function() {
	// Back to Top
	// hide #back-top first
	$("#back-top").hide();
	
	// fade in #back-top
	$(function () {
		$(window).scroll(function () {
			if ($(this).scrollTop() > 100) {
				$('#back-top').fadeIn();
			} else {
				$('#back-top').fadeOut();
			}
		});

		// scroll body to 0px on click
		$('#back-top a').click(function () {
			$('body,html').animate({
				scrollTop: 0
			}, 800);
			return false;
		});
	});

	$.localScroll();
	
	// Form Validation
	$(".form, #forgot_password_form").each(function() {
		$(this).validate();
	});

	// Form Labels
	$(".form label, #login label, #login_window form label").inFieldLabels();
	
	// Homepage groups - hover states
	var groupTop = '20px';
	var groupTopSlide = '10px';
	$("#group-1").hover(function(e){
		$("#speechbox-default").hoverFlow(e.type, {opacity:'0'}).css("z-index","1");
		$("#speechbox-1").hoverFlow(e.type, {top:groupTop, opacity:'1'}).fadeIn().css("z-index","100");
	}, function(e) {
		$("#speechbox-1").hoverFlow(e.type, {top:groupTopSlide, opacity:'0'}, 150).css("z-index","1");
		$("#speechbox-default").hoverFlow(e.type, {opacity:'1'}).css("z-index","100");
	});
	$("#group-2").hover(function(e){
		$("#speechbox-default").hoverFlow(e.type, {opacity:'0'}).css("z-index","1");
		$("#speechbox-2").hoverFlow(e.type, {top:groupTop, opacity:'1'}).fadeIn().css("z-index","100");
	}, function(e) {
		$("#speechbox-2").hoverFlow(e.type, {top:groupTopSlide, opacity:'0'}, 150).css("z-index","1");
		$("#speechbox-default").hoverFlow(e.type, {opacity:'1'}).css("z-index","100");
	});
	$("#group-3").hover(function(e){
		$("#speechbox-default").hoverFlow(e.type, {opacity:'0'}).css("z-index","1");
		$("#speechbox-3").hoverFlow(e.type, {top:groupTop, opacity:'1'}).fadeIn().css("z-index","100");
	}, function(e) {
		$("#speechbox-3").hoverFlow(e.type, {top:groupTopSlide, opacity:'0'}, 150).css("z-index","1");
		$("#speechbox-default").hoverFlow(e.type, {opacity:'1'}).css("z-index","100");
	});
	
	// Tooltips
	$("#category_tooltips li a").tooltip({ effect: 'fade'});
	
	// Login box
	$("a.login, #login .close").click(function(){
		if ( !$("#login").hasClass("active") ) {
			$("#login").fadeIn().addClass("active");
			return false;
		} else {
			$("#login").fadeOut().removeClass("active");
			return false;
		}
	});
	
	// Add quote for IE
	$(".ie blockquote p:last-child").append('&#8221;');
	
	// Document type classes
	$('a[href]').each(function() {
	   if((C = $(this).attr('href').match(/[.](doc|docx|xls|ppt|pdf|mp3)$/))) {
	       $(this).addClass(C[1]).attr('target', '_blank');
	   }
	});
	$('a').each(function() {
		if ( $(this).attr('target') == '_blank' ) {
			$(this).addClass('externallink');
		}
	});
	// open PDF in new window
	$("a[href$=pdf]").each(function() {
		$(this).attr('target', '_blank');
	});
	
	// Style ordered lists
	$('ol li').wrapInner('<span> </span>');
	$('ol').css('color','#8CC63F');
	// Zebra Stripe Lists
	$('.checklist li:odd').addClass('odd');
	 
	// Uniform
	$("select, input:checkbox, input:radio, input:file").uniform();
	 
	// Fancybox
	$(".youtube").click(function() {
		$.fancybox({
				'padding'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'fade',
				'title'			: this.title,
				'width'			: 680,
				'height'		: 495,
				'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'			: 'swf',
				'swf'			: {
				   	'wmode'		: 'transparent',
					'allowfullscreen'	: 'true'
				}
			});
		return false;
	});
	$("a.inline").fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'fade',
		'autoDimensions'	: 'true',
		'scrolling'   : 'no'
	});
	 
	// Tabs
	$(".tabs").tabs(".panes > div.subject", {
		effect:		"fade"
	});
	
	// Contact Form
	$("input[name='classification']").change(function() {
		var checkedInputID = $("input[@name='classification']:checked").attr("id");
		if (checkedInputID == 'classification_1') {
			$(".form_section").fadeOut();
			$("#inquiry_1").fadeIn();
		} else if (checkedInputID == 'classification_2') {
			$(".form_section").fadeOut();
			$("#inquiry_2").fadeIn();
		} else if (checkedInputID == 'classification_3') {
			$(".form_section").fadeOut();
			$("#inquiry_3").fadeIn();
		} else if (checkedInputID == 'classification_4') {
			$(".form_section").fadeOut();
			$("#inquiry_4").fadeIn();
		} else if (checkedInputID == 'classification_5') {
			$(".form_section").fadeOut();
			$("#inquiry_5").fadeIn();
		}
	});
		
}); // end document.ready
