/* Foundation v2.2 http://foundation.zurb.com */
jQuery(document).ready(function ($) {

	/* Use this js doc for all application specific JS */

	/* TABS --------------------------------- */
	/* Remove if you don't need :) */

	function activateTab($tab) {
		var $activeTab = $tab.closest('dl').find('a.active'),
				contentLocation = $tab.attr("href") + 'Tab';

		//Make Tab Active
		$activeTab.removeClass('active');
		$tab.addClass('active');

    	//Show Tab Content
		$(contentLocation).closest('.tabs-content').children('li').hide();
		$(contentLocation).css('display', 'block');
	}

	$('dl.tabs').each(function () {
		//Get all tabs
		var tabs = $(this).children('dd').children('a');
		tabs.click(function (e) {activateTab($(this));});
	});

	if (window.location.hash) {
		activateTab($('a[href="' + window.location.hash + '"]'));
	}
	
	
	function activateTab2($tab2) {
		var $activeTab2 = $tab2.closest('dl').find('a.active'),
				contentLocation = $tab2.attr("href") + 'Tab2';

		//Make Tab Active
		$activeTab2.removeClass('active');
		$tab2.addClass('active');

    	//Show Tab Content
		$(contentLocation).closest('.tabs-content2').children('li').hide();
		$(contentLocation).css('display', 'block');
	}

	$('dl.tabs2').each(function () {
		//Get all tabs
		var tabs2 = $(this).children('dd').children('a');
		tabs2.click(function (e) {activateTab2($(this));});
	});

	if (window.location.hash) {
		activateTab2($('a[href="' + window.location.hash + '"]'));
	}
	
	
	

	/* ALERT BOXES ------------ */
	$(".alert-box").delegate("a.close", "click", function(event) {
    event.preventDefault();
	  $(this).closest(".alert-box").fadeOut(function(event){$(this).remove();});
	});


	/* PLACEHOLDER FOR FORMS ------------- */
	/* Remove this and jquery.placeholder.min.js if you don't need :) */

	$('input, textarea').placeholder();

	/* TOOLTIPS ------------ */
	$(this).tooltips();



	/* UNCOMMENT THE LINE YOU WANT BELOW IF YOU WANT IE6/7/8 SUPPORT AND ARE USING .block-grids */
//	$('.block-grid.two-up>li:nth-child(2n+1)').css({clear: 'left'});
//	$('.block-grid.three-up>li:nth-child(3n+1)').css({clear: 'left'});
//	$('.block-grid.four-up>li:nth-child(4n+1)').css({clear: 'left'});
//	$('.block-grid.five-up>li:nth-child(5n+1)').css({clear: 'left'});



	/* DROPDOWN NAV ------------- */

	var lockNavBar = false;
	$('.nav-bar a.flyout-toggle').live('click', function(e) {
		e.preventDefault();
		var flyout = $(this).siblings('.flyout');
		if (lockNavBar === false) {
			$('.nav-bar .flyout').not(flyout).slideUp(500);
			flyout.slideToggle(500, function(){
				lockNavBar = false;
			});
		}
		lockNavBar = true;
	});
  if (Modernizr.touch) {
    $('.nav-bar>li.has-flyout>a.main').css({
      'padding-right' : '75px'
    });
    $('.nav-bar>li.has-flyout>a.flyout-toggle').css({
      'border-left' : '1px dashed #eee'
    });
  } else {
    $('.nav-bar>li.has-flyout').hover(function() {$(this).children('.flyout').show();}, function() {$(this).children('.flyout').hide();})
  }

  /* ORBIT ------------- */
	
  $('#featured').orbit({
    animation: 'horizontal-push',
    animationSpeed: 800,
    timer: true,
    advanceSpeed: 4000,
    pauseOnHover: true,
    startClockOnMouseOut: false,
    startClockOnMouseOutAfter: 1000,
    directionalNav: true,
    captions: false,
    captionAnimation: 'fade',
    captionAnimationSpeed: 800,
    bullets: true,
    bulletThumbs: false,
    bulletThumbLocation: '',
    afterSlideChange: function(){}});

});