$(document).ready(function($) {
	//$('a[rel*=facebox]').facebox();
	$('#main > li').bind('mouseover', jsddm_open);
	$('#main > 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();
  
 // Carousel
 $(".panels").jCarouselLite({
    btnNext: ".next",
    btnPrev: ".prev",
	visible: 1
 });

 // 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: 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)
    });
 
    // anything slider
    $("#thumbNav a:eq(0)").html("<img src='/images/banners/thumb1.jpg' />");
    $("#thumbNav a:eq(1)").html("<img src='/images/banners/thumb2.jpg' />");
    $("#thumbNav a:eq(2)").html("<img src='/images/banners/thumb3.jpg' />");
    $("#thumbNav a:eq(3)").html("<img src='/images/banners/thumb4.jpg' />");
  
});

$(function() {
    //find all form with class transform and apply the plugin
    $("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;
