// ===========================
//  Reset script on 'Back'
// ===========================
history.navigationMode = 'compatible';

/*$(function(){
	$('#artbox').mouseenter(function() {
		var $marginLefty = $(this).find('#description');
  
  //$(this).next('div').text( "mouse enter" );

 //alert($marginLefty.id);
 //alert($marginLefty.width());
 $marginLefty.animate({
   //right: parseInt($marginLefty.css('right'),10) == 0 ? $marginLefty.outerWidth() : 0 });
   right: parseInt($marginLefty.css('right'),10) == 0 ? '-23em' : 0 });
  });
});*/

$(function(){
	$('#artbox img.main').after('<div class="label">'+$('#artbox img.main').attr('alt')+'</div>');
	
	var anim_description = $('#artbox').find('#description');
	var anim_tab = anim_description.find('#tab');
	
	$('#artbox').mouseenter(function() {
		anim_description.stop().animate({ left: '55em' });
		anim_tab.stop().animate({ opacity: 0 });
   });
   $('#artbox').mouseleave(function() {
		anim_description.stop().animate({ left: '78em' });
		anim_tab.stop().animate({ opacity: 1 });
   });
});



//right: -78em;
//-55

// ===========================
//  Active Nav
// ===========================
var pathArray = window.location.pathname.toString().split("/");
$(function(){
	// Make current page active
	$('a[href='+window.location.pathname+']').addClass('current_page');
	//document.write('<div id="error_check">'+window.location.pathname+'</div>');
	// Keep top nav active if in sub directory
	if (pathArray.length > 3) {
		$('#nav a[href*=/'+pathArray[2]+'/]').addClass('current_page');
	}
});

// ===========================
//  Cycle
// ===========================
$(function(){
	// Create div to place labels
	$('.cycle').after('<div class="label"></div>');
	// Cycle code
	$('.cycle').cycle({
		fx: 'fade',
		pager: '#artbox .label',
	    pagerAnchorBuilder: function(index, slide) {
        	return "<a href='javascript:setSlide("+index+")'>"+$(slide).find('img').attr('alt')+"</a>"; 
    	} 
	});
});
function setSlide(index) {
	// When link pressed go to index
	$('.cycle').cycle(index);
}

// ===========================
//  Tiles
// ===========================
$(function(){
	$('#tiles li a').each(function() {
		// Create a label for each of the tiles
		$(this).append('<div class="label">' + $(this).find('img').attr('alt') + '</div>');
		// Roll over/out states
		$(this).hover(
		function() { $(this).find('.label').stop().animate({ backgroundColor: "black" }, 300); },
		function() { $(this).find('.label').stop().animate({ backgroundColor: '#999999' }, 800); }
		);
		// Reset on click
		$(this).click(function() {
			$(this).find('.label').css("background-color","#999999");
		});
	});
});
