(function($) {

	$(window).load(function() {
		
		var hash = window.location.hash.substr(1);
		
		if ( window.location.hash != '' ) {
			//console.log(hash);
			var ind = $('a#'+hash).attr('href');
			Shadowbox.open({
				content: ind,
				gallery: 'Mixed' 
			});
			var prev = $('#sb-nav-previous');
			var next = $('#sb-nav-next');
			$('#sb-wrapper').append(prev).append(next);
		}
		
		$('#smart-archives-list h2:gt(5), #smart-archives-list ul:gt(5)').hide();
		$('span.view-all a').live('click', function() {
			$(this).remove();
			$('#smart-archives-list h2:gt(5), #smart-archives-list ul:gt(5)').show();
			return false;
		});
		
	});
	
	$('#team-news-filter a').live('click', function() {
		var team = $(this).attr('href');
		$('#team-news-filter li').removeClass('selected');
		$(this).parent().addClass('selected');
		$('#team-news').html('<img src="/blog/wp-content/themes/SkullCandy2/img/loader.gif" style="padding:15px;" />');
		$('#team-news').load(team+' #team-news', function() {
			Shadowbox.clearCache();
			Shadowbox.setup();
			console.log(team+' loaded');
		});
		return false;
	});

	$('#inkd .navigation a').live('click', function() {
		var link = $(this).attr('href');
		var randomnumber = Math.floor(Math.random()*100000);
		var theID = $('a.selected').attr('id');
		//console.log(link);
		$('#loader').show();
		$(this).parent().parent().remove();
		$('.section').append('<div class="'+randomnumber+'"></div>');
		$('.'+randomnumber).load(link+' #morecontent', function() {
			if ( theID == 'All' ) {
				$('.section li').fadeIn();
			} else {
				$('.section li:not(".'+theID+'")').hide(0, function() {
					$('.section li.'+theID).fadeIn();
				});
			}
			$('#loader').hide();
			$('#inkd-filter.bottom').show();
			Shadowbox.clearCache();
			Shadowbox.setup();
		});
		return false;
	});

	$('#inkd-filter a').live('click', function() {
		var theID = $(this).attr('id');
		$('#inkd-filter a').removeClass('selected');
		$('a#'+theID).addClass('selected');
		if ( theID == 'All') {
			$('.section li').fadeIn();
			//window.location.hash = 'All';
		} else {
			$('.section li:not(".'+theID+'")').hide(0, function() {
				$('.section li.'+theID).fadeIn();
			});
			//window.location.hash = theID;
		}
		return false;
	});

	$('body.page-template-inkd-php .section li a').live('click', function() {
		var prev = $('#sb-nav-previous');
		var next = $('#sb-nav-next');
		var postID = $(this).attr('id');
		window.location.hash = postID;
		$('#sb-wrapper').append(prev).append(next);
		return false;
	});
	
	$('body.page-template-team-news-php .section li a').live('click', function() {
		var prev = $('#sb-nav-previous');
		var next = $('#sb-nav-next');
		$('#sb-wrapper').append(prev).append(next);
		return false;
	});
	
	/*$('body.page-template-inkd-php #sb-overlay, body.page-template-inkd-php #sb-nav-close').live('click', function() {
		window.location.hash = '';
	});*/

	$('#sb-body-inner').live('mouseover mouseout', function(event) {
		if ( $('#sb-drag-proxy').length ) {
			if (event.type == 'mouseover') {
				$(this).append('<div id="drag"></div>');
			} else {
				$('#drag').remove();
			}
		}
	});
	
	$('#sb-body-inner').live('mousedown mouseup', function(event) {
		if ( $('#sb-drag-proxy').length ) {
			if (event.type == 'mousedown') {
				$('#drag').hide();
			} else {
				$('#drag').show();
			}
		}
	});
	
	/*$('#sb-body-inner').live('dblclick', function(event) {
		alert('CLICKED');
	});*/
	
	/*$.mapKey('down', imageDown);
	$.mapKey('up', imageUp);
	
	function imageDown() {
		var h = $('img#sb-player').attr('height');
		var c = parseInt($('img#sb-player').css('top'));
		var d = $('#sb-drag-proxy').height();
		var h = ((0 - h) + d);
		console.log(c);
		console.log(h);
		if ( c <= h  ) { } else {
			$('img#sb-player').animate({'top': '-=200'}, 500);
		}
	}
	
	function imageUp() {
		$('img#sb-player').animate({'top': '0'}, 500);
	}*/

})(jQuery);
