/*
* Skeleton V1.1
* Copyright 2011, Dave Gamache
* www.getskeleton.com
* Free to use under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
* 8/17/2011
*/

$(window).scroll(function(){
	if (navigator.userAgent.indexOf("Mobile") < 0){
		scrolltop = $('body').scrollTop() + 115;
		docspace = $(window).height()-115;
		$("#wrapper > div").each(function(){
			offset = $(this).offset().top;
			height = $(this).height();
			innerheight = $(this).children(".news-post").height();
			pospoint = offset+height-innerheight;
			imageheight = $(this).children(".news-images").height();
			if(innerheight < imageheight){
				if(scrolltop > offset && docspace > innerheight && imageheight > innerheight){
					if(pospoint-30 > scrolltop){
						$(this).children(".news-post").css("top","115px").css("bottom","").css("position","fixed");
					} else {
						$(this).children(".news-post").css("top","").css("bottom","0px").css("position","absolute");
					}
				} else {
					$(this).children(".news-post").css("top","0px").css("bottom","").css("position","absolute");
				}
			}
		});
	}
});


$(document).ready(function() {

	/* Tabs Activiation
	================================================== */

	var tabs = $('ul.tabs');

	tabs.each(function(i) {

		//Get all tabs
		var tab = $(this).find('> li > a');
		tab.click(function(e) {

			//Get Location of tab's content
			var contentLocation = $(this).attr('href');

			//Let go if not a hashed one
			if(contentLocation.charAt(0)=="#") {

				e.preventDefault();

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

				//Show Tab Content & add active class
				$(contentLocation).show().addClass('active').siblings().hide().removeClass('active');

			}
		});
	});
});
