// JavaScript Document

function pagerFactory(idx, slide) {
	var title = ($(slide).attr("alt"));
	return '<li><a href="#">'+title+'</a></li>';
}

$(document).ready(function () {   
	
	//Drop Down Nav
	$('#nav li').hover(  
		function (e) {  
			$(this).children('ul:hidden').fadeIn(300);
		},   
		function () {  
			$(this).children('ul:visible').fadeOut(200);
		}  
	);

	//Form Highlight & Message Transition
	$("form").highlight();
	$(".msg").delay(3000).fadeOut(3000);
	//$('a[href$="' + window.location.pathname + '"]').addClass("highlight");
	
	//Form Example Text
	$('.example').example(function() {
	  return $(this).attr('title');
	});

	//Header Rotation
    $('#headerImage').cycle({
		fx: 'fade',
        prev:    '#prev',
        next:    '#next',
        pager:   '#headerImageNav',
        pagerAnchorBuilder: pagerFactory
	});

	//Tab Actions
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	
	//Tab On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});
	
	//Regular Contact Form Validations
	var container = $('#formError');
	$("#form").validate({
		errorContainer: container,
		errorLabelContainer: $("ol", container),
		wrapper: 'li',
		meta: "validate",
		focusInvalid: false
	});
	
	//Login Form Validations
	var loginContainer = $('#formLoginError');
	$("#formLogin").validate({
		errorContainer: loginContainer,
		errorLabelContainer: $("ol", loginContainer),
		wrapper: 'li',
		meta: "validate",
		focusInvalid: false
	});
	
	//Signup Form Validations
	var signupContainer = $('#formSignupError');
	$("#formSignup").validate({
		errorContainer: signupContainer,
		errorLabelContainer: $("ol", signupContainer),
		wrapper: 'li',
		meta: "validate",
		focusInvalid: false
	});

	$("a.video").click(function() {
		$.fancybox({
			'padding'             : 0,
			'autoScale'   		: false,
			'transitionIn'        : 'fade',
			'transitionOut'       : 'fade',
			'speedIn'				: '150',
			'speedOut'			: '150',
			'title'               : this.title,
			'width'               : 550,
			'height'              : 343,
			'overlayColor'		: '#000',
			'href'                : this.href = this.href.replace(new RegExp("watch\\?v=", "i"), 'v/') + '&autoplay=1',
			'type'                : 'swf',
			'swf'                 : {'allowfullscreen':'true'}
		});
		return false;
	}); 

});
