$(function(){

	$(".IE6 #gnav li, .IE6 #lnav li").hover(function(){$(this).addClass('hover');}, function(){$(this).removeClass('hover');});
	$('#gnav li, #lnav li').css('cursor','pointer').click(function(e){
		e.stopPropagation(); 
			 if(this.firstChild.href.match(/javascript:spanish()/)) spanish(); 
		else if(this.firstChild.href.match(/javascript:english()/)) english(); 
		else if(this.firstChild.href)window.location=this.firstChild.href;});
	$("a[rel=external]").live("click", function(){this.target="_blank"});



	var popups = new Array();
	$(".PhotoGallery ul a").each(function(){ popups.push(new Image());popups[popups.length-1].src=this.href;}).live("click",function(){
		$("#body .wysiwyg").hide();
		$("#right").hide();
		$(".PhotoGallery ul").hide();
		$("#body").css("width","600px");
		$(this).closest(".PhotoGallery").prepend("<img src='"+this.href+"' alt='' class='bigimg' /><span class='body bigimg'>"+$(this).siblings("span.body").text()+"</span>");
		return false;
	});
	$(".PhotoGallery .bigimg").live("click",function(){
		$("#body .wysiwyg").show();
		$("#right").show();
		$(".PhotoGallery ul").show();
		$("#body").css("width","");
		$(".bigimg").remove();
		return false;
	});
	$(".PhotoGallery .links .link").live("click", function(){
		$(".PhotoGallery .showing").removeClass("showing");
		$(".PhotoGallery .image"+$(this).text()).addClass("showing");
		if($(".bigimg").length > 0){
			$(".bigimg").remove();
			$(this).closest(".PhotoGallery").prepend("<img src='"+$(".PhotoGallery .image"+$(this).text() + " a").attr("href")+"' alt='' class='bigimg' /><span class='body bigimg'>"+$(".PhotoGallery .image"+$(this).text() + " a").siblings("span.body").text()+"</span>");
		}
		return false;
	});
	$(".PhotoGallery .links .next").click(function(){
		var showing = $(".PhotoGallery .links .showing");
		if(showing.next('.link').length > 0 )
			showing.next().click();
		else
			$(".PhotoGallery .links .link").eq(0).click();
		return false;
	});
	$(".PhotoGallery .links .back").click(function(){
		var showing = $(".PhotoGallery .links .showing");
		if(showing.prev('.link').length > 0 )
			showing.prev().click();
		else
			$(".PhotoGallery .links .link").eq($(".PhotoGallery .links .link").length-1).click();
		return false;
	});
	$("a[rel=popup]").each(function(){ popups.push(new Image());popups[popups.length-1].src=this.href;}).live("click", function(){
		pic1= new Image();pic1.src=this.href;
		try{popup.close();} catch(e){}
		popup = window.open("","popup","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width="+pic1.width+", height="+pic1.height);
		$(popup.document.body).html("<img src='"+this.href+"' alt=''/>").css("margin",0);
		return false;
	});

});

function spanish(){
	var uri = window.location.href;
	if(window.location.href.split(basedir + "en/").length > 1)
		window.location = basedir + "es/" + window.location.href.split(basedir + "en/")[1];
}function  english(){
	var uri = window.location.href;
	if(window.location.href.split(basedir + "es/").length > 1)
		window.location = basedir + "en/" + window.location.href.split(basedir + "es/")[1];
}

function validate_services(){
	
		if( $('#name').val().length < 1 ){
			window.alert("You must enter a value for the field 'Name'");
			return false;
		}
		if( $('#phone').val().length < 1 ){
			window.alert("You must enter a value for the field 'Phone'");
			return false;
		}
		if( $('#email').val().length < 1 ){
			window.alert("You must enter a value for the field 'Email'");
			return false;
		}
		if( ! $('#email').val().match(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i) ){
			window.alert("The Email address you entered is not a valid email address.");
			return false;
		}
	}

function validate_contact(){
	
		if( $('#name').val().length < 1 ){
			window.alert("You must enter a value for the field 'Name'");
			return false;
		}
		if( (!$('#Interested_In_Making_Reservation').get(0).checked) && (!$('#Interested_In_Adding_Services').get(0).checked) && 	(!$('#Add_Me_To_eNewsletter').get(0).checked) && (!$('#Interested_In_Other').get(0).checked) ){
			window.alert("You must enter a value for the field 'I am interested in'");
			return false;
		}
		if( $('#phone').val().length < 1 ){
			window.alert("You must enter a value for the field 'Phone'");
			return false;
		}
		if( $('#email').val().length < 1 ){
			window.alert("You must enter a value for the field 'Email'");
			return false;
		}
		if( ! $('#email').val().match(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i) ){
			window.alert("The Email address you entered is not a valid email address.");
			return false;
		}
		if( $('input[name=Heard_about_LVN_from]:checked').length < 1 ){
			window.alert("You must enter a value for the field 'I heard about La Vida Nica / Gran Pacifica Resort from'");
			return false;
		}
	}



