$(document).ready(function($) {
	$('#mainNav > li').bind('mouseover', jsddm_open);
	$('#mainNav > li').bind('mouseout',  jsddm_timer);
	
	// this is for the flowplayer overlay
	$("body").append("<div class='overlay' id='overlay'><div class='contentWrap'></div></div>");
	var exposeConfig = {color: '#000',loadSpeed: 200,	opacity: 0.8 };
	
	$("a[rel*=#overlay]").overlay({ 
	   expose: exposeConfig, 
        onBeforeLoad: function() { 
            var wrap = this.getContent().find(".contentWrap"); 
            wrap.load(this.getTrigger().attr("href")); 
        } 
    });
  
//  tabControl.init();
//  accordionControl.init();

	// Anything Slider
	 $('.anythingSlider').anythingSlider({
		easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
		autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
		delay: 6000,                    // How long between slide transitions in AutoPlay mode
		startStopped: false,            // If autoPlay is on, this can force it to start stopped
		animationTime: 600,             // How long the slide transition takes
		hashTags: true,                 // Should links change the hashtag in the URL?
		buildNavigation: false,          // If true, builds and list of anchor links to link to each slide
		pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
		startText: "Go",                // Start text
		stopText: "Stop",               // Stop text
		navigationFormatter: formatText       // Details at the top of the file on this use (advanced use)
	 });

 
  
});


// get overlay API
$(function() {
    var api = $("#overlay").overlay({
            api: true, 
            expose: {color: '#000',loadSpeed: 200,	opacity: 0.8 },
            onBeforeLoad: function() { 
                var wrap = this.getOverlay().find(".contentWrap");
                wrap.load("/stay-informed.cfm"); 
            } 
        });
    
    // the name is "loadOverlay"
    window.LaunchOverlay = function(url) {
        api.load();
    };
});


//find all form with class transform and apply the plugin
$(function() {
    $("form.transform").jqTransform();
});


// for anything slider
function formatText(index, panel) {return index + "";}


var tabControl = {};
tabControl.init = function(){
	$('#tabs a').click(function(){
		var p = '#'+$(this).parent().parent().parent().attr('id');
		
		$(p +' #tabs a').removeClass('active');
		$(this).addClass('active');
		
		$(p + ' .tabbox').hide();
		$($(this).attr('href')).show();
		
		return false;
	});
}


var accordionControl = {};
accordionControl.init = function(){
	$('#accordion dd').hide();
	$('#accordion dt a').click(function(){
		$('#accordion dd').slideUp();
		$(this).parent().next().slideDown();
		return false;
	});
}

var timeout    = 100;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');
 }

function jsddm_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

document.onclick = jsddm_close;
