
//////////////////////////////////////////
//  P $$ Delay Plugin
/////////////////////////////////////////
(function($){
	$.fn.delay = function(time, callback){
		jQuery.fx.step.delay = function(){};
		return this.animate({delay:1}, time, callback);
	}
})(jQuery);
//////////////////////////////////////////
//  P $$ ESPEN Switcher
/////////////////////////////////////////
(function($){
	$.fn.eSwitch = function(options){
		// Options
		var opt = options || {};
		
		opt.groupA = opt.groupA || 'groupA';
		opt.textA = opt.textA || 'textA';
		opt.groupB  = opt.groupB || 'groupB';
		opt.textB  = opt.textB || 'textA';

		this.each(function(){
			
			var $this = $(this);
			var $dad = $this.parents('div');
			var $id = $dad.attr('id');
			
			// Setup Parent, Create Controller, Hide the kids
			$this.parents('div#'+$id+'')
			.addClass('switcher')
			.find('>h3')
			.after('<ul class="switcher"/>')
			.end()
			.find('li.'+opt.groupB+'')
			.hide();

			//Build out the controller
			$('#'+$id+' ul.switcher').html(
				'<li><a class="'+opt.groupA+'Show active">'+opt.textA+'</a>|</li>' +
				'<li><a class="'+opt.groupB+'Show">'+opt.textB+'</a></li>'
			).after('<span class="clear"/>');
			
			// Show / Hide the kids
			$('#'+$id+' ul.switcher li a').click(function(){
				$(this)
				.parents('ul.switcher')
				.siblings('ul')
				.find('li:visible')
				.fadeOut(500)
				.end()
				.find('li:hidden')
				.delay(500)
				.fadeIn(500);
			});

			// Switch Nav Highlight
			$('#'+$id+' ul.switcher li a').click(selectNav);
			function selectNav() {
				$(this)
				.parents('#'+$id+' ul.switcher')
				.find('li a')
				.removeClass('active')
				.end()
				.end()
				.addClass('active');
		  	}

			
		});
		return this;
	}
})(jQuery);
//////////////////////////////////////////
//  Doc Ready
/////////////////////////////////////////
$(document).ready(function(){

	//////////////////////////////////////////
	//  MIsc Crapolla
	/////////////////////////////////////////
	// Open external links in new window
	$('a[rel*="external"], #links #page #primaryContent ul li a').click(function(){
		window.open(this.href);
		return false;
	});
	//helper
	$('#error #footer p a').hover(function(){
		$('#helper').show(); 
		}, function(){
		$('#helper').hide();	
	});

	//////////////////////////////////////////
	//  Switcher
	/////////////////////////////////////////
	$('#exhibitions ul').eSwitch({
		'groupA' : 'solo',
		'textA' : 'Solo',
		'groupB' : 'group',
		'textB' : 'Group'
	});
	$('#publications ul').eSwitch({
		'groupA' : 'book',
		'textA' : 'Book',
		'groupB' : 'mag',
		'textB' : 'Mag'
	});


	
	//////////////////////////////////////////
	//  Dev Tools
	/////////////////////////////////////////
/*
	$('#header').append(
		'<div id="devTools">'+
		'<span>Grid</span>'+
		'<input type="checkbox" name="grid" />'+
		'</div>');
	$('#devTools').css({
		'position' : 'absolute',
		'text-align': 'right',
		'right' : 0, 
		'top' : 15, 
		'height' : 20, 
		'width' : 100 
	});
	$('input[name=grid]').change(function(){
		$('body').toggleClass('grid');
	});*/

});

