/* create global $my variable */
var $my = window.$my || {};

/* startup */
jQuery(function($) {

	// convert youtube & vimeo embeds with oembed
	// $("a[href*=vimeo.com], a[href*=youtube.com]").oembed();

	/* add js class, useful utility */
	$('html').addClass('js');
	
	/* add class to top level of nav_primary, since Structure tag can't limit depth */
	$('#nav_primary :first-child').children('li').addClass('level1');

	/* hoverIntent functions for navigation dropdowns */
	function mySubnavMakeTall() { $(this).children('ul').slideDown(); }
	function mySubnavMakeShort() { $(this).children('ul').slideUp(); }
	$my.hoverIntentConfig = {
		sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		interval: 200, // number = milliseconds for onMouseOver polling interval    
		over: mySubnavMakeTall, // function = onMouseOver callback (REQUIRED)    
		timeout: 500, // number = milliseconds delay before onMouseOut    
		out: mySubnavMakeShort // function = onMouseOut callback (REQUIRED)    
	};

	/* enable hoverIntent for nav */	
	$('#nav_primary :first-child').children('li').hoverIntent( $my.hoverIntentConfig );
	

	/* trigger overlay for details */
	$('#details').append('<div class="close">close</div>');
	$('#view_details').overlay({
		// some expose tweaks suitable for modal dialogs
		expose: {
			color: '#000',
			loadSpeed: 200,
			opacity: 0.8
		}
	});

	/* handle fullscreen feature for any artwork */
	// do not perform fullscreen for IE6 and below
	if( ! ( $.browser.msie && parseInt($.browser.version) < 7 ) ) {
		$('#fullscreen').append('<div class="close">close</div>');
		$('#fullscreen').append('<div class="image" /><h1 />');
	
		$('#view_fullscreen').overlay({
			onBeforeLoad: function() {
				var overlay = this.getContent();
				var imgHolder = $(overlay).find('.image');
				var imgSrc = this.getTrigger().attr("href");
				var img = new Image();
				var h1 = this.getTrigger().attr("title");
				$(overlay).find('h1').html(h1);
				$('html').css('overflow', 'hidden');
				
				$(img)
					// once the image has loaded, execute this code
					.load(function () {
						$(imgHolder).html($(this)).fadeIn('fast');
					})
					// if there was an error loading the image, react accordingly
					// .error(function () {
					// 	alert('error');
					// })
					
					// *finally*, set the src attribute of the new image to our image
					.attr('src', imgSrc);
			},
			onClose : function() {
				$('html').css('overflow', 'auto');
			},
			top: 0,
			left: 0
		});
	}

});

