
$(function() {
	
	var menuTimeout;
	
	var navigationLinkSelector = '#navigation a';
	var navigationDropdownSelector = '.navigation-dropdown';
	//var navigationLinkDropdownTitleSelector = '.navigation-dropdown .title';
	//var navigationLinkDropdownBodySelector = '.navigation-dropdown .body';
	
	var bannerSlideshowImageSelector = '.slideshow .slideshow-item';
	var bannerSlideshowCurrentSlide = 0;
	var bannerSlideshowPauseDuration = 5000;
	var bannerSlideshowAnimationInDuration = 400;
	var bannerSlideshowAnimationOutDuration = 200;
	
	
	
	$(navigationDropdownSelector).css({
		opacity: 0,
		display: 'none'
	});
	
	
	$(navigationLinkSelector).mouseenter(function(e) {
		if(menuTimeout) {
			clearTimeout(menuTimeout);
		}
		
		var rel = $(this).attr('rel');
		
		var startProps = {
			display: 'block',
			left: ($(this).offset().left + ($(this).width() / 2))
		};
		
		var endProps = { opacity: 1 };
		
		$('#'+rel).stop().css(startProps).animate(endProps, 200);
	});
	
	
	$(navigationDropdownSelector).mouseenter(function(e) {
		if(menuTimeout) {
			clearTimeout(menuTimeout);
		}
		
		var startProps = {
			display: 'block'
		};
		
		var endProps = {
			opacity: 1
		};
		
		$(this).stop().css(startProps).animate(endProps, 200);
	});
	
	
	$(navigationDropdownSelector+','+navigationLinkSelector).mouseleave(function(e) {
		var endProps = {
			opacity: 0
		};
		
		menuTimeout = setTimeout(function() {
			$(navigationDropdownSelector).stop().animate(endProps, 200, function() {
				$(this).css('display', 'none');
			});
		}, 200);
		
	});
	
	
	
	
	$('form a.submit').click(function(e) {
		e.preventDefault();
		e.stopPropagation();
		
		$(this).parents('form').submit();
	});
	
	$('form a.reset').click(function(e) {
		e.preventDefault();
		e.stopPropagation();
		
		$(this).parents('form').reset();
	});
	
	
	$('a').mouseover(function() {
		$(this).addClass('hover');
		Cufon.refresh();
	});
	
	$('a').mouseout(function() {
		$(this).removeClass('hover');
		Cufon.refresh();
	});
	
	$('a').mousedown(function() {
		$(this).addClass('active');
		Cufon.refresh();
	});
	
	
	
	if($(bannerSlideshowImageSelector).size() > 0) {
		$(bannerSlideshowImageSelector).css({ opacity: 0 }).removeClass('hide');
		
		function showSlide() {
			var endProps, startProps;
			
			endProps = { opacity: 0 };
			$(bannerSlideshowImageSelector).stop().delay(bannerSlideshowAnimationInDuration).animate(endProps, bannerSlideshowAnimationOutDuration);
			
			
			startProps = { opacity: 0 };
			endProps = { opacity: 1 };
			
			$(bannerSlideshowImageSelector).eq(bannerSlideshowCurrentSlide).stop().css(startProps).animate(endProps, bannerSlideshowAnimationInDuration, 'easeOutCubic', function() {
				if(bannerSlideshowCurrentSlide < ($(bannerSlideshowImageSelector).size() - 1)) {
					bannerSlideshowCurrentSlide++;
				} else {
					bannerSlideshowCurrentSlide = 0;
				}
				
				setTimeout(showSlide, bannerSlideshowPauseDuration);
			});
			
			
		}
		
		showSlide();
	}
	
	
	$("a[rel^='prettyPhoto']").prettyPhoto();
	
	
	/**
	 * change the UA-XXXXX-X to be your site's ID
	 */
	/*
	var _gaq = [['_setAccount', 'UA-XXXXX-X'], ['_trackPageview']];
	(function(d, t) {
		var g = d.createElement(t),
		s = d.getElementsByTagName(t)[0];
		g.async = true;
		g.src = ('https:' == location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
		s.parentNode.insertBefore(g, s);
	})(document, 'script');
	*/
	
});
