//var base_path = "http://devhost/relaxincomfort/";
var base_path = "http://relaxincomfort.com";
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	// prepareLinks()
	//
	//
	//
function prepareLinks() {
	var links = document.getElementsByTagName("a");
	for(var i=0; i<links.length; i++) {
		var rel = links[i].getAttribute("rel");
		if(rel == "external") {
			links[i].setAttribute("target", "_blank");
		}
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	// ie6dropdown()
	//
	//
	//
function ie6dropdown() {
	var browser = navigator.userAgent;
	if(browser.indexOf('MSIE 6.0') != -1) {
		var nav_main = $('nav_main');
		var list_items = nav_main.getElementsByTagName('li');
		for(var i=0; i < list_items.length; i++) {
			var t = list_items[i];
			t.onmouseover = function() {
				this.className = this.className + ' hover';
			}
			t.onmouseout = function() {
				this.className = '';
			}
		}
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	// initQuickLinks(parentElem)
	//
	//
	//
function initQuickLinks(parentElem) {
	if(!$(parentElem)) return false;
	var parentElem = $(parentElem);
	var items = parentElem.getElementsByTagName('li');
	for(var i=0; i < items.length; i++) {
		var t = items[i];
		var a_tag = t.getElementsByTagName('a')[0];
		
		if(a_tag.getAttribute('rel') == 'external') 
		{
			t.target_window = 'external';
		}
		t.destination = a_tag.getAttribute('href');
		
		t.onclick = function() {
			
			if(this.target_window == 'external') 
			{
				
			}
			else
			{
				window.location = this.destination;
			}
		}
		t.onmouseover = function() {
			this.style.cursor = 'pointer';
			this.style.borderColor = '#c8b098';
		}
		t.onmouseout = function() {
			this.style.borderColor = '#624c37';
		}
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	// locationHours()
	//
	//
	//
function locationHours() {
	if(!$('store_locations')) return false;
	var holders = $('store_locations').select('li.store_hours');
	for(var i=0; i < holders.length; i++) {
		var t = holders[i];
		t.list = t.select('ul')[0];
		t.list.style.display = 'none';
		t.trigger = t.select('a')[0];
		t.onclick = function() {
			Effect.toggle(this.list, 'appear', {duration: 0.2});
			return false;
		}
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	//writeFlashContent()
	//
	//
	//
function writeFlashContent(swfPath, embedId, version, backgroundColor, containerId, swfWidth, swfHeight, argName, argValue) {
	if(!document.getElementById) return false;

	var swfPath = swfPath;
	var embedId = embedId;
	var version = version;
	var backgroundColor = backgroundColor;
	var containerId = containerId;
	var swfWidth = swfWidth;
	var swfHeight = swfHeight;

	if(!document.getElementById(containerId)) return false;

	var swfContainer = document.getElementById(containerId);

	var so = new SWFObject(swfPath, embedId, swfWidth, swfHeight, version, backgroundColor);
	so.addParam("scale", "noscale");
	so.addParam("menu","false");
	so.addParam("salign", "tl");
	if(backgroundColor == 'transparent') {
		so.addParam("wmode", "transparent");
	}
	if(argName && argValue) {
		so.addVariable(argName, argValue);
	}
	so.write(swfContainer);	
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	// fadeElem()
	//
	//
function fadeElem(element, speed, start, end) {
	 new Effect.Opacity(element, {duration:speed, from:start, to:end});
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	//displayLoading()
	//
	//
	//
function displayLoading(element, value) {
	var button = document.getElementById(element);
	button.setAttribute("value", value);
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	// removeConfirmations();
	//
	//
	//
function removeConfirmations() {
	var paras = document.getElementsByTagName("p");
	for(var i=0; i<paras.length; i++){
		if(paras[i].className == "confirm" || paras[i].className == "removed"){
			var feedback = paras[i];
			setTimeout(function() {new Effect.Fade(feedback);}, 6000);
		}
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	// ajaxifyForm(form_id, url, loadingElem)
	//
	//
	//
function ajaxifyForm(form_id, url, loadingElem, loadingMsg) {
	if(document.getElementById(form_id)) {
		var theForm = document.getElementById(form_id);
		var xhr = new Hijax();
		xhr.setContainer(theForm);
		xhr.setUrl(base_path + url);
		xhr.setCanvas(theForm.parentNode);
		if(loadingElem != '') {
			xhr.setLoading(function() {
				displayLoading(loadingElem, loadingMsg);
			});
		}
		xhr.setCallback(function() {
			ajaxifyForm(form_id, url, loadingElem, loadingMsg);
			removeConfirmations();
		});
		xhr.captureData();
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	//addLoadEvent()
	//
	//
	//
function addLoadEvent(func) {
	var oldonload = window.onload;
	if(typeof window.onload != 'function') {
		window.onload = func;
	}else{
		window.onload = function() {
			oldonload();
			func();
		}
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	//call functions on page load with addLoadEvent
	//
	//
	//
addLoadEvent(function(){
	prepareLinks();
	ie6dropdown();
	locationHours();
	initQuickLinks('home_quick_links');
	initQuickLinks('content_secondary');
	ajaxifyForm('contact_form', 'contact_form.php', 'send_btn', 'Sending...');
	ajaxifyForm('ask_the_experts_form', 'ask_the_experts_form.php', 'send_btn', 'Sending...');
});
