/**
 * custom.js
 *
 * 1Serpent
 * Design, Development and Managed Hosting
 * http://1serpent.com/
 *
 * Adds some magic to our pretty stuff.
 */

jQuery(document).ready(function() {

	// Hide noscript
	$('#noscript').hide();

	// Drop-down menu navigation fix
	$("ul.menu > li").hover(function() {
		$(this).addClass("sp_hover");
	}, function() {
		$(this).removeClass("sp_hover");
	});

	// Mini nav
	$("#mini_nav a").click(function(event) {
		event.preventDefault();
		$("#mini_nav a").not(this).next("div").slideUp("slow").removeClass("sp_active");
		$(this).next("div").slideToggle("slow").toggleClass("sp_active");

		if( $("#sp_fade").length == 0 && $("#mini_nav a").next("div").hasClass("sp_active") ) {
			$("#page").append('<div id="sp_fade"></div>');
			$('#sp_fade').css({'filter' : 'alpha(opacity=45)'}).fadeIn("fast");
		}
		else if( !$("#mini_nav a").next("div").hasClass("sp_active") ) {
			$("#sp_fade").remove();
		}
	});

	$(".format_text a.button_call").click(function(event) {
		event.preventDefault();
		$('html, body').animate({scrollTop:0}, 'slow');
		$(".mini_nav_call .sp_jquery_box").slideToggle("slow").toggleClass("sp_active");
		if( $("#sp_fade").length == 0 && $("#mini_nav a").next("div").hasClass("sp_active") ) {
			$("#page").append('<div id="sp_fade"></div>');
			$('#sp_fade').css({'filter' : 'alpha(opacity=45)'}).fadeIn("fast");
		}
	});

	$("#sp_fade").live('click', function() {
		$("#sp_fade").fadeOut("fast", function() {
			$("#sp_fade").remove();
		});
		$(".sp_jquery_box").slideUp("slow").removeClass("sp_active");
		return false;
	});

	// Slider
	function formatText(index, panel) {
		return index + "";
	}

	$('.anythingSlider').anythingFader({
		autoPlay: true,					// This turns off the entire FUNCTIONALY, not just if it starts running or not.
		delay: 5000,					// How long between slide transitions in AutoPlay mode
		startStopped: false,			// If autoPlay is on, this can force it to start stopped
		animationTime: 300,				// 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)
	});

	// Equal height
	function equalHeight(group) {
		var tallest = 0;
		group.each(function() {
			var thisHeight = $(this).height();
			if(thisHeight > tallest) {
				tallest = thisHeight;
			}
		});
		group.height(tallest);
	}

	equalHeight( $("#footer_widgets li.widget") );

});
