$(document).ready(function() {

	Gallery('.gallery');
	Scrolling('#nav li a');
	Scrolling('.top');
	HoverTip('.showtime');
	
	
	var defaultValue = $('#mce-EMAIL').attr('title');
	
	$('#mce-EMAIL').focus(function() {
		
		if($(this).val() == defaultValue)
		{
			$(this).val('');
		}

    });
	
	// if field is empty afterward, add text again
	$('#mce-EMAIL').blur(function()
	{
		if($(this).val() == '')
		{
			$(this).val(defaultValue);
		}
	});

	//press slides
	$('#pressSlideShow').cycle({
		timeout:		10000,
		height:			'300',
		fit:			1,
		pause: 			1,
		next:			'#pressSlideShow'
	});
	
	$('#pressSlideShow blockquote').each(function() {
		var pressHeight = 0;
		var itemHeight = $(this).innerHeight();
		
		if(pressHeight < itemHeight)
		{
			pressHeight = itemHeight;
		}
		
		$('#pressSlideShow').height(pressHeight);
	});
	
	
});

// Image Gallery
function Gallery (gallery) {
	
	$(gallery).children('a:gt(0)').css({
		'position': 'absolute',
		'left': '-9999px'
	});
	
	// Modal Window
	$(gallery).children('a').fancybox({
			'autoScale'     :   true,
			'transitionIn'	:	'fade',
			'transitionOut'	:	'fade',
			'speedIn'		:	800, 
			'speedOut'		:	200, 
			'overlayColor'  :   '#000',
			'overlayOpacity':   0.9,
			'overlayShow'	:	true,
			'titlePosition' :   'over'
	});
	
	// Hover Effect
	$('<div class="window-shade">View Full Sized Gallery</div>').appendTo(gallery).hide();
	
	$(gallery).children('a').hover(
		function(){
			$(this).children('img').fadeTo('fast', 0.7);
			$(this).siblings('.window-shade').fadeTo('fast', 1.0);
		},
		function(){
			$(this).children('img').fadeTo('fast', 1.0);
			$(this).siblings('.window-shade').fadeTo('fast', 0);
		}
	);

}

// Page Scrolling
function Scrolling (triggers) {
	
	var triggers = $(triggers);
	
	triggers.click(function (e) {
		e.preventDefault();
		var anchor = $(this).attr('href');
		
		$.scrollTo($(anchor), 300);
	})
	
}


// Effects
function HoverTip (triggers) {
	
	var triggers = $(triggers);
	
	triggers.css('position','relative');
	
	triggers.hover(
		function (e) {
			var tip = $(this).attr('title');
			$(this).append('<div class="tooltip"><span>'+tip+'</span></div>');
			$(this).children('.tooltip').hide();
			$(this).children('.tooltip').fadeIn(300);
			// $(this).attr('title','');
		},
		function  (e) {
			$(this).children('.tooltip').fadeOut(500, function() {
				$(this).remove();
			});
			// $(this).attr('title',tip);
		}
	);	
}

// Modal Windows
function Modal (external_link) {
	$(external_link).fancybox({
		'autoScale'     :   true,
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade',
		'speedIn'		:	800, 
		'speedOut'		:	200, 
		'overlayColor'  :   '#000',
		'overlayOpacity':   0.9,
		'overlayShow'	:	true,
		'titlePosition' :   'over',
		'height'        :   530,
		'width'         :   800
	});

}


// Slideshow (not used)
function Slideshow (gallery, speed) {
	
	var image_height = $(gallery).find('img').outerHeight();
	
	$(gallery).children('a').css({
		'height': image_height,
		'position': 'absolute',
		'left': 0,
		'top': 0
	});

	$(gallery).children('a:gt(0)').hide();

	setInterval(function(){$(gallery).children('a').eq(0).fadeOut().next('a').fadeIn().end().appendTo(gallery);}, speed || 4000);

}


