//Use this function to be able to add delay's to animations. jQuery doesnt have this built in for some reason.
$.fn.delay = function(time, callback){
    // Empty function:
    jQuery.fx.step.delay = function(){};
    // Return meaningless animation, (will be added to queue)
    return this.animate({delay:1}, time, callback);
}

$(document).ready(function() {
	
	// ***********************************************
	// AUTHOR: WWW.CGISCRIPT.NET, LLC
	// URL: http://www.cgiscript.net
	// Use the script, just leave this message intact.
	// Download your FREE CGI/Perl Scripts today!
	// ( http://www.cgiscript.net/scripts.htm )
	// ***********************************************
	var isNS = (navigator.appName == "Netscape") ? 1 : 0;
	var EnableRightClick = 0;
	if(isNS)
	document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
	function mischandler(){
	if(EnableRightClick==1){ return true; }
	else {return false; }
	}
	function mousehandler(e){
	if(EnableRightClick==1){ return true; }
	var myevent = (isNS) ? e : event;
	var eventbutton = (isNS) ? myevent.which : myevent.button;
	if((eventbutton==2)||(eventbutton==3)) return false;
	}
	function keyhandler(e) {
	var myevent = (isNS) ? e : window.event;
	if (myevent.keyCode==96)
	EnableRightClick = 1;
	return;
	}
	document.oncontextmenu = mischandler;
	document.onkeypress = keyhandler;
	document.onmousedown = mousehandler;
	document.onmouseup = mousehandler;
	
	
	
	
	// Setup scene
	
	$('div#content').css('opacity', 0);
	$('h1#logo-main').css('opacity', 0);
	$('h2#logo-secondary').css('opacity', 0);
	
	$('ul#main-nav li a').each(function() {
		$(this).css('opacity', 0);
	});
	
	// Fade in content div
	$('div#content').delay(1400).animate({opacity:1}, 600, "linear");
	
	// Fade in Logos
	$("h1#logo-main").animate({opacity:1},1000, "linear", null);
    $("h2#logo-secondary").delay(200).animate({opacity:1},1000, "linear", null);
	
	// Fade in menu elements one at a time
	var i = 0;
	$('ul#main-nav li a').each(function() {
		$(this).delay(200 * i).animate({opacity:1}, 1000, "linear");
		i++;
	});
	
	if(jQuery.isFunction($.fn.galleria)) {
		$('.gallery_demo_unstyled').addClass('gallery_demo');
		$('ul.gallery_demo').css('display', 'block').galleria({
			history   : true,
			clickNext : true,
			insert    : '#main_image',
			onImage   : function(image,caption,thumb) {
				image.css('display','none').fadeIn(1000);
				caption.css('display','none').fadeIn(1000);
				var _li = thumb.parents('li');
				_li.siblings().children('img.selected').fadeTo(500,0.3);
				thumb.fadeTo('fast',1).addClass('selected');
				image.attr('title','Next image >>');
			},
			onThumb : function(thumb) {
				var _li = thumb.parents('li');
				var _fadeTo = _li.is('.active') ? '1' : '0.3';
				thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
				thumb.hover(
					function() { thumb.fadeTo('fast',1); },
					function() { _li.not('.active').children('img').fadeTo('fast',0.3); }
				)
			}
		});
	}
});



