$(document).ready(function(){

// this is for the main nav drop down stuff, starts up mouseover, mouseout
	$('#jsddm > li').bind('mouseover', jsddm_open);
	$('#jsddm > li').bind('mouseout',  jsddm_timer);
// main nav
	
// all images are using this 'cycle' for more info on the settings: http://malsup.com/jquery/cycle/options.html
	$('#allImages').cycle({ 
    fx:    'fade', 
	continuous: 1,
	speed: 3000,
	random: 0,
	cleartype: true, cleartypeNoBg: true,
	pause:	1
	 });
// all header images

// slideShow with controls 
	$("#slideshow").css("overflow", "hidden");
	
	$("ul#slides").cycle({
	fx: 'fade',
	pause: 1,
	prev: '#prev',
	next: '#next'
	});
	 
	$("#slideshow").hover(function() {
	$("ul#nav").fadeIn();
	},
		function() {
	$("ul#nav").fadeOut();
	});// slideShow with controls





// stuff for when there's an awareness box up on the site, hovering brings up the ability to mini it
	$("#awareness").hover(
		function () {
			$(".closeThis").css("display" , "block");
		},
		function () {
			$(".closeThis").css("display" , "none");
		});
	
	$(".closeThis").click(function() {
		$("#awareness").fadeOut(1000);
	})
// awareness

// stuff for pro development part of the site
	$(".proDevProgs").click(function() {
		$(".proProgs").slideToggle(500);
		$(this).toggleClass('showing'); 
		if ($(this).hasClass("showing")) {
			$(".progText").text('-') }
		else $(".progText").text('+') 
	} ) 
	$(".proDevTrain").click(function() {
		$(".proTrain").slideToggle(500);
		$(this).toggleClass('showing');
		if ($(this).hasClass("showing")) {
			$(".trainText").text('-') }
		else $(".trainText").text('+')
	})

// url parsing for the pro dev stuff
	if (jQuery.url.param("prog")) {
		$(".proProgs").show();
		$(".proDevProgs").toggleClass('showing');
		if ($(".proDevProgs").hasClass('showing')) {
			$(".progText").text('-') }
		 }
	if (jQuery.url.param("train")) {
		$(".proTrain").show();
		$(".proDevTrain").toggleClass('showing');
		if ($(".proDevTrain").hasClass('showing')) {
			$(".trainText").text('-') }
		 }
// url parsing

// disabled the submit button until they attach a file, if PDF, it enables ONLY. and then it validates the select 
// option because CF isn't smart enough to do it - and the people aren't smart enough to read.
$(":input[id=submitGrad]").attr("disabled","disabled")
    $("#myForm").validate({
	   rules: {
		 positions: "required",
		 appStatus: "required"
	   },
	   messages: {
		 positions: "Select One",
		 appStatus: "Select One"
	   }
	})

});



// stuff for the drop down menus
var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
   $(this).addClass('myActiveLink');
   ddmenuitem = $(this).find('ul').css('display', 'block');
   }

function jsddm_close()
{  if(ddmenuitem) { 
	  ddmenuitem.css('display', 'none'); 
	  $("#jsddm li").removeClass('myActiveLink'); };
}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

document.onclick = jsddm_close;
// all stuff for drop down

// form validate for the morons who don't read the grad assist app
function extCheck() {
	var ext = $('#upload').val().split('.').pop().toLowerCase();
	var allow = new Array('pdf');
	if(jQuery.inArray(ext, allow) == -1) {
	    alert('File must be a PDF! You cannot send any file but a PDF. Please fix this and try again. You cannot submit your form until it is corrected. You have selected document ending in ' + ext + '.' );
		$(":input[type=submit]").attr("disabled","disabled");
	} else {$(":input[id=submitGrad]").removeAttr("disabled")}
}


// Calendar Email
function sendMail() {

		$("#myformCalendarEmail").submit(function() {
	
		var email = $("#email").val();
		var emailf = $("#emailFrom").val();
		var extra = $("#additional").val();
		var eventNumber = $("#myformCalendarEmail").attr('eventNumber');
																									
			$.ajax({
				url: "../includes/calendarProcessEmail.cfm",
				data: {
							e: email,
							ef: emailf,
							extra: extra,
							eventNumber: eventNumber 
							},
				timeout: 2000,
				success: function(data) {
					
					jQuery(document).trigger('close.facebox');
				},
				error: function(data) {
					alert("There was a problem... Check the fields and try again.");
				}
			});
		return false;
		})
}
