
	var current_page;
	var gallery = {
		ids:{
			pic_headshots:"headshots",
			pic_fashion:"fashion",
			pic_promotional:"promotional",
			pic_live:"live",
			pic_artistic:"artistic"
			},
		totals:{
			headshots:19,
			fashion:16,
			promotional:12,
			live:1,
			artistic:29		},
		current: "",
		page:1,
		page_max:12,
		pages:1,
		remainder:0
	}
	var about = {
		ids: {
			pic_note: "note",
			pic_expect: "expect",
			pic_shoot: "shoot",
			pic_pricing: "pricing",
			pic_street: "street"
			},
		current: ""
	}
	var nav = {
		nav_vars:[]
	}
	var subnav = {
		subnav_gallery_vars:[],
		subnav_about_vars:[]
	}
	var pics = {}
	
	var Pic = Class.create({
		initialize: function(o, source, thumb_source, thumb_position, pic_target, set_id, callback){
			if(!set_id){set_id=null;}
			if(!callback){callback=null;}
			this.var_name=o;
			this.target = pic_target;
			this.thumb_position = thumb_position;
			this.source = source;
			this.thumb_src = thumb_source;
			this.thumb = Builder.node("img", {src:thumb_source, onclick:o+".swap("+o+");"});
			if(set_id){this.thumb.id = set_id;}
			Element.insert(thumb_position, this.thumb);
			if(callback == "load_content"){Event.observe(this.target, 'click', load_content);}
			if(callback == "load_gallery"){Event.observe(this.target, 'click', load_gallery);}
			if(callback == "load_about"){Event.observe(this.target, 'click', load_about);}
			this.preload();
		},
		preload: function(){
			this.pic = new Image();
			this.pic.loaded = 0;
			this.pic.onload = this.ready;
			this.pic.onerror = this.fail;
			this.pic.onabort = this.fail;
			this.pic.src = this.source;
		},
		ready: function(){
			this.loaded = 1;
		},
		fail: function(){
			this.loaded = 2;
		},
		swap: function(o){
			Effect.Pulsate(o.thumb_position, {pulses:1, from:.7, duration:.5});
			if(o.pic.loaded == 1){
				var t = $(o.target);
				t.fade({duration:.4, queue:{position: 'end', scope: 'center_image_queue'}});
				setTimeout(function(){
					t.width=1;
					t.height=1;
					t.src=o.pic.src;
					t.width=o.pic.width;
					t.height=o.pic.height;
					t.appear({duration:.5, queue:{position: 'end', scope: 'center_image_queue'}});
				}, 400);
			}
			else if (o.pic.loaded == 2){$(o.target).src="";}
			else setTimeout(o.var_name + ".swap(" + o.var_name + ");", 500);
		}
	});
	
	var navPic = Class.create(Pic,{
		swap: function(){
			for(var i = 0; i<nav.nav_vars.length; i++){
				$(nav.nav_vars[i].target).src=nav.nav_vars[i].thumb_src;
			}
			$(this.target).src=this.source;
		}
	});
	
	var subnavGalleryPic = Class.create(Pic,{
		swap: function(){
			for(var i = 0; i<subnav.subnav_gallery_vars.length; i++){
				$(subnav.subnav_gallery_vars[i].target).src=subnav.subnav_gallery_vars[i].thumb_src;
			}
			$(this.target).src=this.source;
		}
	});
	
	var subnavAboutPic = Class.create(Pic,{
		swap: function(){
			for(var i = 0; i<subnav.subnav_about_vars.length; i++){
				$(subnav.subnav_about_vars[i].target).src=subnav.subnav_about_vars[i].thumb_src;
			}
			$(this.target).src=this.source;
		}
	});
	
	function load_content(event){
		elem = Event.element(event);
		fade_others(".subnav", "subnav_queue");
		switch(elem.id){
			case "pic_portfolio":
				this_page = "portfolio";
				$('subnav_portfolio').appear({duration:.5, queue:{position:'end', scope:'subnav_queue'}});
				break;
			case "pic_about":
				this_page = "about";
				$('subnav_about').appear({duration:.5, queue:{position:'end', scope:'subnav_queue'}});
				break;
			case "pic_contact":
				this_page = "contact";
				break;
			case "pic_news":
				this_page = "news";
				break;
			case "pic_home":
				this_page = "home";
				break;
		}
		if(this_page != current_page){
			pageTracker._trackPageview("/"+this_page);
			fade_others(".content");
			current_page = this_page;
			$(current_page).appear({duration:.75, queue:{position: 'end', scope: 'content_queue'}});
		}
	}
	
	function load_gallery(event){
		if(typeof(event) == "object"){
			gallery.page = 1;
			elem = Event.element(event);
			this_gallery = gallery.ids[elem.id];
		}
		else{this_gallery = event;}
		pageTracker._trackPageview("/"+this_gallery);
		fade_others('.content', 'gallery_queue');
		gallery.current = this_gallery;
		gallery.pages = Math.ceil(gallery.totals[gallery.current]/gallery.page_max);
		gallery.remainder = gallery.totals[gallery.current] % gallery.page_max;
		setTimeout(function(){
		var table_left = $('thumbs_left_table')
		table_left.childElements().each(function(s){s.remove();});
		table_left.insert({bottom:write_thumbs(this_gallery, "left", 1+12*(gallery.page-1), 6+12*(gallery.page-1))});
		var table_right = $('thumbs_right_table')
		table_right.childElements().each(function(s){s.remove();});
		table_right.insert({bottom:write_thumbs(this_gallery, "right", 7+12*(gallery.page-1), 12*(gallery.page))});
		temp_int = setInterval(function(){
			if($H(pics).all(function(n){return $H(n).get("1").pic.loaded;})){
				$("arrow_left_container").style.display="none";
				$("arrow_right_container").style.display="none";
				if (gallery.pages > 1 && gallery.page != gallery.pages){
					var g = gallery.page + 1;
					$("arrow_num_right").src = "images/" + g + "white.png";
					$("arrow_right_container").style.display="block";
				}
				if (gallery.pages > 1 && gallery.page != 1){
					var g = gallery.page - 1; 
					$("arrow_num_left").src = "images/" + g + "white.png";
					$("arrow_left_container").style.display="block";
				}
				var c = $('center_img');
				var b = pics[gallery.totals[gallery.current] - ((gallery.page-1)*gallery.page_max)];
				c.width=1;
				c.height=1;
				c.src = b.pic.src;
				c.width=b.pic.width;
				c.height=b.pic.height;
				$('portfolio').appear({duration:.5, queue:{position: 'end', scope: 'gallery_queue'}});
				clearInterval(temp_int);
				}
			}, 250);
		}, 450);
	}
	
	function load_about(event){
		elem = Event.element(event);
		this_about = about.ids[elem.id];
		if(this_about != about.current){
			pageTracker._trackPageview("/"+this_about);
			fade_others('.about', 'about_queue');
			setTimeout(function(){
				$(about.current).toggle();
				$(this_about).toggle();
				about.current = this_about;
				$('about').appear({duration:.5, queue:{position: 'end', scope: 'about_queue'}});
			}, 600);
		}
	}

	function fade_others(class_name, queue_name){
		if(!queue_name){queue_name = 'content_queue';}
		var a = $$(class_name);
		var prev=false;
		for (var x = 0; x < a.length; x++){
			if (a[x].style.display != "none"){prev = true; a[x].fade({duration:.4, queue:{position: 'end', scope: queue_name}});}
		}
	}
	

	function write_thumbs(this_gallery, side, start, end){
		var i = start - (gallery.page-1)*12;
		if(end > gallery.totals[this_gallery]){end = gallery.totals[this_gallery]};
		$('thumbs_'+side+'_table').insert({bottom:Builder.node("ul", {id: 'thumbs_'+side})});
		for(var s= gallery.totals[this_gallery] - (start-1); s > gallery.totals[this_gallery] - end; s--){
			var this_script = "<script>pics["+s+"] = new Pic('pics["+s+"]', 'photos/"+this_gallery+"/"+s+".jpg', 'photos/"+this_gallery+"/thumb-"+s+".jpg', 'thumb"+s+"', 'center_img');<\/script>";
			$('thumbs_'+side).insert(Builder.node("li", {id:"thumb"+s},
				Builder.node("div", {id:"thumb_number_"+s, className:"thumb_number float_opposite_"+side},
				Builder.node("img", {src:"images/"+i+".png"}, '')
				))
			);
			$('thumbs_'+side).insert({bottom:this_script});
			i++;
		}
	}
	
	Event.observe(window, 'load', function(){
		if(BrowserDetect.browser == "Explorer" && BrowserDetect.version < 7){
			$('header').insert({before:Builder.node('p', "Please update your copy of Internet Explorer to version 7 or later to view this site.")});
		}
		else{
			$('header').appear({duration:1});
			current_page = "home";
			gallery.current = "headshots";
			about.current = "note";
			nav_pic_home = new navPic('nav_pic_home', 'images/wptitle.png', 'images/wptitle.png', 'nav_home', 'pic_home', 'pic_home', "load_content");
			nav_pic_news = new navPic('nav_pic_news', 'images/newsgrn.png', 'images/news.png', 'nav_news', 'pic_news', 'pic_news', "load_content");
			nav_pic_portfolio = new navPic('nav_pic_portfolio', 'images/portfoliogrn.png', 'images/portfolio.png', 'nav_portfolio', 'pic_portfolio', 'pic_portfolio', "load_content");
			nav_pic_about = new navPic('nav_pic_about', 'images/aboutgrn.png', 'images/about.png', 'nav_about', 'pic_about', 'pic_about', "load_content");
			nav_pic_contact = new navPic('nav_pic_contact', 'images/contactgrn.png', 'images/contact.png', 'nav_contact', 'pic_contact', 'pic_contact', "load_content");
			nav.nav_vars = [nav_pic_home, nav_pic_news, nav_pic_portfolio, nav_pic_about, nav_pic_contact];
			temp_int = setInterval(function(){
						if(nav_pic_contact.pic.loaded){
							$('nav').appear({duration:.75});
							clearInterval(temp_int);
						}
					}, 250);
			nav_pic_headshots = new subnavGalleryPic('nav_pic_headshots', 'images/headshotson.png', 'images/headshots.png', 'nav_headshots', 'pic_headshots', 'pic_headshots', "load_gallery");
			nav_pic_fashion = new subnavGalleryPic('nav_pic_fashion', 'images/fashionon.png', 'images/fashion.png', 'nav_fashion', 'pic_fashion', 'pic_fashion', "load_gallery");
			nav_pic_artistic = new subnavGalleryPic('nav_pic_artistic', 'images/artisticon.png', 'images/artistic.png', 'nav_artistic', 'pic_artistic', 'pic_artistic', "load_gallery");
			nav_pic_live = new subnavGalleryPic('nav_pic_live', 'images/liveon.png', 'images/live.png', 'nav_live', 'pic_live', 'pic_live', "load_gallery");
			nav_pic_promotional = new subnavGalleryPic('nav_pic_promotional', 'images/promotionalon.png', 'images/promotional.png', 'nav_promotional', 'pic_promotional', 'pic_promotional', "load_gallery");
			nav_pic_note = new subnavAboutPic('nav_pic_note', 'images/aboutrandyllon.png', 'images/aboutrandyll.png', 'nav_note', 'pic_note', 'pic_note', "load_about");
			//nav_pic_street = new subnavAboutPic('nav_pic_street', 'images/wordstreeton.png', 'images/wordstreet.png', 'nav_street', 'pic_street', 'pic_street', "load_about");
			nav_pic_shoot = new subnavAboutPic('nav_pic_shoot', 'images/theshooton.png', 'images/theshoot.png', 'nav_shoot', 'pic_shoot', 'pic_shoot', "load_about");
			//nav_pic_expect = new subnavAboutPic('nav_pic_expect', 'images/whatexpecton.png', 'images/whatexpect.png', 'nav_expect', 'pic_expect', 'pic_expect', "load_about");
			//nav_pic_pricing = new subnavAboutPic('nav_pic_pricing', 'images/pricingon.png', 'images/pricing.png', 'nav_pricing', 'pic_pricing', 'pic_pricing', "load_about");
			subnav.subnav_gallery_vars = [nav_pic_headshots, nav_pic_fashion, nav_pic_artistic, nav_pic_live, nav_pic_promotional];
			// nav_pic_street, nav_pic_expect,
			subnav.subnav_about_vars = [nav_pic_note, nav_pic_shoot]; // removed , nav_pic_pricing
			nav_pic_headshots.swap();
			nav_pic_note.swap();
			write_thumbs('headshots', "left", 1, 6);
			write_thumbs('headshots', "right", 7, 12);
			init();
		}
	});
	
	function init(){
			if(pics[gallery.totals[gallery.current]] && pics[gallery.totals[gallery.current]].pic.loaded == 1){
				$('center_img').src = pics[gallery.totals[gallery.current] - (gallery.page-1)].pic.src;
				$("arrow_left_container").style.display="none";
				$("arrow_right_container").style.display="none";
				gallery.pages = Math.ceil(gallery.totals[gallery.current]/gallery.page_max);
				gallery.remainder = gallery.totals[gallery.current] % gallery.page_max;
				if (gallery.pages > 1 && gallery.page != gallery.pages){
					var g = gallery.page + 1;
					$("arrow_num_right").src = "images/" + g + "white.png";
					$("arrow_right_container").style.display="block";
				}
				if (gallery.pages > 1 && gallery.page != 1){
					var g = gallery.page - 1; 
					$("arrow_num_left").src = "images/" + g + "white.png";
					$("arrow_left_container").style.display="block";
				}
				$(current_page).appear({duration:.5, queue:{position: 'end', scope: 'content_queue'}});
			}
			else{setTimeout("init()", 250);}
	}

	function submit_contact(){
		if($('error_msg')){$('error_msg').remove();}
		var form = $('contact_form');
		if(form.getElements().all(function(n){return n.present();})){
			if(check_email($F(form['email']))){
				new Ajax.Request('./contact.php',{
				parameters: form.serialize(),
				onSuccess: function(transport){
					if (transport.responseText){
						contact_error("Message sent successfully.")
					}
					else{contact_error("There was an error trying to send the email.<br />You can try sending again, or send an email directly to:<br /> randyll@wendlfulphotography.com");}
				},
				onFailure: function(){
					alert("AJAX Failed!");
				}
			});
			}else{contact_error("Please make sure you have entered a valid email address.");}
		}else{contact_error("Please fill out all fields.");}
	}
	
	function contact_error(message){
	$('contact_form').insert({after:Builder.node('p', {id:'error_msg'}, message)});
	}
	
	function check_email(address) {
	return address.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
	}
	