jQuery(document).ready(function($) {
  
  
  
/*-----------------------------------------------------------------------------------*/
/*	Navigation slide controller
/*-----------------------------------------------------------------------------------*/		 		

	jQuery('a[href*=#]').click(function() {

	$(".sf-menu li a").removeClass("current-menu-item");
	$(this).addClass("current-menu-item"); 
	
	
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
    && location.hostname == this.hostname) {
      var $target = $(this.hash);
      $target = $target.length && $target
      || $('[name=' + this.hash.slice(1) +']');
      if ($target.length) {
        var targetOffset = $target.offset().top - 55,
        duration=800,
		easing="easeInOutExpo";
        $('html,body')
        .animate({scrollTop: targetOffset}, 800, "easeInOutExpo");
       return false;
      }
    }
    });
    
			

	// Based roughly on Christian Kriesi's Amazing Slide Script
	jQuery(window).resize(function() {
	
			var sidebar 	= $("#section-sidebar"),
				tophat		= $("#section-tophat"),
				sb_menu 	= sidebar.find('.sf-menu'),
				sb_offset	= sidebar.offset(),
				win 		= $(window),
				
				
				//check if the sidebar exceeds the window viewport height. if thats not the case make it static
				set_sidebar = function()
				{
					if(sidebar.height() + sb_offset.top> win.height()) 
					{ 
						sidebar.css({position:'relative'}); 
					}
					else
					{
						sidebar.css({position:'fixed'}); 
					}
				};
				
			set_sidebar();
			win.resize(set_sidebar);
		});
	
	
/*-----------------------------------------------------------------------------------*/
/*	WayPoints - sets the # active link for the module you're scrolled to.
/*-----------------------------------------------------------------------------------*/

		$('.home .content_block:nth-child(0)').waypoint(function() {
		   $(".slide-menu li a").removeClass("current-menu-item");
		   $(".slide-menu li:nth-child(0) a").addClass("current-menu-item");
		});
		
		$('.home .content_block:nth-child(1)').waypoint(function() {
		   $(".slide-menu li a").removeClass("current-menu-item");
		   $(".slide-menu li:nth-child(1) a").addClass("current-menu-item");
		});
		
		$('.home .content_block:nth-child(2)').waypoint(function() {
		   $(".slide-menu li a").removeClass("current-menu-item");
		   $(".slide-menu li:nth-child(2) a").addClass("current-menu-item");
		});
		
		$('.home .content_block:nth-child(3)').waypoint(function() {
		   $(".slide-menu li a").removeClass("current-menu-item");
		   $(".slide-menu li:nth-child(3) a").addClass("current-menu-item");
		});
		
		$('.home .content_block:nth-child(4)').waypoint(function() {
		   $(".slide-menu li a").removeClass("current-menu-item");
		   $(".slide-menu li:nth-child(4) a").addClass("current-menu-item");
		});
		
		$('.home .content_block:nth-child(5)').waypoint(function() {
		   $(".slide-menu li a").removeClass("current-menu-item");
		   $(".slide-menu li:nth-child(5) a").addClass("current-menu-item");
		});
		
		$('.home .content_block:nth-child(6)').waypoint(function() {
		   $(".slide-menu li a").removeClass("current-menu-item");
		   $(".slide-menu li:nth-child(6) a").addClass("current-menu-item");
		});
		
		$('.home .content_block:nth-child(7)').waypoint(function() {
		   $(".slide-menu li a").removeClass("current-menu-item");
		   $(".slide-menu li:nth-child(7) a").addClass("current-menu-item");
		});
		
		$('.home .content_block:nth-child(8)').waypoint(function() {
		   $(".slide-menu li a").removeClass("current-menu-item");
		   $(".slide-menu li:nth-child(8) a").addClass("current-menu-item");
		});
		
		$('.home .content_block:nth-child(9)').waypoint(function() {
		   $(".slide-menu li a").removeClass("current-menu-item");
		   $(".slide-menu li:nth-child(9) a").addClass("current-menu-item");
		});
		
		$('.home .content_block:nth-child(10)').waypoint(function() {
		   $(".slide-menu li a").removeClass("current-menu-item");
		   $(".slide-menu li:nth-child(10) a").addClass("current-menu-item");
		});


/*-----------------------------------------------------------------------------------*/
/*	Filterable - http://www.gethifi.com/blog/a-jquery-plugin-to-create-an-interactive-filterable-portfolio-like-ours
/*-----------------------------------------------------------------------------------*/

		 $('#portfolio-list').filterable(); // ACTIVATE FILTER SCRIPT
		 		
		 // Default Override Section
		 // Now set inside each individual template-XXX.php file
		 // Then the script is activated inside the footer.php file

		 // Stop editting. The next section is our button actions. 
		 // Use this for research if you're having trouble understanding how the column count thing works. 
		 // ie: Note the differences between the Four Columns classes and the Three Columns classes.
		 
		 // Four Column Buttons Actions
		 $("span.4-col-grid").click(function () {
			 $("#portfolio-list .module-container").removeClass("twelve columns").addClass("three columns");
			 $("#portfolio-list .module-img").removeClass("eight columns alpha");
			 $("#portfolio-list .module-meta").fadeOut(100).removeClass("four three columns alpha omega visible");
			 $(".list_btn").css("opacity","1");
			 $(".hybrid_btn").css("opacity","1");
			 $(".grid_btn").css("opacity","0.5");
		 });
		 
		 $("span.4-col-hybrid").click(function () {
			 $("#portfolio-list .module-container").removeClass("twelve columns").addClass("three columns");
			 $("#portfolio-list .module-img").removeClass("eight columns alpha");
			 $("#portfolio-list .module-meta").fadeIn(300).removeClass("four omega").addClass("three columns alpha visible");
			 $(".list_btn").css("opacity","1");
			 $(".hybrid_btn").css("opacity","0.5");
			 $(".grid_btn").css("opacity","1");
		 }); 
		 
		 $("span.4-col-list").click(function () {
			 $("#portfolio-list .module-container").removeClass("three columns").addClass("twelve columns");			 
			 $("#portfolio-list .module-img").addClass("eight columns alpha");
			 $("#portfolio-list .module-meta").fadeIn(300).removeClass("alpha").addClass("four columns omega visible");
			 $(".list_btn").css("opacity","0.5"); 
			 $(".hybrid_btn").css("opacity","1");
			 $(".grid_btn").css("opacity","1");
		 }); 
		 
		 // Three Column Buttons Actions
		 $("span.3-col-grid").click(function () {
			 $("#portfolio-list .module-container").removeClass("twelve columns").addClass("four columns");
			 $("#portfolio-list .module-img").removeClass("eight columns alpha");
			 $("#portfolio-list .module-meta").fadeOut(100).removeClass("four columns alpha omega visible");
			 $(".list_btn").css("opacity","1");
			 $(".hybrid_btn").css("opacity","1");
			 $(".grid_btn").css("opacity","0.5");
		 });
		 
		 $("span.3-col-hybrid").click(function () {
			 $("#portfolio-list .module-container").removeClass("twelve columns").addClass("four columns columns");
			 $("#portfolio-list .module-img").removeClass("eight columns alpha");
			 $("#portfolio-list .module-meta").fadeIn(300).removeClass("omega").addClass("four columns alpha visible");
			 $(".list_btn").css("opacity","1");
			 $(".hybrid_btn").css("opacity","0.5");
			 $(".grid_btn").css("opacity","1");
		 }); 
		 
		 $("span.3-col-list").click(function () {
			 $("#portfolio-list .module-container").removeClass("four columns").addClass("twelve columns");			 
			 $("#portfolio-list .module-img").addClass("eight columns alpha");
			 $("#portfolio-list .module-meta").fadeIn(300).removeClass("four columns alpha").addClass("four columns omega visible");
			 $(".list_btn").css("opacity","0.5"); 
			 $(".hybrid_btn").css("opacity","1");
			 $(".grid_btn").css("opacity","1");
		 }); 
		 		 
		 // Two Column Buttons Actions
		 $("span.2-col-grid").click(function () {
			 $("#portfolio-list .module-container").removeClass("twelve columns").addClass("six columns");
			 $("#portfolio-list .module-img").removeClass("eight columns alpha");
			 $("#portfolio-list .module-meta").fadeOut(100).removeClass("four columns alpha omega visible");
			 $(".list_btn").css("opacity","1");
			 $(".hybrid_btn").css("opacity","1");
			 $(".grid_btn").css("opacity","0.5");
		 });
		 
		 $("span.2-col-hybrid").click(function () {
			 $("#portfolio-list .module-container").removeClass("twelve columns").addClass("six columns");
			 $("#portfolio-list .module-img").removeClass("eight columns alpha");
			 $("#portfolio-list .module-meta").fadeIn(300).removeClass("four columns omega").addClass("six columns alpha visible");
			 $(".list_btn").css("opacity","1");
			 $(".hybrid_btn").css("opacity","0.5");  
			 $(".grid_btn").css("opacity","1");
		 }); 
		 
		 $("span.2-col-list").click(function () {
			 $("#portfolio-list .module-container").removeClass("six columns").addClass("twelve columns");			 
			 $("#portfolio-list .module-img").addClass("eight columns alpha");
			 $("#portfolio-list .module-meta").fadeIn(300).removeClass("eight six columns alpha").addClass("four columns omega visible");
			 $(".list_btn").css("opacity","0.5"); 
			 $(".hybrid_btn").css("opacity","1");
			 $(".grid_btn").css("opacity","1");
		 }); 
		 

		 
		 
	
	
	
/*-----------------------------------------------------------------------------------*/
/*	FlexSlider - http://flex.madebymufffin.com/
/*-----------------------------------------------------------------------------------*/

		$('.flexslider').flexslider({
			animation: "slide",              //Select your animation type (fade/slide)
			slideshow: true,                //Should the slider animate automatically by default? (true/false)
			slideshowSpeed: 7000,           //Set the speed of the slideshow cycling, in milliseconds
			animationDuration: 500,         //Set the speed of animations, in milliseconds
			directionNav: true,             //Create navigation for previous/next navigation? (true/false)
			controlNav: true,               //Create navigation for paging control of each clide? (true/false)
			keyboardNav: true,              //Allow for keyboard navigation using left/right keys (true/false)
			touchSwipe: true,               //Touch swipe gestures for left/right slide navigation (true/false)
			prevText: "Previous",           //Set the text for the "previous" directionNav item
			nextText: "Next",               //Set the text for the "next" directionNav item
			randomize: false,                //Randomize slide order on page load? (true/false)
			slideToStart: 0,                //The slide that the slider should start on. Array notation (0 = first slide)
			pauseOnAction: true,            //Pause the slideshow when interacting with control elements, highly recommended. (true/false)
			pauseOnHover: false,            //Pause the slideshow when hovering over slider, then resume when no longer hovering (true/false)
			controlsContainer: ".flexslider-container"           //Advanced property: Can declare which container the navigation elements should be appended too. Default container is the flexSlider element. Example use would be ".flexslider-container", "#container", etc. If the given element is not found, the default action will be taken.
		});



/*-----------------------------------------------------------------------------------*/
/* prettyPhoto or rLightbox - http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/
/* Change this to rlightbox or prettyPhoto
/*-----------------------------------------------------------------------------------*/
		$("a[data-rel^='prettyPhoto']").prettyPhoto();
		$(".XYZ a").prettyPhoto();
		$("a.boxLink").prettyPhoto();
		$(".gallery-item a").prettyPhoto();
		
		
  		 
/*-----------------------------------------------------------------------------------*/
/*	DropDown Menu - http://users.tpg.com.au/j_birch/plugins/superfish/
/*-----------------------------------------------------------------------------------*/
		/*  $(".menu ul li").horizontalMenu({
			timeHide: 900
		});	 */
	
  		
		 $("ul.sf-menu").supersubs({
		 	minWidth:    13,   // minimum width of sub-menus in em units 
            maxWidth:    27,   // maximum width of sub-menus in em units 
            extraWidth:  0    // extra width can ensure lines don't sometimes turn over 
                               // due to slight rounding differences and font-family 
		 }).superfish({
		 	delay: 600,
		 	Speed: 'normal',
		 	animation:   {opacity:'show'},
		 	autoArrows: true,
		 }); 
		 
		 $("#responsive-nav select").change(function() {
  			window.location = $(this).find("option:selected").val();
		 });




/*-----------------------------------------------------------------------------------*/
/*	PERSISTENT HEADER - http://css-tricks.com
/*-----------------------------------------------------------------------------------*/
	
	function UpdateTableHeaders() {
	   $(".persist-area").each(function() {
	
	       var el             = $(this),
	           offset         = el.offset(),
	           scrollTop      = $(window).scrollTop(),
	           floatingHeader = $(".floatingHeader", this)
	
	       if ((scrollTop > offset.top) && (scrollTop < offset.top + el.height())) {
	           floatingHeader.css({
	            "visibility": "visible"
	           });
	       } else {
	           floatingHeader.css({
	            "visibility": "hidden"
	           });
	       };
	   });
	}
	
	// DOM Ready
	$(function() {
	
	   var clonedHeaderRow;
	
	   $(".persist-area").each(function() {
	       clonedHeaderRow = $(".persist-header", this);
	       clonedHeaderRow
	         .before(clonedHeaderRow.clone())
	         .css("width", clonedHeaderRow.width())
	         .addClass("floatingHeader");
	
	   });
	
	   $(window)
	    .scroll(UpdateTableHeaders)
	    .trigger("scroll");
	
	});



/*-----------------------------------------------------------------------------------*/
/*	Jump to the Top - custom, no URL
/*-----------------------------------------------------------------------------------*/

	var topLink = jQuery('#back-to-top');
	function jumpToTop(topLink) {		
		if(jQuery(window).scrollTop() > 0) {topLink.fadeIn(150);} 
		else {topLink.fadeOut(150);}
	}
	
	jQuery(window).scroll( function() {jumpToTop(topLink);});
	
	topLink.find('a').click( function() {
		jQuery('html, body').stop().animate({scrollTop:0}, 450);
		return false;
	});



/*-----------------------------------------------------------------------------------*/
/*	Tipsy & Normal Tooltips - http://onehackoranother.com/projects/jquery/tipsy/
/*-----------------------------------------------------------------------------------*/

		//jQuery('.tipsy').tipsy({gravity: 's', fade: true});
		//jQuery('ul.social img').tipsy({gravity: 's', fade: true, delayIn: 2000, delayOut: 200});
		//jQuery('p.social a').tipsy({gravity: 's', fade: true, delayIn: 2000, delayOut: 200});
		//jQuery('a.popLink').tipsy({gravity: 's', fade: true, delayIn: 2000, delayOut: 200});
		//jQuery('.gallery-item img').tipsy({gravity: 's', fade: true, delayIn: 3000, delayOut: 200});
		//jQuery('#sub-sidebar .social a').tipsy({gravity: 's', fade: true});



});
