var barleft = null;
var barwidth = null;
var returnleft = null;
var returnwidth = null;
var frame = null;
var nextframe = frame + 1;
var start_frame = null;
var end_frame = null;
var delay = null;
var switch_image = null;
var header_color = null;
var text_location = null;
var direction = "out";
var weather_direction = "out";
var newCity = null;
var oldCity = null;
var buttonNum = null;
var google_map = null;
var transition = null;
var pageTitle = null;

function ChangePhoto (oldimg, newimg) {

   document.images[oldimg].src=newimg;

}
function overBar(barleft, barwidth){
	new Effect.Morph(
		"navline_over",
		{style: 'left:' +barleft+'px; width: ' +barwidth+'px;', duration: 0.4});
}

function returnBar(returnleft, returnwidth){
	new Effect.Morph(
		"navline_over",
		{style: 'left:' +returnleft+'px; width: ' +returnwidth+'px;', duration: 0.4});
}

function rickrolled(){
	new Effect.Morph(
	"rickroll_div",
	{style: 'top: -150px; height: 120%; width: 100%; z-index:1000; background: #ccc;', duration: 0.2});
}


function open_gallery(start_frame, end_frame) {
	Effect.Appear('gallery_container');
	start_slideshow(start_frame, end_frame, 4000);	
	frame = 1;
	transition = 1;
}

function open_gallery(start_frame, end_frame) {
	new Effect.Appear('gallery_container');
	transition = 1;
	start_slideshow(start_frame, end_frame, 4000);	
}

function fadeOld() {
	Effect.Fade('image' + (frame -1));
}

function ChangeImage(frame, start_frame, end_frame, delay) {
	return (function() {
		Effect.Fade('image' + frame);
		if (frame == end_frame) { 
			new Effect.Fade('gallery_container');
			clearTimeout ( galleryTimeout );
			start_frame = 1;
			frame = 1;
		} else { frame = frame + 1; }
		switch(transition) {
				case 1:
				Effect.Appear('image' + frame, {afterFinish: fadeOld }); 
				transition = 2;
				break;
				
				case 2:
				Effect.BlindDown('image' + frame, {afterFinish: fadeOld });
				transition = 1;
				break;
		}
		galleryTimeout = setTimeout(ChangeImage(frame, start_frame, end_frame, delay), delay + 150);
	})
}

function start_slideshow(start_frame, end_frame, delay) {
	frame = 1;
	galleryTimeout = setTimeout(ChangeImage(frame, start_frame, end_frame, delay), delay);
	//ChangeImage(start_frame,start_frame,end_frame, delay);
}

function slide_content(text_location) {
	if ((pageTitle == "location") && (google_map == "no")) {
		google_map = "yes";
		document.getElementById('location_link').style.display="none";
		document.getElementById('google_link').style.display="inline";
	}
	else if ((pageTitle == "location") && (google_map == "yes")) {
		document.getElementById('location_link').style.display="inline";
		document.getElementById('google_link').style.display="none";
	}
	if (weather_direction == "in") {
		slide_weather(text_location);
	}
	if (direction == "out") {
		direction = "in";
		if (text_location == "map") {
			google_map = "yes";
		} else {
			document.getElementById('slider_button').innerHTML = 'Hide';
		}
		Effect.Appear('slider_bg');
		if ((text_location == "right") || (text_location == "map")) {
			Effect.MoveBy('slider_container_outer', 0, -689);
			document.getElementById('slider_container').style.zIndex=10;
			document.getElementById('slider_container_outer').style.zIndex=10;
			
		} else {
			Effect.MoveBy('slider_container_outer', 0, 689);
						document.getElementById('slider_container').style.zIndex=1500;
						document.getElementById('slider_container_outer').style.zIndex=1500;

		}
	} else {
		direction = "out";
		if (text_location == "map") {
			document.getElementById('slider_button').innerHTML = 'View Location Map';
			google_map = "yes";
		} else {
			document.getElementById('slider_button').innerHTML = 'View';
		}
		Effect.Fade('slider_bg');
		if ((text_location == "right") || (text_location == "map")) {
			Effect.MoveBy('slider_container_outer', 0, 689);
									document.getElementById('slider_container').style.zIndex=1500;
									document.getElementById('slider_container_outer').style.zIndex=1500;

		} else {
			Effect.MoveBy('slider_container_outer', 0, -689);
						document.getElementById('slider_container').style.zIndex=10;
						document.getElementById('slider_container_outer').style.zIndex=10;

		}
	}
}

function slide_weather(text_location) {
	if (direction == "in") {
		slide_content(text_location);
		}
	if (weather_direction == "out") {
		weather_direction = "in";
		document.getElementById('weather_button').innerHTML = 'Hide';
		Effect.Appear('weather_bg');
		if (text_location == "right") {
			Effect.MoveBy('weather_container', 0, -689);
			document.getElementById('weather_frame_right').style.zIndex=15;
		} else {
			Effect.MoveBy('weather_container', 0, 689);
			document.getElementById('weather_frame_left').style.zIndex=15;
		}
	} else {
		weather_direction = "out";
		document.getElementById('weather_button').innerHTML = 'View';
		Effect.Fade('weather_bg');
		if (text_location == "right") {
			Effect.MoveBy('weather_container', 0, 689);
			document.getElementById('weather_frame_right').style.zIndex=10;
		} else {
			Effect.MoveBy('weather_container', 0, -689);
			document.getElementById('weather_frame_left').style.zIndex=10;
		}
	}
}

function changeCity(newCity, oldCity, buttonNum) {
	document.getElementById('cityButton' + buttonNum).innerHTML = oldCity;
}

function confirmSubmit() {
	Effect.Fade('slider_content');
	Effect.Appear('slider_confirmation');
}
function swapRealestate() {
	Effect.Fade('real_estate_main');
	Effect.Fade('more_button');
	Effect.Appear('real_estate_page');
}



/*===================================*/
// FORM HANDLER AND VERIFICATION STUFF
/*===================================*/
function sndForm(frm) {
	
	var url = 'includes/cf_process.php';
	var pars = Form.serialize(frm);
	var myAjax = new Ajax.Request( 
		url, {
				method: 'post', 
				parameters: pars, 
				//onLoading: function() {
				//				$('cload').show();
				//			}, 
				onSuccess: function(transport) {
					if (transport.responseText.match(/OK/)) {
							var Holder = $('cform');
							new Ajax.Updater(Holder, 'thankyou.html');
					} else {
						alert(transport.responseText);
						return false;
					}
				}
			 } 
	);
}