$(document).ready(function($) {
	
	// 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();
	 
	 // Dropdowns
	$('ul.sf-menu').superfish({ speed: 'fast' });
 
	 // 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: 1200,             // How long the slide transition takes
		hashTags: true,                 // Should links change the hashtag in the URL?
		buildNavigation: true,          // 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)
	 });
     
     
    // TRIGGERS FOR SLIDER ON HOMEPAGE
    var trigger_over = function() { 
        $(".default_sitAnalysis_content").fadeOut('400', function() {$(".expanded_sitAnalysis_content").fadeIn('400');});
        $(".sitAnalysis .ft img.first").fadeOut('500');
        $(".sitAnalysis .content").animate({
            height: '130px',
            top: '0px'
          }, 750, function() {
            $(".sitAnalysis .content").unbind('mouseover' , trigger_over);
            $(".sitAnalysis .content .close").bind('click', trigger_click);
        });   
        
        $(".sitAnalysis .ft img.second").fadeIn('750');
    }
    
    var trigger_click = function() {
        $(".expanded_sitAnalysis_content").fadeOut('400', function() {$(".default_sitAnalysis_content").fadeIn('400');});   
        $(".sitAnalysis .ft img.second").fadeOut('500');
        $(".sitAnalysis .content").animate({
            height: '42px',
            top: '84px'
          }, 500, function() {
            $(".sitAnalysis .content .close").unbind('click', trigger_click);
            $(".sitAnalysis .content").bind('mouseover', trigger_over);
        });
        $(".sitAnalysis .ft img.first").fadeIn('750');
    }
      // TRIGGERS FOR SLIDER ON HOMEPAGE  
      $(".sitAnalysis .content, .sitAnalysis .ft").bind('mouseover', trigger_over);
        
    
});

/*
function triggerOverlay(tgt) {
{
// make overlay API global
var o = $(tgt).overlay({
finish: { top: 100 },
onBeforeLoad: function() {
this.getBackgroundImage().expose({color: '#ffffff', closeOnClick:false });
},
onClose: function() {
$.expose.close();
}
});
o.load();
}
*/
$(function() {
// get overlay API
    var api = $("#overlay").overlay({
            api: true, 
            expose: {color: '#000',loadSpeed: 200,	opacity: 0.8 },
            onBeforeLoad: function() { 
                var wrap = this.getOverlay().find(".contentWrap");
                wrap.load("/resident-login.cfm"); 
            } 
        });
    
    // the name is "loadOverlay"
    window.LaunchOverlay = function(url) {
        api.load();
    };
});





// 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;
	});
	
	$('#accordion table').hide();
	$('#accordion .category a').click(function(){
//		alert('iasdlfasd');
		var href = $(this).attr('href');
		$("."+href).slideToggle();
		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;
