jQuery.ajaxSetup({
	'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript");}
});

jQuery.fn.thumbToggle = function(speed, easing, callback) { 
	if (this.css('right') == "-220px") { return this.animate({right: '0'}, 500); }
	if (this.css('right') == "0px") { return this.animate({right: '-200px'}, 500); }
	// return this.animate({opacity: 'toggle'}, speed, easing, callback); 
};
function doNothing(){}

function notify(notice) { 
	$('#flash_notice').html(notice);
	$('#flash_notice').show().fadeTo(600,1,function(){
		//delay and fadeout
		$(this).fadeTo(2500,1,function(){$(this).fadeTo(600,0,function(){$(this).hide();})});
	});
}

function removeParent(child) {
	$(child).parent().fadeOut("slow",function(){ $(this).remove(); })
}

$(document).ready(function(){
	
	$('ul.gallery').galleria({
		history   : false, // activates the history object for bookmarking, back-button etc.
		clickNext : true, // helper for making the image clickable
		insert    : '#slideshow', // the containing selector for our main image
		onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes

		// fade in the image & caption
		image.css('display','none').fadeIn(1000);
		// caption.css('display','none').fadeIn(1000);

		// fetch the thumbnail container
		var _li = thumb.parents('li');

		// fade out inactive thumbnail
		_li.siblings().children('img.selected').fadeTo(500,0.5);

		// fade in active thumbnail
		thumb.fadeTo('fast',1).addClass('selected');

		// add a title for the clickable image
		image.attr('title','Next Image');
	},
	onThumb : function(thumb) { // thumbnail effects goes here

		// fetch the thumbnail container
		var _li = thumb.parents('li');

		// if thumbnail is active, fade all the way.
		var _fadeTo = _li.is('.active') ? '1' : '0.5';

		// fade in the thumbnail when finnished loading
		thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);

		// hover effects
		thumb.hover(
			function() { thumb.fadeTo(400,1); },
			function() { _li.not('.active').children('img').fadeTo(400,0.5); } // don't fade out if the parent is active
		);
	}
	});

	//autoscroll thumb area
	$('#thumbs').autoscroll(AUTOSCROLL_Y);

	//reveal thumbs on hover over thumb icon
	$('#viewThumbs').hover(function(){
		$('#thumbs').animate({right: '0'}, 500);
		},''
	);

	//toggle thumbs on click of thumb icon
	$('#viewThumbs').click(function(){ $('#thumbs').thumbToggle(); });

	//hide thumbs on mouseout of thumbs
	function toggleThumbs() { $(this).thumbToggle(); }
	$('#thumbs').hoverIntent({    
				sensitivity: 3, // number = sensitivity threshold (must be 1 or higher) 
				interval: 1, 
				over: doNothing,
				timeout: 150, // number = milliseconds delay before onMouseOut    
				out: toggleThumbs // function = onMouseOut callback (REQUIRED)    
			});

	$('a.details').click(function(){ $('#details').slideToggle(); return false; });

	function openMenu(){ $(this).siblings('li').children('ul').slideUp(); $(this).children('ul').slideDown(); }
	function closeMenu(){ $('this[class!=active]').children('ul').slideUp(); }
	function resetMenu(){ 
		$(this).children('li[class!=active]').children('ul').slideUp(); 	
		$(this).children('li.active').children('ul').slideDown(); 
	}	
	$('ul#mainMenu li').hoverIntent({
				sensitivity: 5, // number = sensitivity threshold (must be 1 or higher) 
				interval: 10, 
				over: openMenu,
				timeout: 100, // number = milliseconds delay before onMouseOut    
				out: closeMenu // function = onMouseOut callback (REQUIRED)
			});
	// $('ul#mainMenu li').hover(function(){openMenu},function(){closeMenu});
	// 	$('ul#mainMenu').hover(function(){doNothing},function(){resetMenu});
	$('ul#mainMenu').hoverIntent({
				sensitivity: 5, // number = sensitivity threshold (must be 1 or higher) 
				interval: 1, 
				over: doNothing,
				timeout: 500, // number = milliseconds delay before onMouseOut    
				out: resetMenu // function = onMouseOut callback (REQUIRED)
			});
	
	
});