 function sm_CheckEmailFormat(fieldValue)
            { //reference to email field passed as argument

            // Begin Valid Email Address Tests

            //if field is not empty
            if(fieldValue != ""){
                    var atSymbol = 0

                    //loop through field value string
                    for(var a = 0; a < fieldValue.length; a++){

                            //look for @ symbol and for each @ found, increment atSymbol variable by 1
                            if(fieldValue.charAt(a) == '@'){
                                    atSymbol++
                            }

                    }

                    // if more than 1 @ symbol exists
                    if(atSymbol > 1){
                            // then cancel and dont submit form
                            return false
                    }

                    // if 1 @ symbol was found, and it is not the 1st character in string
                    if(atSymbol == 1 && fieldValue.charAt(0) != '@'){
                            //look for period at 2nd character after @ symbol
                            var period = fieldValue.indexOf('.',fieldValue.indexOf('@')+2)

                            // '.' immediately following 1st '.' ?
                            var twoPeriods = (fieldValue.charAt((period+1)) == '.') ? true : false

                            //if period was not found OR 2 periods together OR field contains less than 5 characters OR period is in last position
                            if(period == -1 || twoPeriods || fieldValue.length < period + 2 || fieldValue.charAt(fieldValue.length-1)=='.'){
                                    // then cancel and dont submit form
                                    return false
                            }
                    }

                    // no @ symbol exists or it is in position 0 (the first character of the field)
                    else{
                            // then cancel and dont submit form
                            return false
                    }
            }
            // if field is empty
            else{
                    // then cancel and dont submit form
                    return false
            }

            //all tests passed, submit form
            return true
            }
     function sm_validateform(){
     	var emailID=document.frmSample.sm_email
     	if ((emailID.value==null)||(emailID.value=='')){
     		alert('Please check your email address.')
     		emailID.focus()
     		return false
     	}
     	if (sm_CheckEmailFormat(emailID.value)==false){
     		alert('Please check your email address.')
     		emailID.value=''
     		emailID.focus()
     		return false
     	}
     	return true
      }


(function(){
	var 
		foldingMenu = window.foldingMenu = function( eventype,method,elems ) {
			method = method.split("|");
			elems = elems.split(",");
			eTree = method[1].split(",");
			switch (method[0]) {
				case "parent":
					return new foldingMenu.initp( eventype,elems,eTree );
					break;
				case "sibling":
					return new foldingMenu.inits( eventype,elems,eTree );
					break;
				case "direct":
					return new foldingMenu.initd( eventype,elems,eTree );
					break;
				default:
					alert("It's borked.");
			}
		};

	foldingMenu = foldingMenu.prototype = {
		initp: function( eventype,elems,eTree ) {
			var actioner = " " + eTree[0];
			var submenu = " " + eTree[1];
			for (i=0;i<elems.length;i++) {
				$(elems[i] + actioner).each(function(e){
					var thiswidth = $(this).width();
					var thischildwidth = $(this).children(submenu).width();
					if (thiswidth > thischildwidth) {
						$(this).children(submenu).css({width: thiswidth});
					} else {
						$(this).children(submenu).css({width: thischildwidth});
					}
					var thisfinalwidth = $(this).children(submenu).width();
					$(this).children(".submenu").children("ul").children("li").children("a").css({width: thisfinalwidth-24});
					$(this).children(".submenu").children(".menu_bottom").children(".bottom").css({width: thisfinalwidth-14});
				});
				$(elems[i] + actioner + submenu).hide();
				$(elems[i] + " .open").each(function() {
					var tag_type = this.tagName;
					if (this.tag_type != "A") { $(this).show(); }
				});
				$(elems[i] + " .open").parents(submenu).show();
				$(elems[i] + actioner + submenu + ":visible").parent().children("a").addClass("sub_parent expanded");
				$(elems[i] + actioner + submenu + ":hidden").parent().children("a").addClass("sub_parent");
				switch (eventype) {
					case "click":
						$(elems[i] + actioner + submenu).parent().children("a").click(function() {
							$(this).next(submenu).toggle("fast");
							$(this).toggleClass("expanded").blur();
							return false;
						});
						break;
					case "hover":
						$(elems[i] + actioner + submenu).parent().hover(function() {
							onLink = 1;
							curSub = $(submenu).index($(this).children(submenu));
							$(this).siblings().removeClass("curHover");
							$(this).addClass("curHover");
							$(this).children(submenu).slideDown(1,	function(e){
																		if(onLink == 0) {
																			$(submenu + ":eq(" + curSub + ")").hide();
																		}
																		$(this).parent().siblings(":not(.curHover)").children(submenu).hide();
																	});
							$(this).children("a").toggleClass("expanded");
						}, function() {
							onLink = 0;
							$(this).removeClass("curHover");
							$(this).children(submenu).hide();
							$(this).children("a").toggleClass("expanded");
						});
						break;
				}
			}
		},

		inits: function( eventype,elems,eTree ) {
			var actioner = " " + eTree[0];
			var submenu = " " + eTree[1];
			for (i=0;i<elems.length;i++) {
				$(elems[i] + submenu).hide();
				$(elems[i] + " .open").each(function() {
					var tag_type = this.tagName;
					if (this.tag_type != "A") { $(this).show(); }
				});
				$(elems[i] + " .open").parents(submenu).show();
				$(elems[i] + submenu + ":visible").prev(actioner).children("a").addClass("sub_parent expanded");
				$(elems[i] + submenu).prev(actioner).children("a").addClass("sub_parent");
				switch (eventype) {
					case "click":
						$(elems[i] + submenu).prev(actioner).click(function() {
							$(this).next(submenu).toggle("fast");
							$(this).children("a").toggleClass("expanded").blur();
							return false;
						});
						break;
					case "hover":
						$(elems[i] + submenu).prev(actioner).hover(function() {
							$(this).next(submenu).show("fast");
							$(this).children("a").toggleClass("expanded");
						}, function() {
							$(this).next(submenu).hide();
							$(this).children("a").toggleClass("expanded");
						});
						break;
				}
			}
		},
		
		initd: function( eventype,elems,eTree ) {
			var expander = " " + eTree[0];
			var submenu = " " + eTree[1];
			
		}
	}
})();

function initCorners(elem) {
	$(elem + " ul ul a").append('<span class="corner tl"></span><span class="corner tr"></span><span class="corner bl"></span><span class="corner br"></span><span class="bar top"></span><span class="bar right"></span><span class="bar bottom"></span><span class="bar left"></span>');
	$(elem + " .menu_bottom").append('<span class="corner bl"></span><span class="bar bottom"></span><span class="corner br"></span>');
}

     var imgoing = 1;    
     step = 2;
     what2scroll = "#slider";
     
     function startScroll(direction){
          switch(direction){
              case "up":
              
              break;
              case "down":
              
              break;
              case "left":
                  currentpos = $("#slider").scrollLeft();
                  newpos = currentpos - step;
                  $("#slider").scrollLeft(newpos); 
                  
              break;
              case "right":
                  currentpos = $("#slider").scrollLeft();
                  newpos = currentpos + step;
                  $("#slider").scrollLeft(newpos); 
              break;
              default:
              break;
          }
          
          timer = setTimeout("startScroll(\"" + direction + "\")", 0);
     }
     function stopScroll(){
          clearTimeout(timer);
     }

$(document).ready(function() {
	var hash = window.location.hash;
	var path = window.location.pathname;
	
	if(path == "/" || path == "/index.php" || path == "/test-homepage/") {
		var hpflipInterval = 0;
		hpflipIntervalSet();
		
		hpflippages = 1;
		$("#hpflip_pages_wrapper .hpflip_page").each(function(){
			var thisid = "page" + hpflippages;
			$(this).attr("id",thisid);
			hpflippages++;
		});
		hpflippages = 1;
		$(".hpflip_linkbar a").each(function(){
			var thisid = "link" + hpflippages;
			$(this).attr("id",thisid);
			hpflippages++;
		});
		$("#list_scroller br").remove();
		$(".hpflip_linkbar .list").prepend("<table id=\"gallery_list_table\"><tbody><tr id=\"gallery_list_row\"></tr></tbody></table>");
		for(x=1;x<hpflippages;x++){
			$("#gallery_list_row").append("<td id=\"tableblock" + x + "\"></td>");
			$("#tableblock" + x).append($("#link" + x));
		}
		$(".hpflip_linkbar .list").scrollLeft(0);
		if (hpflippages <= 4) {
			$(".hpflip_linkbar_scroller").css({"opacity" : 0});
		}
		
		$(".hpflip_linkbar a").click(function() {
			var switchpage = "#page" + this.id.substr(4);
			if (!($(switchpage).is(":visible"))) {
				hpflipIntervalClear();
				$(".hpflip_page:visible").fadeOut("slow");
				$(".hpflip_page" + switchpage).fadeIn("slow");
				highlightThumb(this,"thumb_selected");
				this.blur();
				return false;
			} else {
				if (imgoing == 1) {
					hpflipIntervalClear();
					this.blur();
					return false;
				} else {
					return true;
				}
			}
		});
		
		$("#hpflip_control a").click(function(){
			hpflipClickHandler(this);
			return false;
		});
		$(".hpflip_linkbar_scroller").click(function(){
			hpflipClickHandler(this);
			return false;
		});
		
		$(".hpflip_page img").click(function() {
			var rawid = $(this).closest(".hpflip_page").attr("id");
			var getindex = rawid.substr(4);
			var geturl = $(".hpflip_linkbar #link" + getindex).attr("href");
			window.location = geturl;
		});
		
		$(".hpflip_linkbar #link1").addClass("thumb_selected");
		$(".hpflip_page:not(#page1)").hide();
	}
	
	$("#content-wrapper").append("<div id=\"fader\" style=\"background:url(/transback_black.png); position:absolute; top:0px; left:0px; width:100%; height:100%; display:none;\"></div>");
	$("#fader").click(function(){
		$(".fadetoggle").click();
	});
	$(".cancel_invite a").click(function(){
		$(".fadetoggle").click();
		return false;
	});

 $("#invite_button a.fadetoggle").click(function(){
	 
	if ($("#bigger_invitebox").is(":visible")) {
		$("#bigger_invitebox").fadeOut("normal").next().css({width : "250px"});
		$(this).children(".closed").hide();
		$(this).children(".open").fadeIn("fast");
		$("#fader").fadeOut(1000);
	} else {
		$("#bigger_invitebox").fadeIn("normal");
		$(this).children(".open").hide();
		$(this).children(".closed").fadeIn("fast").parent().css({width : "16px"});
		$("#fader").fadeIn("fast");
		var testing = ($("#useless_deco").attr("style") == "") ? 1 : 0;
		if (testing == 0) {
			var boxheight = $("#bigger_invitebox").height();
			$("#useless_deco").css({"top" : boxheight+20});
		}
	}
     
	if ($("input#yourname").attr("value") == "") {
		$("input#yourname").focus();
	} else {
		$("input#yourname").select();
	}
     
     return false;
 });

     $("form#inviteform").submit(function(){
       $.post("http://www.fox-hills.com/send_invite.php",{
             yourname: $("#yourname").val(),
             youremail: $("#youremail").val(),
             theirname: $("#theirname").val(),
             theiremail: $("#theiremail").val(),
             personalmessage: $("#personalmessage").val(),
             c: jQuery.url.param("c"),
             i: jQuery.url.param("i")
           }, function(xml) {
       //alert(xml);
              if(!($("#invite_form").hasClass("hide"))){
                   $("#invite_form").addClass("hide");
                   $("#biginviteloading").removeClass("hide");
              }
       //alert("HERE!");
              processRequest(xml);
           });
       return false;
     });
     
     function processRequest(xml){
       //alert("HERE!");
          $("#bigger_invitebox input").css("border-bottom","1px solid #889977");
          if($("status",xml).text() == "1"){
              $("#biginviteloading").addClass("hide");
              $("#invite_message").removeClass("hide");
              
              $("#bigger_invitebox input").css("border-bottom","1px solid #889977");
          }
          else{
              $("#biginviteloading").addClass("hide");
              $("#invite_form").removeClass("hide");
              
              $("missing",xml).each(function(id) {
                  blah = $("missing",xml).get(id);
                  thisname = $(blah).text();
                  
                  $("input#" + thisname).css("border-bottom","1px solid red");
               }); 
              
              $("format",xml).each(function(id) {
                  blah = $("format",xml).get(id);
                  thisname = $(blah).text();
                  
                  $("input#" + thisname).css("border-bottom","1px solid red");
               }); 
          }
     }
     
     $("a#another_invite").click(function(){
         $("#yourname").val("");
         $("#youremail").val("");
         $("#theirname").val("");
         $("#theiremail").val("");
         $("#personalmessage").val("");
          
         $("#invite_message").addClass("hide");
         $("#invite_form").removeClass("hide");
         return false;
     });
     
     $("#image_row img").mouseover(function(){
          $("#large_image").attr("src", $(this).attr("src").replace("thumb", "large"));
     });
     
     $("#image_row #right_arrow").mouseover(function(){
          startScroll("right");
     });
     $("#image_row #right_arrow").mouseout(function(){
          stopScroll();
     });
     $("#image_row #left_arrow").mouseover(function(){
          startScroll("left");
     });
     $("#image_row #left_arrow").mouseout(function(){
          stopScroll();
     });
	 
	initCorners("#nav-wrapper");
	foldingMenu("hover","parent|li,div.submenu","#nav-wrapper");

});

function toggle(elem) {
	var liclass = elem.className;
	if (liclass == "closed") { elem.className = "open"; } else { elem.className = "closed"; }
}

function hpflipClickHandler(elem) {
	var animstat = $("#homepage_flipper").attr("class");
	var scroller = ($(elem).hasClass("hpflip_linkbar_scroller"));
	if (animstat == "playing" || scroller == true) {
		hpflipIntervalClear();
	} else {
		var starting = hpflipCenter();
		hpflipNext(starting);
		hpflipIntervalSet();
		imgoing = 1;
	}
	if (scroller == true) {
		var scrolldirec = $(elem).attr("id").replace("s_","");
		hpflipScroll(scrolldirec,3,false);
	}
	elem.blur();
}

function hpflipIntervalSet() {
	hpflipInterval = setInterval("hpflipNext(0)", 5000 );
	$("#homepage_flipper").attr("class","playing");
	imgoing = 1;
}

function hpflipIntervalClear() {
	imgoing = 0;
	clearInterval(hpflipInterval);
	$("#homepage_flipper").attr("class","stopped");
}

function hpflipNext(starting) {
	var totalpage = $(".hpflip_page").length;
	var curpage = $(".hpflip_page:visible").attr("id");
	var switchpage = parseInt(curpage.substr(4));
	switchpage++;
	if (switchpage > totalpage) { switchpage = 1;}
	var getpage = "#page" + switchpage;
	$(".hpflip_page:visible").fadeOut("slow");
	$(".hpflip_page" + getpage).fadeIn("slow");
	highlightThumb($("#link" + switchpage),"thumb_selected");
	var reset = (switchpage <= 2 || starting != 0) ? true : false;
	var resetto = (switchpage <= 2) ? 0 : starting;
	hpflipScroll("right",1,reset,resetto);
}

function hpflipScroll(direc,dist,reset,resetto) {
	var curscroll = $(".hpflip_linkbar .list").scrollLeft();
	toscroll = (direc == "right") ? (104*dist) : 0-(104*dist);
	goscroll = (reset == true) ? resetto : curscroll+toscroll;
	$(".hpflip_linkbar .list").animate({"scrollLeft":goscroll});
}

function highlightThumb(elem,setclass) {
	$("." + setclass).removeClass(setclass);
	$(elem).addClass(setclass);
}

function hpflipCenter() {
	var curhighlight = parseInt($(".thumb_selected").attr("id").substr(4));
	dist = curhighlight-1;
	return dist*104;
}