$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover(function() { 
			$(this).addClass(c);
		},
		function() { 
			$(this).removeClass(c);
		});
	});
};

$(document).ready(function() {
	
	/* *** Input onFocus *** */
	
	$('input').focus(function() {
		title = $(this).attr('title');
		
		if(title != '') {
			if($(this).attr('value') == title) $(this).attr('value', '');
		}
	});
	
	/* *** Input onBlur *** */
	
	$('input').blur(function() {
		title = $(this).attr('title');
		
		if(title != '') {
			if($(this).attr('value') == '') $(this).attr('value', title);
		}
	});
	
	/* *** Hero Shot Photo Slide Show *** */
	
	$('#hero-photos').cycle();
	
	/* *** Sub Navigation *** */
	
	$("#main-nav li").hover(function(){ 
		$("ul", this).fadeIn("slow");
	}, function() {});
	
	if (document.all) {
		$("#main-nav li").hoverClass ("sfHover");
	}
	
	$('#email-gather form').submit(
		function() {
			var error = false;
			var message = '<h2>Error : Email Gather Tool</h2><p>Please make sure to provide a valid email address</p>';
			var success = '<h2>Success</h2><p>You have successfully entered in to win a Free Vacation!</p>';
			var email = $('#email-gather form input').attr('value');
			var text = 'Your email here';
			
			if('' == email || text == email) error = true;
			
			if(error) {
				$.facebox(message);
			} else {
				$.ajax({
				   type: "POST",
				   url: "/travelsyndicate/ajax/email",
				   data: "email=" + email,
				   success: function(msg){
				     $.facebox(success);
				   }
				 });
			}
			
			$('#email-gather form input').attr('value', text);
			
			return false;
		}
	);
	
	if($('.accordion').length) {
		$('.accordion').accordion(
			{ autoHeight: false }
		);
	}
	
	$('.sub-li-link').hover(
		function() {
			var rel = $(this).attr('rel');
			var title = $(this).attr('title');
			
			$('#sub-ul-' + rel).attr('style', "background:url('assets/content/cruises/" + title + "') no-repeat center right;");
		},
		function() {
			var rel = $(this).attr('rel');
			
			$('#sub-ul-' + rel).attr('style', "none");
		}
	);
	
	$('.show-cruises').click(
		function() {
			var rel = $(this).attr('rel');
			
			$('#li-location-' + rel + ' a.main-li-link').click();
			return false;
		}
	);
});