/* CENTER THE PAGE FUNCTION */
	function center()
{
	//alert('here');
	var myWidth = 0;//, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' )
	{
    	//Non-IE
    	myWidth = window.innerWidth;
    	y = myHeight = window.innerHeight;
		x = (myWidth/2)+1000;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
    	//IE 6+ in 'standards compliant mode'
    	myWidth = document.documentElement.clientWidth;
    	y =myHeight = document.documentElement.clientHeight;
		x = (myWidth/2)+1000;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
    	//IE 4 compatible
    	myWidth = document.body.clientWidth;
    	y = myHeight = document.body.clientHeight;
		x = (myWidth/2)+1000;
  	}
	//window.alert( 'Width = ' + myWidth );
	//window.alert( 'Height = ' + myHeight );
	document.getElementById('wrapper').style.left = x-2000+"px";
	//document.getElementById('footer').style.left = x-2000+"px";
	//document.getElementById('Q_A').style.left = x-2000+"px";
	if(document.getElementById('lightwindow')){
		document.getElementById('lightwindow').style.left = x-1000+"px";
		//alert(document.body.scrollTop);
		move_down = document.body.scrollTop + "px";
		document.getElementById('lightwindow').style.top = "0px";
		document.getElementById('lightwindow_container').style.top = move_down;
	}
	if(document.getElementById('loader_image'))
	{
		document.getElementById('loader_image').style.left = x - 1100+"px";
		document.getElementById('loader_image').style.position = "absolute";
		//document.getElementById('loader_image').style.width = "2000px"
		//document.getElementById('loader_image').style.top = "200px";
	}
	if(document.getElementById('cart_hide_on_load_only_div')){document.getElementById('cart_hide_on_load_only_div').style.left = x - 1000+"px";}
}

Event.observe(document.onresize ? document : window, "resize", function() {center();});


/* Get the current document height */
	function getDocHeight()
	{
    	var D = document;
    	return Math.max(
        	Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        	Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        	Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    	);
	}


/* BROWSER DETECT */
	var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			//This doesn't work. Chrome not returning "Chrome" something to look into...
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

	//Default set
	browser_in_use = "default";
	firefox = ", type: 'page'";
	image_loc = "images/";
	cart_x_min = -750;
	cart_x_max = 500;
	cart_x_start = 250;
	
	cart_y_min = 25;
	cart_y_max = 1750;
	cart_y_start = 30;
	/*
	if((BrowserDetect.browser == "Firefox") || (BrowserDetect.browser == "Safari"))
	{
		browser_in_use = "FF";
		firefox = ", type: 'page'";
		image_loc = "images/";
		cart_x_min = -630;
		cart_x_max = 400;
		cart_x_start = 250;
		cart_y_max = -400;
		cart_y_min = -1375;
		cart_y_start = -900;
	}
	*/
	if(BrowserDetect.browser == "Explorer")
	{
		browser_in_use = "IE";
	}


/* AJAX Functions */	
	function dosubmit_noform(page_to_load, link_number, link_inside)
	{
		category3 = category2;
		new Ajax.Updater('center_content', page_to_load, { onCreate: load_started_function, onComplete: load_finished_function });
		
		category = link_number;
		category2 = link_inside;
		reset_menu_colors();
	}
	
	function enewsSubscribe()
	{

		var en_email = document.forms['enewsform'].elements["en_email"].value;
		var GA_Source = document.forms['enewsform'].elements["GA_Source"].value;
		var GA_Medium = document.forms['enewsform'].elements["GA_Medium"].value;
		var GA_Campaign = document.forms['enewsform'].elements["GA_Campaign"].value;
			
		new Ajax.Updater('hp_email_box', '../core/newsletter.php?email=' + en_email + '&GA_Source=' + GA_Source + '&GA_Medium=' + GA_Medium + '&GA_Campaign=' + GA_Campaign, { onCreate: show_subscribe_loader, onComplete: hide_subscribe_loader });
	}
	
	function question_submit()
	{
		var q_email = document.getElementById("q_email").value;
		var q_question = document.getElementById("q_question").value;
		new Ajax.Updater('question_submission_div', 'pages/energy_healing_question_submission.php?email=' + q_email + '&question=' + q_question
		, { onCreate: show_question_loading, onComplete: hide_question_loading });
	}
	function show_question_loading()
	{
		$('question_loader').style.display = 'block';
		$('question_submission_div').style.display = 'none';
	}
	function hide_question_loading()
	{
		$('question_loader').style.display = 'none';
		$('question_submission_div').style.display = 'block';
	}
	function send_another_question(email, question)
	{
		var q_email = email;
		var q_question = question;
		new Ajax.Updater('question_submission_div', 'pages/question_submission.php?email=' + q_email + '&question=' + q_question);	
	}
	
	function enewsLoad()
	{
		new Ajax.Updater('hp_email_box', '../core/newsletter.php?new=yes');
	}
	
	function show_subscribe_loader()
	{
		document.getElementById('hp_email_loading').style.display = 'block';
		document.getElementById('hp_email_content').style.display = 'none';
	}
	function hide_subscribe_loader()
	{
		if (typeof writeOnclickAttribute == 'function') {
			$$('.applyAddLinker').each(function(element) {
				writeOnclickAttribute(element);
			});
		};
		document.getElementById('hp_email_loading').style.display = 'none';
		document.getElementById('hp_email_content').style.display = 'block';
	}
/*
	Ajax.Responders.register({
  		onCreate: function()
		{
    		load_started_function();
  		}, 
  		onComplete: function()
		{
    		load_finished_function();
  		}
	});
*/
	function load_started_function() {
		document.getElementById('center_content').style.visibility = "hidden";
		document.getElementById('inner_loader').style.display = "inline";
	}
	
	function load_finished_function() {
		document.getElementById('inner_loader').style.display = "none";
		document.getElementById('center_content').style.visibility = "visible";
		//alert( getDocHeight() );
		cart_y_max = getDocHeight();
		//alert(cart_y_max);
		
		// assure that outbound links to soundstrue have the correct tracking functionality applied
		// writeOnclickAttribute is in initial_state.js
		$$('div#center_content a').each(function(element){
			writeOnclickAttribute(element);
		});
		
	}


/* LIGHTWINDOW FUNCTIONS */
	function light_that_window(destination)
	{
		//scroll.top();
		if($('abstract_player')){ $('abstract_player').sendEvent("STOP"); }
		setTimeout( function() { now_light_that_window(destination); }, 100);
	}

	function closer()
	{
		//if(myLightWindow){myLightWindow.deactivate();}
		if($('abstract_player_lessons')){ $('abstract_player_lessons').sendEvent("STOP"); }
	}

	function now_light_that_window(destination)
	{
		myLightWindow.activateWindow({
			href: destination,
			/*title: page_title,*/
			width: 867,
			height: 700,
			type: 'page'
		});
		cart_y_max = getDocHeight();
	return false;
	}


/* Scroll to Top of Page Functino */
	var  scroll = {	top: function(event) { new Effect.ScrollTo('top', {duration: 1.0}); } }


/* Thin or Wide Page States functions */
	function large_middle()
	{
	//open_blind = ''; last_arrow = '';
	$('center_section_background').style.backgroundImage = "url(images/content_wide_bg.jpg)";
	$('center_section').style.backgroundImage = "url(images/content_wide_main.jpg)";
	$('center_section_close_foot_image').src = "images/content_wide_footer.gif";
	$('center_section_close').style.width = "725";
	$('center_section_background').style.width = "725px";
	$('center_section').style.width = "725px";
	$('center_content').style.width = "725px";
	$('categories_background').style.display = "none";
	$('center_back').style.visibility = "visible";
	//setTimeout( function() { scroll.top(); }, 1000);
	}

	function small_middle()
	{
		$('center_section_background').style.backgroundImage = "url(images/main_middle_bg.jpg)";
		$('center_section').style.backgroundImage = "url(images/main_middle.jpg)";
		$('center_section_close_foot_image').src = "images/main_middle_bottom.gif";
		$('center_section_close').style.width = "502";
		$('center_section_background').style.width = "502px";
		$('center_section').style.width = "502px";
		$('center_content').style.width = "502px";
		$('categories_background').style.display = "inline";
		$('center_back').style.visibility = "hidden";
		//setTimeout( function() { scroll.top(); }, 1000);
	}


/* Control the Audio Player Functions */
	function start_player_from_link(which_player)
	{
		setTimeout(function() { $(which_player).sendEvent("PLAY", "true"); }, 500);
	}

	function stop_player(which_player)
	{
		$(which_player).sendEvent("STOP");
	}


/* right nav menu functions (toggle_accordian) */
	setTimeout( function() { accordianing = false; }, 4000);
	//Effect.Queues.get('menuxscope').interval = 10;
	accordianing = true;
	
	function toggle_accordian(to_show_or_hide)
	{
		if(accordianing == true)
		{
			setTimeout( function() { toggle_accordian(to_show_or_hide); }, 25);
		}
		else
		{
			if($(to_show_or_hide).style.display == 'none')
			{
				new Effect.BlindDown(to_show_or_hide, {
					duration: 0.25,
					queue: 'end',
					afterFinish: function() { slide_up_open(to_show_or_hide); }
				});
				//reset_menu_colors();
			}
			else
			{
				new Effect.BlindUp(to_show_or_hide, {
					duration: 0.25,
					queue: 'end',
					afterFinish: function() { accordianing = false; }
				});
			}
		}
	}
	
	function slide_up_open(to_show_or_hide)
	{
		reset_menu_colors();
		switch(to_show_or_hide)
		{
			case 'sub_category_0':
				var clean_order = new Array('sub_category_1', 'sub_category_2', 'sub_category_3', 'sub_category_4', 'sub_category_5', 'sub_category_6', 'sub_category_7'); var C = setTimeout( function() {  cleanup(clean_order); }, 10); break;
			case 'sub_category_1': var clean_order = new Array('sub_category_2', 'sub_category_3', 'sub_category_4', 'sub_category_5', 'sub_category_6', 'sub_category_7'); var C = setTimeout( function() { cleanup(clean_order); }, 10); break;
			case 'sub_category_2': var clean_order = new Array('sub_category_1', 'sub_category_3', 'sub_category_4', 'sub_category_5', 'sub_category_6', 'sub_category_7'); var C = setTimeout( function() { cleanup(clean_order); }, 10); break;
			case 'sub_category_3': var clean_order = new Array('sub_category_1', 'sub_category_2', 'sub_category_4', 'sub_category_5', 'sub_category_6', 'sub_category_7'); var C = setTimeout( function() { cleanup(clean_order); }, 10); break;
			case 'sub_category_4': var clean_order = new Array('sub_category_1', 'sub_category_2', 'sub_category_3', 'sub_category_5', 'sub_category_6', 'sub_category_7'); var C = setTimeout( function() { cleanup(clean_order); }, 10); break;
			case 'sub_category_5': var clean_order = new Array('sub_category_1', 'sub_category_2', 'sub_category_3', 'sub_category_4', 'sub_category_6', 'sub_category_7'); var C = setTimeout( function() { cleanup(clean_order); }, 10); break;
			case 'sub_category_6': var clean_order = new Array('sub_category_1', 'sub_category_2', 'sub_category_3', 'sub_category_4', 'sub_category_5', 'sub_category_7'); var C = setTimeout( function() { cleanup(clean_order); }, 10); break;
			case 'sub_category_7': var clean_order = new Array('sub_category_1', 'sub_category_2', 'sub_category_3', 'sub_category_4', 'sub_category_5', 'sub_category_6'); var C = setTimeout( function() { cleanup(clean_order); }, 10); break;
		}
	}

	function cleanup(clean_order_passed)
	{
		for( i = 0; i <= clean_order_passed.length; i++ )
		{
			if($(clean_order_passed[i]) == null)
			{
				accordianing = false;
			}
			else
			{
				new Effect.BlindUp(clean_order_passed[i], {
					duration: 0.25,
					queue: 'end'
				});
			}
		}
		accordianing = false;
	}

/* menu bold management */
	function rollover_color(which)
	{
		from_color = $(which).style.color;
		$(which).style.color = '#004A78';
	}
	
	function rollback_color(which)
	{
		$(which).style.color = from_color;
		reset_menu_colors();
	}
	
	function reset_menu_colors()
	{
		for (p = 1; p <= 2000; p++)
		{
			var counterer = "link_" + p;
			if($(counterer) != null)
			{
				if((counterer == category)||(counterer == category2))
				{
					//$(counterer).style.color = "#002140";
					$(counterer).style.fontWeight = "bold";
				}
				else
				{
					//document.getElementById(counterer).style.color = "#002140";
					document.getElementById(counterer).style.fontWeight = "normal";
				}
			}
		}
	}


/* ROTATING BLOCK */
	var spot = 0;
	function swap_lower_left_block()
	{
		switch(spot)
		{
			case 0: case 4: case 8: case 12: case 16: case 20:
			current_rotator = 'left_block1';
			document.getElementById('left_block1_button').src = 'images/rotating-marker-on.gif';
			document.getElementById('left_block2_button').src = 'images/rotating-marker-off.gif';
			document.getElementById('left_block3_button').src = 'images/rotating-marker-off.gif';
			document.getElementById('left_block4_button').src = 'images/rotating-marker-off.gif';
			this_things_state = document.getElementById('left_block1_button').src;
			clearTimeout(rotatorer);
			new Effect.Fade('left_block4', { duration: 0.5 });
			new Effect.Appear('left_block1', { duration: 0.5, queue: 'end' }); 
			spot++;
			rotatorer = setTimeout("swap_lower_left_block()", 10000);
			break;
			
			case 1: case 5: case 9: case 13: case 17:
			current_rotator = 'left_block2';
			document.getElementById('left_block1_button').src = 'images/rotating-marker-off.gif';
			document.getElementById('left_block2_button').src = 'images/rotating-marker-on.gif';
			document.getElementById('left_block3_button').src = 'images/rotating-marker-off.gif';
			document.getElementById('left_block4_button').src = 'images/rotating-marker-off.gif';
			this_things_state = document.getElementById('left_block2_button').src;
			clearTimeout(rotatorer);
			new Effect.Fade('left_block1', { duration: 0.5 });
			new Effect.Appear('left_block2', { duration: 0.5, queue:'end' }); 
			spot++;
			rotatorer = setTimeout("swap_lower_left_block()", 10000);
			break;
			
			case 2: case 6: case 10: case 14: case 18:
			current_rotator = 'left_block3';
			document.getElementById('left_block1_button').src = 'images/rotating-marker-off.gif';
			document.getElementById('left_block2_button').src = 'images/rotating-marker-off.gif';
			document.getElementById('left_block3_button').src = 'images/rotating-marker-on.gif';
			document.getElementById('left_block4_button').src = 'images/rotating-marker-off.gif';
			this_things_state = document.getElementById('left_block3_button').src;
			clearTimeout(rotatorer);
			new Effect.Fade('left_block2', { duration: 0.5 });
			new Effect.Appear('left_block3', { duration: 0.5, queue:'end' }); 
			spot++;
			rotatorer = setTimeout("swap_lower_left_block()", 10000);
			break;
			
			case 3: case 7: case 11: case 15: case 19:
			current_rotator = 'left_block4';
			document.getElementById('left_block1_button').src = 'images/rotating-marker-off.gif';
			document.getElementById('left_block2_button').src = 'images/rotating-marker-off.gif';
			document.getElementById('left_block3_button').src = 'images/rotating-marker-off.gif';
			document.getElementById('left_block4_button').src = 'images/rotating-marker-on.gif';
			this_things_state = document.getElementById('left_block4_button').src;
			clearTimeout(rotatorer);
			new Effect.Fade('left_block3', { duration: 0.5 });
			new Effect.Appear('left_block4', { duration: 0.5, queue:'end' }); 
			spot++;
			rotatorer = setTimeout("swap_lower_left_block()", 10000);
			break;
			
			case 21: clearTimeout(rotatorer);
		}
		
		//var rotatorer = setTimeout("swap_lower_left_block()", 10000);
	}

	function halt(show_this_one, hide_this1, hide_this2, hide_this3)
	{
		shower = show_this_one+'_button';
		hider1 = hide_this1+'_button';
		hider2 = hide_this2+'_button';
		hider3 = hide_this3+'_button';
		current_rotator = show_this_one;
			document.getElementById(shower).src = 'images/rotating-marker-on.gif';
			document.getElementById(hider1).src = 'images/rotating-marker-off.gif';
			document.getElementById(hider2).src = 'images/rotating-marker-off.gif';
			document.getElementById(hider3).src = 'images/rotating-marker-off.gif';
			this_things_state = document.getElementById(shower).src;
		clearTimeout(rotatorer);
		new Effect.Fade(hide_this1, { duration: 0.2 });
		new Effect.Fade(hide_this2, { duration: 0.2 });
		new Effect.Fade(hide_this3, { duration: 0.2 });
		new Effect.Appear(show_this_one, { duration: 0.2, queue:'end' });
	}

	function hover(activated)
	{
		this_things_state = document.getElementById(activated).src;
		document.getElementById(activated).src = 'images/rotating-marker-3.gif';	
	}

	function hover_out(activated)
	{
		document.getElementById(activated).src = this_things_state;	
	}
	
	
/* URL Tracker */
	last_page = new Array();
	go_here = '';
	
	function tracker()
	{
		go_here = location.hash;
		go_here = go_here.substr(1);
		last_page.unshift(go_here);
	}
	
	function visit_last_remove_from_tracker()
	{
		go_here = last_page.shift();
		//alert(go_here);
		if(go_here == ''){go_here = '!state_link_28';}
		if(go_here == 'undefined'){go_here = '!state_link_28';}
		return go_here;
	}


/* Expando sections functions */
	function accordian(to_show_or_hide, to_toggle)
	{
		if(accordianing == true)
		{
			setTimeout( function() { accordian(to_show_or_hide, to_toggle); }, 25);
		}
		else
		{
			accordianing = true;
			toggle_arrow_noscroll(to_toggle);
			if($(to_show_or_hide).style.display == 'none')
			{
				new Effect.BlindDown(to_show_or_hide, {
					duration: 0.5,
					afterFinish: function(){ accordianing = false; }
				});
			}
			else
			{
				new Effect.BlindUp(to_show_or_hide, {
					duration: 0.5,
					afterFinish: function(){ accordianing = false; }
				});
			}
			cart_y_max = getDocHeight();
		}
	}
	
	function toggle_arrow_noscroll(id_sent)
	{
		this_current_image = ($(id_sent).src).search(/close/);
		if(this_current_image == -1)
		{
			$(id_sent).src = 'images/arrow-close.gif';
		}
		else
		{
			$(id_sent).src = 'images/arrow-expand.gif';
		}
	}
	
	
/* onclicks for energyhealing Exercises Overview since it's loaded late if ever */
	function load_more(state_to_activate)
	{
		tracker();
		StateManager.setState(state_to_activate);
		return false;
	}
	
/* printer functions */
	//expand all sections
	function printer_function()
	{
		//alert(number_of_accordians);
		var i = 1;
		while (i <= number_of_accordians)
		{
			to_show_or_hide = "Div_" + i;
			to_toggle = to_show_or_hide+"_arrow";
			if($(to_show_or_hide).style.display == 'none')
			{
				new Effect.BlindDown(to_show_or_hide, { duration: 0.5 });
				cart_y_max = getDocHeight();
				toggle_arrow_noscroll(to_toggle);
			}
			i++;
		}
		setTimeout("print_window()", 2000);
		return false
	}
	//open a window with the content only
	function print_window()
	{
		//alert('here');
		var display_setting="toolbar=yes,location=no,directories=yes,menubar=yes,";
		display_setting+="scrollbars=yes,width=750, height=600, left=100, top=25";
		
		var content_innerhtml = "<div id='frameToPrint'>"+document.getElementById("center_content").innerHTML+"</div>";
		var document_print=window.open("","print_version",display_setting);
		document_print.document.open();
		document_print.document.write('<html><head><link href="css/print.css" rel="stylesheet" type="text/css" /><title>Sounds True Guide: energyhealing</title></head>');
		document_print.document.write('<body style="font-family:verdana; font-size:12px;" onLoad="print();" >');
		document_print.document.write(content_innerhtml);
		document_print.document.write('</body></html>');
		document_print.document.close();
		track_it('/guide/energyhealing/print/');
		return false;
	}

	/* GATC pageview */
	function track_it(page_visited)
	{
		//_gaq.push(['_trackPageview', page_visited]);
	}
