// JavaScript Document
// remap jQuery to $
(function($){})(window.jQuery);

/*
CSS Browser Selector v0.4.0 (Nov 02, 2010)
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua=u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1},g='gecko',w='webkit',s='safari',o='opera',m='mobile',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3.6')?g+' ff3 ff3_6':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('blackberry')?m+' blackberry':is('android')?m+' android':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?m+' j2me':is('iphone')?m+' iphone':is('ipod')?m+' ipod':is('ipad')?m+' ipad':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win'+(is('windows nt 6.0')?' vista':''):is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);

/* trigger when page is ready */

/* we are loading this near the end */

$(function (){

	//make story area clickable
	/*
	$(".story").click(function(){
	     window.location=$(this).find("a").attr("href");
	     return false;
	});
	*/
	
	//convert divs to clickable
	$(".clickable").click(function(){
	     window.location = $(this).attr("url");
	     return false;
	});
	
	//Sliding boxes for homepage stories 
	if (!$.browser.msie) {
		$('.story').hover(function(){

			var _this = this;

			$(".details", this).stop().animate({bottom:'0px', opacity:'1'},{queue:false,duration:500, easing: 'easeOutQuint', complete: function(){
                                        $(".overlay", _this).css({overflow:"visible"});
                                }
                        });
			$(".entry-title", this).stop().animate({bottom:'-310px', opacity:'0'},{queue:false,duration:500, easing: 'easeOutQuint'});
			
		}, function() {
			$(".overlay", this).css({overflow:"hidden"});
			$(".details", this).stop().animate({bottom:'310px', opacity:'0'},{queue:false,duration:1000, easing: 'easeOutBack'});
			$(".entry-title", this).stop().animate({bottom:'10px', opacity:'1'},{queue:false,duration:600, easing: 'easeOutBack'});
		});
		
		//Sliding boxes for homepage featured stories 
		$('#stories-featured li').hover(function(){
			$(".details", this).stop().animate({top:'0px', opacity:'1'},{queue:false,duration:500, easing: 'easeOutQuint'});
			
			var $current = jQuery(".timestamp, .viewcount"),
			index = $current.index();
			if (index === 0) {
			   
			} else if (index === jQuery("#img").children().length - 1) {
			    $(".timestamp", this).stop().animate({top:'100px', opacity:'0'},{queue:false,duration:500, easing: 'easeOutQuint'});
			    $(".viewcount", this).stop().animate({top:'175px', opacity:'0'},{queue:false,duration:500, easing: 'easeOutQuint'});
			}
		}, function() {
			$(".details", this).stop().animate({top:'-200px', opacity:'0'},{queue:false,duration:500, easing: 'easeOutBack'});
			
			var $current = jQuery(".timestamp, .viewcount"),
			index = $current.index();
			if (index === 0) {
			   
			} else if (index === jQuery("#img").children().length - 1) {
				$(".timestamp", this).stop().animate({top:'3px', opacity:'1'},{queue:false,duration:500, easing: 'easeOutBack'});
				$(".viewcount", this).stop().animate({top:'73px', opacity:'1'},{queue:false,duration:500, easing: 'easeOutBack'});
			}
			
		});
	}else{
		$('#grid-story .story').hover(function(){
			$(".details", this).stop().animate({bottom:'0px', opacity:'1'},{queue:false,duration:1, easing: 'easeOutQuint'});
			$(".entry-title", this).stop().animate({bottom:'-310px',opacity:'0'},{queue:false,duration:1, easing: 'easeOutQuint'});
			$(".story-meta", this).stop().animate({top:'200px','opacity':'0'},{queue:false,duration:1, easing: 'easeOutQuint'});
			$(".overlay", this).css({overflow:"visible"});
			
		}, function() {
			$(".overlay", this).css({overflow:"hidden"});
			$(".details", this).stop().animate({bottom:'310px','opacity':'0'},{queue:false,duration:1, easing: 'easeOutBack'});
			$(".entry-title", this).stop().animate({bottom:'10px','opacity':'1'},{queue:false,duration:1, easing: 'easeOutBack'});
			$(".story-meta", this).stop().animate({top:'10px','opacity':'1'},{queue:false,duration:1, easing: 'easeOutBack'});
		});
		
		//Sliding boxes for homepage featured stories 
		$('#stories-featured li').hover(function(){
			$(".details", this).stop().animate({top:'0px', opacity:'1'},{queue:false,duration:1});
			
			var $current = jQuery(".timestamp, .viewcount"),
			index = $current.index();
			if (index === 0) {
			   
			} else if (index === jQuery("#img").children().length - 1) {
			    $(".timestamp", this).stop().animate({top:'100px'},{queue:false,duration:1});
			    $(".viewcount", this).stop().animate({top:'175px'},{queue:false,duration:1});
			}
		}, function() {
			$(".details", this).stop().animate({top:'-200px', opacity:'0'},{queue:false,duration:1});
			
			var $current = jQuery(".timestamp, .viewcount"),
			index = $current.index();
			if (index === 0) {
			   
			} else if (index === jQuery("#img").children().length - 1) {
				$(".timestamp", this).stop().animate({top:'3px'},{queue:false,duration:1});
				$(".viewcount", this).stop().animate({top:'73px'},{queue:false,duration:1});
			}
			
		});
	}
	
	
	//search palceholder text
	$('#s').focus(function(){ 
	if($(this).val() == $(this).attr('defaultValue')) {
			$(this).val('');
		}
	});
	
	$('#s').blur(function(){
	if($(this).val() == '')	{
			$(this).val($(this).attr('defaultValue'));
		} 
	});
	
	//signup palceholder text
	$('#name').focus(function(){ 
	if($(this).val() == $(this).attr('defaultValue')) {
			$(this).val('');
		}
	});
	
	$('#name').blur(function(){
	if($(this).val() == '')	{
			$(this).val($(this).attr('defaultValue'));
		} 
	});
	
	$('#email').focus(function(){ 
	if($(this).val() == $(this).attr('defaultValue')) {
			$(this).val('');
		}
	});
	
	$('#email').blur(function(){
	if($(this).val() == '')	{
			$(this).val($(this).attr('defaultValue'));
		} 
	});
	

	//sharebar animation
	$(function() {
		var $sharebar = $("#akp-sharebar-vertical");

		var $story = $(".post-wrap");

		var offset = $sharebar.offset();
		var story_offset = $story.offset();

		var topPadding = 15;

		var set_sharebar_pos = function() {

			var scrolltop = $(window).scrollTop();

			if ($(window).width() > 850 && $story.length > 0) {
				if(scrolltop + $sharebar.outerHeight() > story_offset.top + $story.outerHeight()) {
					$sharebar.removeClass("akp-sharebar-fixed").addClass("akp-sharebar-bottom");
				} else if (scrolltop > offset.top && !$sharebar.hasClass("akp-sharebar-fixed")) {
					$sharebar.addClass("akp-sharebar-fixed").removeClass("akp-sharebar-bottom");
				} else if(scrolltop < offset.top && $sharebar.hasClass("akp-sharebar-fixed")) {
					$sharebar.removeClass("akp-sharebar-fixed").removeClass("akp-sharebar-bottom");
				}
			}
		}

		if($sharebar.length > 0) {
			$(window).scroll(set_sharebar_pos);
			$(window).load(set_sharebar_pos);
		}
	
	});    
});


/* optional triggers

$(window).load(function() {
	
});

$(window).resize(function() {
	
});

*/


$(document).ready(function() {



	//Set Default State of each portfolio piece

	$(".paging123").show();

	$(".paging123 a:first").addClass("active");

		

	//Get size of images, how many there are, then determin the size of the image reel.

	var imageWidth = $(".window").width();

	var imageSum = $(".image_reel img").size();

	var imageReelWidth = imageWidth * imageSum;

	

	//Adjust the image reel to its new size

	$(".image_reel").css({'width' : imageReelWidth});

	

	//Paging + Slider Function

	rotate = function(){	

		var triggerID = $active.attr("rel") - 1; //Get number of times to slide

		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide



		$(".paging123 a").removeClass('active'); //Remove all active class

		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)

		

		//Slider Animation

		$(".image_reel").animate({ 

			left: -image_reelPosition

		}, 500 );

		

	}; 

	

	//Rotation + Timing Event

	rotateSwitch = function(){		

		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds

			$active = $('.paging123 a.active').next();

			if ( $active.length === 0) { //If paging reaches the end...

				$active = $('.paging123 a:first'); //go back to first

			}

			rotate(); //Trigger the paging and slider function

		}, 3000); //Timer speed in milliseconds (3 seconds)

	};

	

	rotateSwitch(); //Run function on launch

	

	//On Hover

	$(".image_reel a").hover(function() {

		clearInterval(play); //Stop the rotation

	}, function() {

		rotateSwitch(); //Resume rotation

	});	

	

	//On Click

	$(".paging123 a").click(function() {	

		$active = $(this); //Activate the clicked paging

		//Reset Timer

		clearInterval(play); //Stop the rotation

		rotate(); //Trigger rotation immediately

		rotateSwitch(); // Resume rotation

		return false; //Prevent browser jump to link anchor

	});	

	

});



