/* 	Author: Marc Broad
	WWW: marcbroad.com
	WWW: resume.marcbroad.com
	WWW: myopia.co.nz
	WWW: dystopia.co.nz
   	WWW: photopia.co.nz 
   	WWW: drbroad.com 
    Feel free to copy away, credit is appreciated.	
*/


// remap jQuery to $
(function($){


// function to bind the footer to the bottom of the screen if the scroll isnt big enough.
// tool tip options
// navbar slide down
// dynamic menu for homepage

	
	$('.toggle').click(function(){
		Shuffle();		
	});
	
	$('body').keyup(function (event) {
		if(event.keyCode == 78)
			Shuffle();
	});
	
	function Shuffle(){
		
		var count = $('article').length;
		var len = count;
		// unshift the array to make looping easier
		// work out how manyarticles there are
		
		// change the front class/...
		var cur = $('article.front')
		var next = cur.next()
		if(!next.length){
			next = $('article:first')
		}
		next.addClass('front');
		cur.removeClass('front');
		
		var curIndex = $('article').index(next)
		//$("article:gt(" + curIndex + ")").add("article:lt(" + curIndex + ")") 
		
		//$('article')
		//$("article:gt(" + curIndex + ")").add("article:lt(" + curIndex + ")")
		$("article").each(function(){
		
			
			
			var pos = $('article').index(this) - curIndex
			if(pos < 0) pos = len + pos
			
			window.log(1 - pos/len)
			$(this).css({
							'z-index':(len * 100) - (pos * 100),
							'top':(len * 40) - (pos * (50 - pos*2)),
							'-webkit-transform':'scale(' + (1 - pos/len) + ') skewY(-13deg)',
							'-moz-transform':'scale(' + (1 - pos/len) + ') skewY(-13deg)',
							'text-shadow':'0 0 '+ ((pos * 2) + 1)  +'px rgba(0, 0, 0, '+ (0.25 + (0.5 / len)*pos) +')',
							'-webkit-transform-origin':'left',
							'-moz-transform-origin':'left',
							'color':'rgba(0,0,0,0)'
			});
			
			$(this).attr('id', pos)
			
		/*
			if($(this).hasClass('front')){
				$(this).removeClass('front').addClass('back');	
			}
			else if($(this).hasClass('middle')){
				$(this).removeClass('middle').addClass('front');	
			}
			else if($(this).hasClass('back')){
				$(this).removeClass('back').addClass('middle');	
			}
		*/
			count --;
		});
		
		$('article.front').css({'color':'rgba(0,0,0,1)'});
		window.log('------------------')
	}

 



})(this.jQuery);



// usage: log('inside coolFunc',this,arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  if(this.console){
    console.log( Array.prototype.slice.call(arguments) );
  }
};



// catch all document.write() calls
(function(doc){
  var write = doc.write;
  doc.write = function(q){ 
    log('document.write(): ',arguments); 
    if (/docwriteregexwhitelist/.test(q)) write.apply(doc,arguments);  
  };
})(document);



