var empty = /^\s*$/;
var email_format = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
var number_format = /^\d+$/;

jQuery(function() {
	
	/************************* INDEX ******************************/
	jQuery(".season-link").hover(function() {
		jQuery("#" + jQuery(this).attr("id") + "-image").stop(true, true).fadeIn();
	}, function() {
		jQuery("#" + jQuery(this).attr("id") + "-image").stop(true, true).hide();
	});
	
	/************************* INDEX ******************************/
	
	
	/************************* NAVS ******************************/
	var orig_text = "";
	jQuery(".menu-text a.main-menu").hover(function() {
		orig_text = jQuery(this).html();
		jQuery(this).html(jQuery(this).attr("title"))
	}, function() {
		jQuery(this).html(orig_text)
	});
	
	jQuery(".menu-text ul li a").hover(function() {
		orig_text = jQuery(this).html();
		jQuery(this).html(jQuery(this).attr("title"))
	}, function() {
		jQuery(this).html(orig_text);
	});
	
	jQuery(".mainnav li a").hover(function() {
		orig_text = jQuery(this).html();
		jQuery(this).html(jQuery(this).attr("title"))
	}, function() {
		jQuery(this).html(orig_text);
	});
	
	jQuery(".menu-text a.main-menu").click(function() {
		the_id = jQuery(this).attr("id");
		jQuery(".fadein img").hide();
		jQuery(".fadein img").attr("src", base_url + "images/site/" + the_id + ".jpg");
		jQuery(".fadein img").fadeIn(3000);
		jQuery(".menu-text a").removeClass("bold");
		jQuery(this).addClass("bold");
		jQuery(".navigation ul li ul").slideUp();
		jQuery(this).parent().find("ul").slideDown();
		jQuery(".col-2").slideUp();
		jQuery(".col-3").slideUp();
		jQuery(".col-4").slideUp();
	});
	
	jQuery(".menu-text ul li a").click(function() {
		the_id = jQuery(this).attr("id");
		if(the_id != '') {
			jQuery(".fadein img").hide();
			jQuery(".fadein img").attr("src", base_url + "images/site/" + the_id + ".jpg");
			jQuery(".fadein img").fadeIn(3000);
			jQuery(".col-2").slideDown();
			jQuery(".col-3").slideDown();
			jQuery(".col-4").slideDown();
		}
		jQuery(".menu-text ul li a").removeClass("bold");
		jQuery(this).addClass("bold");
	});
	
	/*jQuery(".mainnav li a").hover(function() {
		jQuery(".sub-navigation-wrap").stop(true, true).slideDown(200);
	}, function() {
		jQuery(".sub-navigation-wrap").stop(true, true).slideUp(200);
	});
	
	jQuery(".sub-navigation-wrap").hover(function() {
		jQuery(this).stop(true, true).show();
	}, function() {
		jQuery(this).stop(true, true).slideUp(200);
	});*/
	/************************* NAVS ******************************/
	
	
	/************************* STYLE ******************************/
	if(cur_page == 'style') {
		// Initialize history plugin.
		jQuery.history.init(deeplink_content);
		// deep linking
		jQuery(".deeplink").live("click", function() {
			var hash = jQuery(this).attr("href");
			jQuery.history.load(hash);
			return false;
		});
		// deep linking
	}
	/************************* STYLE ******************************/
	
	
	/*********************** JUMP LIST ****************************/
	jQuery(".jump-nav-img").click(function() {
		jQuery(".jump-list-thumb-container").slideToggle();
	});
	/*********************** JUMP LIST ****************************/
	
	
	/********************* DEEP LINK ****************************/
	function deeplink_content(hash) {
		// ajax post here
		if(hash != '') {
			jQuery(".menu-text a").removeClass("bold");
			jQuery("#" + hash).addClass("bold");
			jQuery(".navigation ul li ul").slideUp();
			jQuery("#" + hash).parent().find("ul").slideDown();
		}
	}
	/********************* DEEP LINK ****************************/
	
	jQuery(".content-bg").fadeIn(3000);
});

function validate_form() {
	msg = jQuery("#info-msg").html("");
	
	jQuery('.required').each(function() {
		// vars
		id = jQuery(this).attr("id");
		
		tag = jQuery('#' + id).parent().attr('class');
		
		if(tag != 'hidden') {
			if(empty.test(jQuery(this).val()) || jQuery(this).val() == jQuery(this).attr("rel")) {
				jQuery("#info-msg").html('<div class="info-msg">' + jQuery(this).attr("title") + '</div>');
				return false; 
			}
			
			if(id == "email" && !email_format.test(jQuery(this).val())) {
				jQuery("#info-msg").html('<div class="info-msg">' + jQuery(this).attr("title") + '</div>');
				return false;
			}
			
			if(jQuery('#present').is(':checked') == false) {
				from = jQuery('#year').val() + '' + jQuery('#month').val();
				to = jQuery('#year-to').val() + '' + jQuery('#month-to').val();
			
				if(parseInt(to) < parseInt(from)) {
					jQuery("#info-msg").html('<div class="info-msg">Invalid entry for employment period.</div>');
					return false;
				}
			}
		}
	});
	
	cur_msg = jQuery("#info-msg").html();
	
	if(cur_msg != '') {
		return false;
	} else {
		return true;
	}
}

function validate_passwords(password1, password2) {
	if(password1 != password2) {
		jQuery("#info-msg").html('<div class="info-msg">Passwords did not match</div>');
		return false;
	}
	return true;
}

