

// ########
// DIALOG #
// ########
	
	function popup(content) {
	
		$("#alertDialog").html(content);
		overlay(0);
	
			$("#alertDialog").dialog({
				bgiframe: false,
				title: 'Total Body PT',
				hide: 'puff',
				width: 'auto',
				close: function() { unoverlay();$(this).dialog('destroy')}
			});

		$("#alertDialog").dialog('option', 'width', $("#alertDialog").parent().width());
	}


// ##############
// CENTER A DIV #
// ##############

	function centerDiv(id) {
		var cWidth = document.documentElement.clientWidth;
		var cHeight = document.documentElement.clientHeight;
		var popupHeight = $(id).height();
		var popupWidth = $(id).width();

		$(id).css({"top": cHeight/2-popupHeight/2, "left": cWidth/2-popupWidth/2});

    }
    
    
// #########
// OVERLAY #
// #########

	function overlay(closeable) {

			if (closeable === undefined) {closeable = 1;}
	
			if (closeable == 1 || closeable == 2) {
				$(window).bind('keydown', function(e) { if (e.keyCode = 27) {unoverlay();} });
   				$("#overlay").bind('click', function(){unoverlay();});
			}

			winHeight = $(document).height();
			$("#overlay").height(winHeight);


			if (closeable == 1) {$("#overlay").html('<div id="overlayClose"><button class="header_button"><span><img src="/lite/cp/images/icons/close.gif" height="16" width="16" /> Close</span></button></div>');}

			$("#overlay").windowHeight
        		$("#overlay").fadeIn(500, function(){$("#overlayContent").show();centerDiv("#overlayContent");});
			$("#overlay").fadeTo("slow", 0.90);
		}

	function unoverlay() {
			$("#overlayContent").hide();
			$("#overlay").fadeOut(500);
			$(window).unbind('keydown');
			$("#overlay").unbind('click');
			$("#overlay").html('');
		}






// #################
// PAYMENT OVERLAY #
// #################

	function paymentOverlay(){
	overlay(0);
	$("#overlayContent").html('<img src="/static/images/loading_bar.gif" width="354" height="100"/><br/><br/><img src="/static/images/paypal_logo.gif" width="193" height="23"/>');
	
	}


// ##################
// AJAX GET REQUEST #
// ##################

	var currentPage = false;
	var previousPage = false;

	function ajaxopen(target, url, formID) {

		$('#footer_left').css('display', 'inline');

		// CHECK IF THIS IS A FORM REQUEST, IF SO SERIALIZE THE INPUT ELEMENTS AND POST
			if (formID === undefined) {formData = false;}
			else {formData = $(formID).serialize(); if($(formID).attr('rel') == "useURL") {url += '&' + formData;} }

		$.ajax({
			url: url,
			cache: false,
			dataType: "html",
			type: "POST",
			data: formData,

			success: function(html){

				if (target == "alert") {alert(html);}
				else if (target == "popup") {popup(html);}
				else if (target == "0") {}
				
				else {
					$(target).html(html);
					$(target).scrollTop(0);

					if(Changing == 1) {previousPage = ChangingCurrentPage;}
					else {previousPage = window.location.hash.replace(/^#/,'');;}
				
					currentPage = url;
					window.location.hash = url;
					Changing = 0;
				}
				
				
			},

			error: function(textStatus, errorThrown){
				alert('There has been an error accessing this page\n\nPlease try again.');
			},

			complete: function(){
				
				$('#footer_left').fadeOut(600);
				$('form.jqtransform').jqTransform();
				eval($("#center_content .js_execute").text()); $("#center_content .js_execute").remove();$('form.jqtransform').jqTransform();
				
				
				jquery_tip();
			}
		});

		if (formData != false) {return false;}
	}
	
	
	
	
// ####################
// # INDEX JAVASCRIPT #
// ####################	

	function AddToBookmarks(url, title){

	if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "")
	}
	

// TYPEWRITTER
	setTimeout("$('#news_typewriter').typewriter();", 100);
	setInterval("$('#news_typewriter').typewriter();", 15000);


	// DOM READY

		$(document).ready(function(){
		
		//$('#left_content').height($('#main_content').height()+16);
			//$('.navLinks').corner('round all 10px');
			//$('#news_top').corner('round tl tr 10px');
			//$('#footer_content').corner('round bl br 10px');
			$('.ceebox').ceebox();

			$(window).scroll(function()
			{$('#sidebar').animate({top:$(window).scrollTop()+300+"px" },{queue: false, duration: 350});});
		});

