
// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
function log(){
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  arguments.callee = arguments.callee.caller;  
  if(this.console) console.log( Array.prototype.slice.call(arguments) );
};
// make it safe to use console.log always
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c})(window.console=window.console||{});


$(document).ready(function() {
	var works;
	$.getJSON('data.json', function(data) {
		works = data[1];
		for (i=1;i<=data[0];i++)
		{
			var element = '<li><a href="#'+works[i].id+'" rel="'+i+'"><img src="images/thumbs/'+works[i].thumb+'" /></li>';
			$('nav ul').append(element);
		}
		$('nav ul li').live('click', function() {
			var data_id = $(this).find('a').attr('rel');
			
			var heading = $('<h2 />', {
				text: works[data_id].title
			});
			if (works[data_id].content.substring(0,7) == "http://") {
				var element = $('<iframe />', {
								src: "http://player.vimeo.com/video/" + works[data_id].content.split('/').pop() + "?api=1&title=0&byline=0&portrait=0&loop=1&color=ED1C24&autoplay=1", 
								width: 540, 
								height: 315, 
								frameborder: 0,
								id: "vimeo"
							});;
			} else {
				var element = $('<img />', {
					src: 'images/work/' + works[data_id].content
				});
			}
			var link = $('<a />', {
				href: 'images/work/' + works[data_id].content,
				rel: "workzzzzz",
				title: works[data_id].title
			});
			var description = $('<p />', {
				text: works[data_id].description
			});
			$('#display').html('');
			$('#display').append(heading).append(link).append(description);
			$('#display').find('a').append(element);
			
			colorboxify($('#display').find('a'));
			return false;
			//<p><a href="../content/ohoopee1.jpg" rel="example2" title="Me and my grandfather on the Ohoopee">Grouped Photo 1</a></p>
			
		});
	});
});

function colorboxify(element) {
	element.colorbox({transition:"elastic"});
}

function resize() {
	$('#display img').each(function(){
	    var imgWidth = $(this).width();
	    var imgHeight = $(this).height();

	    if(imgWidth > imgHeight){
	        $(this).width(imgWidth * 0.3);
	    } else {
	        $(this).height(imgHeight * 0.3);
	    }
	});	
}
