$(document).ready(function() {
	
	//+------------------------------
	// Remove the no-js class
	//+------------------------------
	
	$("html").attr("class", "js");
	
	//+------------------------------
	// Home slider
	//+------------------------------
	
	$(".hero_tabs").tabs(".hero > div", {
		effect: 'fade',
		fadeOutSpeed: 'slow',
		rotate: true
	}).slideshow({ 
		autoplay: true,
		interval: 9000, 
		clickable: false, 
		autopause: false 
	});
	
	// Disable homepage slideshow when user clicks a tab
	$('.hero_tabs a').click(function(){
		$('.hero_tabs').data('slideshow').stop();
		return false;
	});
	
	//+------------------------------
	// Utility sign in menus
	//+------------------------------
	
	$("#utility .signin").click(function(event) {
		event.preventDefault();
        $(this).parent().find("div.signin_menu").toggle();
       	$(this).parent().siblings().find("div.signin_menu").hide();
        $("#utility .signin").removeClass("menu-open");
        $(this).addClass("menu-open");
    });

    $("#utility .signin_menu").mouseup(function() {
        return false;
    });
    
    $(document).mouseup(function(event) {
        if($(event.target).parent(".signin").length==0) {
            $(".signin").removeClass("menu-open");
            $("#utility .signin_menu").hide();
        }
    });
    
	//+------------------------------
	// Misc UI
	//+------------------------------
	
	$("#contact_form").validator();

	$('a.new-win').attr('target', '_new');
	
	// Kill borders for IE
	 $("div.sidebar div.widget:last-child").css('border-bottom', 'none');
	 $('input[type=checkbox]').css('border', 'none');
	 $('input[type=radio]').css('border', 'none');
	 
	 // Registration form accordion
	 $("#forms_accordion").tabs("#forms_accordion div.pane", {tabs: 'h4', effect: 'slide', initialIndex: null});
	 
	 // Regular accordions 
	 $(".accordion").tabs(".accordion div.pane", {tabs: 'h3', effect: 'slide', initialIndex: 0});
	 $(".accordion .pane p:last-child").css('margin-bottom', '0');
	
	// Tabs
	$(function() {
		$("ul.tabs").tabs("div.panes > div");
	});
	
	// Columnize
	$('#sitemap ul').makeacolumnlists({cols:2,colWidth:325,equalHeight:false});
	$('.columns ul').makeacolumnlists({cols:3,colWidth:206,equalHeight:false});
	
	// Call modal window
	$('a[rel*=facebox]').facebox();
	
	$('#fc_calendar').live('mouseover mouseout',function(){
		$("#fc_calendar .event_info").tooltip({relative: 'true', position: 'top center', predelay: 300, offset: [5, 0]});
	});
	
	//Reveals
	$('#reveal').hide();
	$('a.reveal').click(function(event) {
		event.preventDefault();
		$('#reveal').slideToggle();
		$(this).hide();
    });
    
	
	//+------------------------------
	// Sticky Buns
	//+------------------------------
	if($('div.sticky').length > 0) {
		$('div.sidebar div.wrapper').append('<div id="sticky_container"></div>');
		// Create Sticky Container

		$('div.sidebar div.wrapper div.widget.sticky').each(function() {$(this).appendTo('div#sticky_container');});
		// Move Sticky Elements into Sticky Container

		// Sticky Buns

		var sticky_elem = 'div#sticky_container';
		// Sidebar is the outer container - set to position:relative
		var sticky_pos = $(sticky_elem).offset();
		sticky_pos = sticky_pos.top;
		$(window).scroll(function(e,i)
		{sticky_buns(sticky_elem,sticky_pos);});
	}
	
	function sticky_buns(sticky_elem,sticky_pos) {
		var sticky_class = 'sticky_buns';
		function make_sticky_buns(sticky_elem,sticky_pos,sticky_class) {
			var window_pos = $(window).scrollTop();
			window_pos = window_pos +20;
			if(window_pos >= sticky_pos)
			{$(sticky_elem).addClass(sticky_class);}
			else if(window_pos <= sticky_pos)
			{$(sticky_elem).removeClass(sticky_class);}
		}
		make_sticky_buns(sticky_elem,sticky_pos,sticky_class);
	}

}); //End $(document).ready
