function initArchiveMenu() { 
  $('.archive-menu ul').hide();
  $('.archive-menu ul.current').show();
  $('.archive-menu li a').click(
    function() {
      var checkElement = $(this).next();
      if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
        $('.archive-menu ul:visible').slideUp('normal');
        return false;
        }
      if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
        $('.archive-menu ul:visible').slideUp('normal');
        checkElement.slideDown('normal');
        return false;
        }
      }
    );
  }
function setCalendar(){
	$('#calendar').height(540);
	$('#calendar').width(845);
	
	function setEqualHeight(rows,columns) {
		var tallestcolumn = 85;
		var numberofrows = 0;
		rows.each( function() {
			numberofrows += 1;
			if(numberofrows == 6) {
				tallestcolumn = 70;
			}
		});
		columns.each( function() {
			currentHeight = $(this).height();
			if(currentHeight > tallestcolumn) {
				tallestcolumn2 = currentHeight;
			}
		});
		columns.height(tallestcolumn);
	}
	setEqualHeight($(".calendarRow"),$(".calendarRow > div.calendarCell"));
}


function initBigTargets() {
	$("div.bigTarget p a").bigTarget({
		hoverClass: 'over', // CSS class applied to the click zone onHover
		clickZone : 'div:eq(0)' // jQuery parent selector
	});	
	$("div.bigTarget h3 a").bigTarget({
		hoverClass: 'over', // CSS class applied to the click zone onHover
		clickZone : 'div:eq(0)' // jQuery parent selector
	});	
}
function initCycle() {
	$(document).ready(function(){	
		$('#slideshow').cycle({ 
		   fx: 'fade', 
		   speed: 1000,
		   timeout: 8000,
		   cleartypeNoBg: true
		 });
	});
}
function initColorBox() {
	$(".iframeCalendar").colorbox({width:"890", height:"600px", iframe:true, scrolling:false});
}
function initContactLink() {
	$("div.contactButton").click(function(){
		$(".quickContact").animate({ height: "440px" }).animate({ height: "340px" }, "fast");
		$("div.contactButton").toggle();
	});
	$('div.hideButton').click(function(){
		$(".quickContact").animate({ height: "0px" }, "fast");
	});	
	  $('div.doneButton').click(function(){
		$('.quickContact').animate({ height: "0px" }, "fast");
		$('div.contactButton').toggle();
	});	
}
function initContactFormSubmit() { 
	var options = { 
		target:        '#hiddenDIV',   // target element(s) to be updated with server response 
	    beforeSubmit:  beforePost,  // pre-submit callback 
	    success:       afterPost  // post-submit callback 
	}
	$('#quickContactForm').validate({
	    submitHandler: function(form) {
			$('#quickContactForm').ajaxSubmit(options);
		}
	});
	// pre-submit callback 
	function beforePost() { 
		$("#contactSubmit").hide();
		$("#submitMessage").show();
	    // here we could return false to prevent the form from being submitted; 
	    // returning anything other than false will allow the form submit to continue 
	    return true; 
	} 
	// post-submit callback 
	function afterPost(rtn)  { 
	    if(rtn=="success") {
	      	$("#quickContactForm").hide();
			$("#contactNotification").fadeIn("slow");
		}else{
	        //there was an error, so grab the UL in the content ID, 
	        //inside the hidden DIV, and put it into the Message Notification
	      $("#errorMessage").html( $("#hiddenDIV #content ul").html() );
		  $("#hiddenDIV").empty(); 
	     }
	}
}
function initLeadCapture() { 
	var options = { 
		target:        '#hiddenDIV',   // target element(s) to be updated with server response 
	    beforeSubmit:  beforePost,  // pre-submit callback 
	    success:       afterPost  // post-submit callback 
	}
	$('#leadCapture').validate({
	    submitHandler: function(form) {
			$('#leadCapture').ajaxSubmit(options);
		}
	});
	// pre-submit callback 
	function beforePost() { 
		$("#submitRequest").hide();
		$("#makingRequest").show();
	    // here we could return false to prevent the form from being submitted; 
	    // returning anything other than false will allow the form submit to continue 
	    return true; 
	} 
	// post-submit callback 
	function afterPost(rtn)  { 
	    if(rtn=="success") {
	      	$("#leadCapture").hide();
			$("#successNotification").fadeIn("slow");
		}else{
	        //there was an error, so grab the UL in the content ID, 
	        //inside the hidden DIV, and put it into the Message Notification
	      $("#errorSupportRequest").html(  $("#hiddenDIV #content ul").html() );
		  $("#hiddenDIV").empty(); 
	     }
	}
	
}
function initEventRegistration() { 
	var options = { 
		target:        '#hiddenDIV',   // target element(s) to be updated with server response 
	    beforeSubmit:  beforePost,  // pre-submit callback 
	    success:       afterPost  // post-submit callback 
	}
	$('a#registerAnother').click(function() {
		location.reload();
	});
	$('#registration').validate({
	    submitHandler: function(form) {
			$('#registration').ajaxSubmit(options);
		}
	});
	// pre-submit callback 
	function beforePost() { 
		$("#registrationSubmit").hide();
		$("#registrationSubmitMessage").show();
	    // here we could return false to prevent the form from being submitted; 
	    // returning anything other than false will allow the form submit to continue 
	    return true; 
	} 
	// post-submit callback 
	function afterPost(rtn)  { 
	    if(rtn=="success") {
	      	$("#registration").hide();
			$("#registrationNotification").fadeIn("slow");
		}else{
	        //there was an error, so grab the UL in the content ID, 
	        //inside the hidden DIV, and put it into the Message Notification
			$("#errorRegistrationMessage").html(  $("#hiddenDIV #content ul").html() );
		  $("#hiddenDIV").empty(); 
	     }
	}
	
}
function initenewsRequest() {
	$(".enewsLink").click(function() {
		if ($("#enewsRequest").is(":hidden")){
			$("#enewsRequest").slideDown();
			$("#enewsSubmit").show();
			$("#enewsSubmitMessage").hide();
		} else {
			$("#enewsRequest").slideUp("fast");
		}
	});
	$('a#enewsRegisterAnother').click(function() {
		location.reload();
	});
	$('a#enewsClose').click(function() {
		$("#enewsNotification").slideUp("slow");
		$("#enewsRequest").slideUp("slow");
	});
	var options = { 
		target:        '#hiddenDIV',   // target element(s) to be updated with server response 
	    beforeSubmit:  beforePost,  // pre-submit callback 
	    success:       afterPost  // post-submit callback 
	};
	$('#enewsRequest').validate({
	    submitHandler: function(form) {
			$('#enewsRequest').ajaxSubmit(options);
		}
	});
	// pre-submit callback 
	function beforePost() { 
		$("#enewsSubmit").hide();
		$("#enewsSubmitMessage").show();
	    // here we could return false to prevent the form from being submitted; 
	    // returning anything other than false will allow the form submit to continue 
	    return true; 
	} 
	// post-submit callback 
	// post-submit callback 
	function afterPost(rtn)  { 
	    if(rtn=="success") {
	      	$("#enewsRequest").hide();
			$("#enewsNotification").fadeIn("slow");
		}else{
	        //there was an error, so grab the UL in the content ID, 
	        //inside the hidden DIV, and put it into the Message Notification
			$("#errorenewsMessage").html(  $("#hiddenDIV #content ul").html() );
		  $("#hiddenDIV").empty(); 
	     }
	}
}
function initZindex() {
	$(function() {
		var zIndexNumber = 1000;
		$('div').each(function() {
			$(this).css('zIndex', zIndexNumber);
			zIndexNumber -= 10;
		});
	});
	$('div.slideuplanding').css('zIndex', 1020);
	$('div.slideupHeaderlanding').css('zIndex', 1010);	
	$('div#cboxOverlay').css('zIndex', 1050);
	$('div#colorbox').css('zIndex', 1051);
	$('div#cboxWrapper').css('zIndex', 1052);
}

$(document).ready(function() {
	initArchiveMenu();
	setCalendar();
	initBigTargets();
	initCycle();
	initColorBox();
	initContactLink();
	initContactFormSubmit();
	initLeadCapture();
	initEventRegistration();
	initenewsRequest();
	initZindex();
	});
	
