$(document).ready(function() {
	$('#navi li:has(ul:hidden)').children('ul').css('opacity', 0);	// set initial submenu opacity
	
	// Navigation Listeners		
	$('#navi li:has(ul:hidden)').mouseenter(function() {
		$(this).children('ul').stop();
		$(this).children('ul').css('display', 'block');
		$(this).children('ul').animate({opacity: 1}, 250);
	}).mouseleave(function() {
		$(this).children('ul').stop();
		$(this).children('ul').css('display', 'block');
		$(this).children('ul').animate({opacity: 0}, 250, 'linear', function() { $(this).css('display', 'none'); });
	});
	
	if ($('#slideshow').length) {
		$('.rotating-image').cycle({
			fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			speed: 1500,
			timeout: 6000
		});		
	}
	
	if ($('.content-footer img').length) {
		$('.content-footer img').fadeIn();
		
	}   
	
	function rotateImages() {
		var currentImage = imagePath + images[display];
		var nextImage = imagePath + images[display + 1];
		
		if (display >= images.length - 1) {
			nextImage = imagePath + images[0];
			display = 0;
		}
		else {
			display++;
		}
		
		$('#slideshow').append('<div class="slideshow-overlay"><img src="' + currentImage + '" alt="" /></div>');
		$('div.rotating-image').hide();
		$('div.rotating-image').find('img').attr('src', nextImage);
		$('div.slideshow-overlay').fadeOut(2000, function() { $(this).remove(); });
		$('div.rotating-image').fadeIn(1250);
	}
	
	// Model Listeners
	if ($('#model-thumbs')) {
		$('#model-thumbs a').each(function(i, el) {
			$(el).click(function(e) {
				e.preventDefault();
				var imgpath = $(this).attr('href');
				
				$('#model-image-container').fadeOut(250, function() {
					$(new Image()).load(function() {
						$('#model-image').attr('src', imgpath);
						$('#model-image-container').fadeIn(250);
					}).attr('src', imgpath)
				});		
			});
		});
	}
	
	// Contact Form Listeners
	if ($('#contact')) {
		$('#contact-name').focus(function() {
			if ($(this).val() == 'Name')
				$(this).val('');
		}).blur(function() {
			if ($(this).val() == '')
				$(this).val('Name');
		});
		
		$('#contact-email').focus(function() {
			if ($(this).val() == 'Email Address')
				$(this).val('');
		}).blur(function() {
			if ($(this).val() == '')
				$(this).val('Email Address');
		});
		
		$('#contact-message').focus(function() {
			if ($(this).val() == 'Enter message here.')
				$(this).val('');
		}).blur(function() {
			if ($(this).val() == '')
				$(this).val('Enter message here.');
		});
	}
	
	$('.thumb img').tipTip({defaultPosition: "top", delay: 0, edgeOffset: -10});
});



