/*
	Any site-specific scripts you might have.
	Note that <html> innately gets a class of "no-js".
	This is to allow you to react to non-JS users.
	Recommend removing that and adding "js" as one of the first things your script does.
	Note that if you are using Modernizr, it already does this for you. :-)
*/

jQuery("#twitter").getTwitter({
	userName: "mrcthms", // your username
	numTweets: 1, // number of loaded tweets
	loaderText: "Loading tweets...",
	slideIn: false,
	slideDuration: 550,
	showHeading: false,
	showProfileLink: false,
	showTimestamp: true
});

var $scrollingDiv = $(".course .left");

$(window).scroll(function(){
	var scrollFromTop = $(window).scrollTop();
	if(scrollFromTop > 210) {
		$scrollingDiv
			.stop()
			.animate({"marginTop": ($(window).scrollTop() - 200) + "px"}, "slow" );	
	} else {
		$scrollingDiv
			.stop()
			.animate({"marginTop": (0) + "px"}, "slow" );				}
});

$(document).ready(function() {
	$('.gallery-wrap').each(function() {
		var show = $(this);
		show.cycle({
			fx: 'scrollHorz',
			speed: 400,
			timeout: 0,
			easing: 'easeInExpo',
//			next: show.siblings('.gallery-next'),
//			prev: show.siblings('.gallery-prev'),
			pager: show.siblings('.cycle-pager')
		});
		
		$(window).resize(limitPlease(function(){
			var widthArray = new Array();
			var heightArray = new Array();
			show.children().children().children().each(function(i, v) {
		    	widthArray[i] = $(this).width();
		    	heightArray[i] = $(this).actual('height');
			//	console.log(newHeight);
				/*
				
		    	$(this).parent().width(newWidth);
		    	$(this).parent().parent().width(newWidth);
		    	$(this).parent().parent().parent().width(newWidth);
		    	$(this).parent().height(newHeight);
		    	$(this).parent().parent().height(newHeight);
		    	$(this).parent().parent().parent().height(newHeight);
			*/
			});
			var newWidth = Math.max.apply(Math, widthArray);
			var newHeight = Math.max.apply(Math, heightArray);
		//	console.log(widthArray);
		//	console.log(heightArray);
			show.width(newWidth);
			show.height(newHeight);
   
		}, 500));
	});
	

	

	function limitPlease(callback, ms) {
	    var previous = (new Date()).getTime();

	    return (function() {
	        var now = (new Date()).getTime();
	        if (now - previous > ms) {
	            previous = now;
	            callback.apply(null, arguments);
	        }
	    });
	}
});
