/* VARS */
var anim_timeout;
var displacement;

var pay_L_clicks = 0;
var pay_L_state = 0;
var joe_R_clicks = 0;
var joe_R_state = 0;
var mel_B_clicks = 0;
var mel_B_state = 0;


//MOVE SECTIONS
function section_click(who) {

	if (who == "joe") {
	 if (joe_R_state == 0) {
			document.getElementById("joe_R_url").onmouseover = "";
			document.getElementById("joe_R_url").onclick = function onclick(event) { section_click('joe'); };
			reset_sections();
			move_joe_left();
			document.body.background = "";
			hide_sections();
		} else {
			document.getElementById("joe_R_url").onmouseover = function onmouseover(event) { section_click('joe'); };
			document.getElementById("joe_R_url").onclick = "";
			reset_sections();
			document.body.background = "images/bk1.jpg";
			show_section([current_section]);

		}

	} else if (who == "pay") {
		if (pay_L_state == 0) {
			document.getElementById("pay_L_url").onmouseover = "";
			document.getElementById("pay_L_url").onclick = function onclick(event) { section_click('pay'); };
			reset_sections();
			move_pay_right();
			document.body.background = "";
			hide_sections();
		} else {
			document.getElementById("pay_L_url").onmouseover = function onmouseover(event) { section_click('pay'); };
			document.getElementById("pay_L_url").onclick = "";
			reset_sections();
			document.body.background = "images/bk1.jpg";
			show_section([current_section]);
		}

	} else if (who == "mel") {
		if (mel_B_state == 0) {
			document.getElementById("mel_B_url").onmouseover = "";
			document.getElementById("mel_B_url").onclick = function onclick(event) { section_click('mel'); };
			reset_sections();
			move_mel_up();
			document.body.background = "";
			hide_sections();
		} else {
			document.getElementById("mel_B_url").onmouseover = function onmouseover(event) { section_click('mel'); };
			document.getElementById("mel_B_url").onclick = "";
			reset_sections();
			document.body.background = "images/bk1.jpg";
			show_section([current_section]);
		}

	}
	document.getElementById('artwork_div').style.display = "none";

}

function reset_sections() {
	if (pay_L_state == 1) {
		move_pay_left();
		document.getElementById("pay_L_url").onmouseover = function onmouseover(event) { section_click('pay'); };
		document.getElementById("pay_L_url").onclick = "";
	}
	if (joe_R_state == 1) {
		move_joe_right();
		document.getElementById("joe_R_url").onmouseover = function onmouseover(event) { section_click('joe'); };
		document.getElementById("joe_R_url").onclick = "";
	}
	if (mel_B_state == 1) {
		move_mel_down();
		document.getElementById("mel_B_url").onmouseover = function onmouseover(event) { section_click('mel'); };
		document.getElementById("mel_B_url").onclick = "";
	}
}


function move_pay_left() {
	move_x_div("pay_L", 0, -190, -1, -1);
	pay_L_clicks++;
	pay_L_state = 0;
}

function move_pay_right() {
	move_x_div("pay_L", -185, 185, -1, -1);
	pay_L_clicks++;
	pay_L_state = 1;
}

function move_joe_left() {
	var start_left = get_x_browser_width();
	move_x_div("joe_R", start_left, -185, "100%", -195);
	joe_R_clicks++;
	joe_R_state = 1;
	set_div_display("artwork_div", "none");
}

function move_joe_right() {
	var start_left = get_x_browser_width() - 185;
	document.getElementById("joe_R").style.margin = "-135px 0 0 -20px";
	move_x_div("joe_R", start_left, 185, -1, -1);
	joe_R_clicks++;
	joe_R_state = 0;
}

function move_mel_up() {
	var start_top = get_x_browser_height();
	move_y_div("mel_B", start_top, -120, "100%", -130);
	mel_B_clicks++;
	mel_B_state = 1;
	set_div_display("artwork_div", "none");
}

function move_mel_down() {
	var start_top = get_x_browser_height() - 110;
	document.getElementById("mel_B").style.margin = "-20px 0 0 -300px";
	move_y_div("mel_B", start_top, 110, -1, -1);
	mel_B_clicks++;
	mel_B_state = 0;
	set_div_display("artwork_div", "none");
}

//X MOVE ENGINE
function move_x_div(div_id, current_left, displacement, css_left, css_margin_left) {
	var the_style = get_obj_style(div_id);  // get the stylesheet

	if (the_style) {

		var new_left;
		//alert(current_left);
		if (displacement < 0) {
			new_left = current_left - 5;
			displacement += 5;
		} else {
			new_left = current_left + 5;
			displacement -= 5;
		}

		// set the left property of the DIV, add px at the
		// end unless this is NN4
		if (document.layers) {
			//alert(the_style.left);
			the_style.left = new_left;
		} else {
			the_style.left = new_left + "px";
		}
		var final_left = current_left + displacement;

		if (new_left > final_left) {
			anim_timeout = setTimeout("move_x_div('" + div_id + "', " + new_left + ", " + displacement + ", '" + css_left + "', " + css_margin_left + ");", 10);
		} else if (current_left < final_left) {
			anim_timeout = setTimeout("move_x_div('" + div_id + "', " + new_left + ", " + displacement + ", '" + css_left + "', " + css_margin_left + ");", 10);
		} else {
			if (css_left != -1) {
				var obj = document.getElementById(div_id);
				obj.style.left = css_left;
				the_style.margin = "-135px 0 0 " + css_margin_left + "px";
			} else {
				if (div_id == "joe_R") {
					var obj = document.getElementById(div_id);
					obj.style.left = "100%";
					the_style.margin = "-135px 0 0 -20px";
				}
			}
		}

	}

}


//Y MOVE ENGINE
function move_y_div(div_id, current_top, displacement, css_top, css_margin_top) {
	var the_style = get_obj_style(div_id);  // get the stylesheet

	if (the_style) {

		var new_top;

		if (displacement < 0) {
			new_top = current_top - 5;
			displacement += 5;
		} else {
			new_top = current_top + 5;
			displacement -= 5;
		}

		// set the top property of the DIV, add px at the
		// end unless this is NN4
		if (document.layers) {
			the_style.top = new_top;
		} else {
			the_style.top = new_top + "px";
		}
		var final_top = current_top + displacement;

		if (new_top > final_top) {
			anim_timeout = setTimeout("move_y_div('" + div_id + "', " + new_top + ", " + displacement + ", '" + css_top + "', " + css_margin_top + ");", 20);
		} else if (current_top < final_top) {
			anim_timeout = setTimeout("move_y_div('" + div_id + "', " + new_top + ", " + displacement + ", '" + css_top + "', " + css_margin_top + ");", 20);
		} else {
			if (css_top != -1) {
				var obj = document.getElementById(div_id);
				obj.style.top = css_top;
				the_style.margin = css_margin_top + "px 0 0 -300px";
			} else {
				if (div_id == "mel_B") {
					var obj = document.getElementById(div_id);
					obj.style.top = "100%";
					the_style.margin = "-20px 0 0 -300px";
				}
			}
		}

	}

}
