base_path = "/";

sub_url = document.location.pathname.split("/");
current_page = sub_url[1];
if (current_page == "info" || current_page == "") {
	container_height = 480; //same as height declared in css
	scroll_div = "scroll_content";
} else if (current_page == "shipping_faq" || current_page == "store_faq" || current_page == "general_faq") {
	container_height = 430; //same as height declared in css
	scroll_div = "faq_content";
}

// scroller

this.divScroller = function() {

	var speed = 7;
	
	var obj = document.getElementById(scroll_div);
	
	obj.up = false;
	obj.down = false;
	obj.fast = false;
		
	var upbtn = document.getElementById("scrollup");
	var dnbtn = document.getElementById("scrolldown");
	
	upbtn.onmouseover = function() {
		obj.up = true;
		upbtn.className = "upon";
	}
	upbtn.onmouseout = function() {
		obj.up = false;
		upbtn.className = "upoff";
	}	
	dnbtn.onmouseover = function() {
		obj.down = true;
		dnbtn.className = "downon";
	}
	dnbtn.onmouseout = function() {
		obj.down = false;
		dnbtn.className = "downoff";
	}
		
	this.start = function() {				
		var newTop;
		var objHeight = obj.offsetHeight;
		var top = obj.offsetTop;
		if (obj.down) {		 
			newTop = ((objHeight+top) > container_height) ? top - (speed) : top;	
			obj.style.top = newTop + "px";
		}
		if (obj.up) {		 
			newTop = (top < 0) ? top + (speed) : top;
			obj.style.top = newTop + "px";
		}
	}
	obj.interval = setInterval("start()", 50);		
		
}

this.addEvent = function() {
	if (window.attachEvent) {
		window.attachEvent("onload", divScroller);
	} else {
		window.addEventListener("load", divScroller, false);
	}
}

scrollerpages = new Array("info", "", "shipping_faq", "store_faq", "general_faq")

for (i=0; i<=scrollerpages.length; i++) {
	if (current_page == scrollerpages[i]) {
		addEvent();
	}
}

// arrow swapping

this.arrowSwap = function() {
	var al = document.getElementById("arrow_l_btn");
	var ar = document.getElementById("arrow_r_btn");
	
	if (al != null) {
		al.onmouseover = function() {
			al.className = "lefton";
		}
		al.onmouseout = function() {
			al.className = "leftoff";
		}
	}
	if (ar != null) {
		ar.onmouseover = function() {
			ar.className = "righton";
		}
		ar.onmouseout = function() {
			ar.className = "rightoff";
		}
	}
}

this.addSwapEvent = function() {
	if (window.attachEvent) {
		window.attachEvent("onload", arrowSwap);
	} else {
		window.addEventListener("load", arrowSwap, false);
	}
}

addSwapEvent();

// rollover info for galleries

function gallery_info(title, info) {
	document.getElementById("right_col").innerHTML = "<h2>" + title + "</h2><p>" + info + "</p>";
}

function clear_info() {
	document.getElementById("right_col").innerHTML = "";
}

// purchase ease-slider

function getCurrentToggle(gallery_id) {
	toggleCookie = readCookie("purchase_open");
	if (gallery_id) {
		//if reading from a click event
		if (toggleCookie == gallery_id) {
			return "opened";
		} else {
			return "closed";
		}
	} else {
		return "closed";
	}
}

function initEase(gallery_id) {
	sale_toggle = getCurrentToggle(gallery_id);
	t = 0; //current time
	d = 22; //duration
	if (sale_toggle == "closed") {
		b = 400; //start value
		c = -342; //change in value
		document.cookie = "purchase_open="+gallery_id+"; path=/";
		sale_toggle = "opened";
		document.getElementById("info_toggle_button").className = "opened";
	} else {
		b = 58; //start value
		c = 342; //change in value
		document.cookie = "purchase_open=''; path=/";
		sale_toggle = "closed";
		document.getElementById("info_toggle_button").className = "";
	}
	easeTimer = setInterval('easeOut(\'info_container\', \'sale_info_container\');', 40);
}

function circularEase(t, b, c, d) {
	t /= d;
	t--;
	return Math.round(c * Math.sqrt(1 - t*t) + b);
}

function easeOut() {
	if (t<=d) {
		h = circularEase(t, b, c, d);
		document.getElementById("info_container").style.height = h + "px";
		if (sale_toggle == "opened") { // would normally be if "closed", but toggle is already flipped by this point, so "open" is used.
			h2 = b - h;
		} else {
			h2 = (b + c) - h;	
		}
		document.getElementById("sale_info_container").style.height = h2 + "px";
		document.getElementById("sale_info").style.top = ((-1) * h) + "px";
		t++;
	} else {
		clearInterval(easeTimer);
	}
}

function setPageCookie(page) {
	document.cookie = "last_page="+page+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
