/*<script>*/
/*
Inline Ajax Page
(C) Anthologyoi.com
*/

var d=document;
var last_page = [];
var cur_page = [];
var last_show = [];
var mrc = '';
var force = 0;
var info = [];

function inap_request(the_id,the_type,show_text,hide_text,extras){
	if( the_id ){
		id =  the_id;}
	if( the_type ){
		type =  the_type;}
	if( hide_text ){
		hide =  hide_text;}
	if( show_text ){
		show =  show_text;}
		extra =  extras;

	where = 'post_'+type+'_'+id;

	dwhere = d.getElementById(where);

	if(type=='addcomment' && extra){
		if(extra.match(';')){
			info = extra.split(';');
		}
		if(isNaN(last_extra[id])){last_extra[id] = 1;}
		if(isNaN(info[0])){
			info[0] = last_extra[id];
			info[1] = 0;
		}
	}else if(type=='content'){
		if (last_page[id] === 0 || isNaN(last_page[id])){
			if(isNaN(extra)){cur_page[id] = 2;}else{cur_page[id] = extra;}
			last_page[id] = 1;
			force = 1;
		}else{
			if(isNaN(extra) && cur_page[id] == 1){extra = 2;}else if (isNaN(extra) && cur_page[id] == 2){extra = 1;}
			last_page[id] = cur_page[id];
			cur_page[id] =extra;
		}
	}

	if (dwhere.innerHTML.length === 0 || force ==1){

					inaprequest = new sack('http://www.johncassimatis.com/wp-content/plugins/inline-ajax-page/inap-get-info.php');
			inaprequest.method = 'POST';
			inaprequest.setVar('id', id);
			inaprequest.setVar('type', type);
			inaprequest.setVar('extra', extra);
			inaprequest.setVar('show', show_text);
			inaprequest.setVar('hide', hide_text);
			inaprequest.element = where;
			inaprequest.onLoading = inap_loading;
			inaprequest.onCompletion = inap_toggle;
			inaprequest.runAJAX();
			inaprequest = null;


	
	}else{
		inap_toggle();
	}
}

function submit_form(the_id,the_type,show_text,hide_text,comment_hide){
	if( the_id ){
		id =  the_id;}
	if( the_type ){
		type =  the_type;}
	if( hide_text ){
		hide =  hide_text;}
	if( show_text ){
		show =  show_text;}
	if( comment_hide ){
		com_hide = comment_hide;}

		try{d.getElementById('submit_'+id).disabled = true;} catch(e){}

		base = d.getElementById('post_addcomment_'+id).getElementsByTagName('input');


			inaprequest = new sack('http://www.johncassimatis.com/wp-content/plugins/inline-ajax-page/inap-get-info.php');
			var x = base.length;
		var value = '';
		var name = '';
		for(i=0; i<x; i++){
			if(base[i].type != 'button'){
				if(base[i].type == 'text' || base[i].type == 'hidden' || base[i].type == 'password'){
						value =  base[i].value;
						name = base[i].name;
				}else if(base[i].type == 'checkbox'){
					if (base[i].checked) {
						value =  base[i].value;
						name = base[i].name;
					}
				}else if(base[i].type == 'select'){
						value =  base[i].value;
						name = base[i].name;
				}
						inaprequest.setVar(name, value);
					}
		}
		base = d.getElementById('post_addcomment_'+id).getElementsByTagName('textarea');
		x = base.length;

		for(i=0; i<x; i++){
							inaprequest.setVar(base[i].name, base[i].value);
					
		}

	
			inaprequest.setVar('type', 'submit_form');
			inaprequest.element = 'submit_form_'+id;
			inaprequest.method = 'POST';
			inaprequest.onLoading = inap_submiting;
			inaprequest.onCompletion = complete_submit;
			inaprequest.runAJAX();
			inaprequest = null;

	}


function inap_paged(page,what){

				inaprequest = new sack('http://www.johncassimatis.com/wp-content/plugins/inline-ajax-page/inap-get-info.php');
			inaprequest.method = 'POST';
			inaprequest.setVar('type', 'paged');
			inaprequest.setVar('pagenum', page);
			inaprequest.setVar('what', what);
			inaprequest.element = 'inap_loop';
			inaprequest.onCompletion = complete_paged;
			inaprequest.runAJAX();
			inaprequest = null;


	}
var last_extra = [];


function inap_toggle(){
var winHeight = window.innerHeight;
	if(!winHeight){
		//yet another IE fix
		winHeight = d.documentElement.clientHeight;
	}



	setTimeout("try{d.getElementById('throbber'+type+id).parentNode.removeChild(d.getElementById('throbber'+type+id));}catch(e){}",100);

 	if (dwhere.style.display == 'none' || force==1 || (last_extra[id] != info[0] && type == 'addcomment')){
 		style1 = 'block';
 		style2 = 'none';
		link =hide;
		var style= '_hide';
 	}else{
 		 style1 = 'none';
 		 style2 = 'block';
 		 link =show;
		var style = '';
 	}

	if(type == 'content'){
		inap_toggle_content();

		var l = d.getElementById('post_content_link'+'_'+id);
		if(show == 'off'){
			d.getElementById('post_page_'+cur_page[id]+'_'+id+'_link').style.fontWeight = 'bold';
			if(last_page[id] !=cur_page[id] ){
			d.getElementById('post_page_'+last_page[id]+'_'+id+'_link').style.fontWeight = 'normal';}
		}else{

			if(l.firstChild.data == hide){
				l.firstChild.data = show;
				l.className = 'post_content_link';
			}else{
				l.firstChild.data = hide;
				l.className = 'post_content_link_hide';
			}

		}
	}else if(type == 'addcomment'){

		inap_toggle_addcomment();

		if(info[0]){
			if(style1 == 'none'){
				d.getElementById('post_addcomment_link'+info[0]+'_'+id).firstChild.data = show;
			}else{
				try{
					if(last_show[id]){
					d.getElementById('post_addcomment_link'+last_extra[id]+'_'+id).firstChild.data = last_show[id];}
				}catch(e){}
				d.getElementById('post_addcomment_link'+info[0]+'_'+id).firstChild.data = hide;
			}
			last_show[id] = show;
			last_extra[id] = info[0];
		}
	}else{
		if(d.getElementById('post_'+type+'_link'+'_'+id)){
			d.getElementById('post_'+type+'_link'+'_'+id).className = 'post_' + type + '_link' + style;
			d.getElementById('post_'+type+'_link'+'_'+id).firstChild.data = link;
		}
		if(!force || ( force && d.getElementById(where).style.display !== "block")){
			inap_effects_pick();
		}
	}


 		force=0;
	if(type == 'comments' && mrc > 1){
		setTimeout("location.href= '#comment-'+mrc;",100);
	}
		if(dwhere.offsetTop > 0){
			window.parent.scrollTo(0,dwhere.offsetTop - winHeight/4);
		}
}

function inap_toggle_addcomment(){

		
	if(style1 == 'block' && force===0){
		dwhere.style.display = 'none';
		d.getElementById('post_addcomment_link'+info[0]+'_'+id).parentNode.insertBefore(dwhere, d.getElementById('post_addcomment_link'+info[0]+'_'+id).nextSibling);

		if(dwhere.style.display != 'block'){
	//	d.getElementById('post_addcomment_link'+info[0]+'_'+id).firstChild.data = show;
			inap_effects_pick();
		}
	}else{
		style1 = 'none';
		inap_effects_pick();
	}
try{d.getElementById('submit_'+id).disabled = false;} catch(e){}
}

function inap_toggle_content(){
	var q = [];
	q[0] = 'show::post_page_'+cur_page[id]+'_'+id;
	AOI_eff.start('post_page_'+last_page[id]+'_'+id, {'mode': 'hide', 'eff': '', 'queue': q} );
}





function inap_effects_pick(){

			AOI_eff.start(where, {'eff': ''});
	
}
function inap_loading(){

	var img = d.createElement('img');
	img.src="http://www.johncassimatis.com/wp-content/plugins/inline-ajax-page/js/throbber.gif";
	img.alt="Please hold now loading";
	img.id = "throbber"+type+id;
	if(cur_page[id] && show == 'off'){
		try{d.getElementById('post_page_'+cur_page[id]+'_'+id+'_link').appendChild(img);}catch(e){}
	}else{
		try{d.getElementById('post_'+type+'_link_'+id).appendChild(img);}catch(e){}
	}
}

function inap_submiting(){
	var img = d.createElement('img');
	img.src="http://www.johncassimatis.com/wp-content/plugins/inline-ajax-page/js/throbber.gif";
	img.alt="Please hold now loading";
	img.id = "throbbersubmit"+id;
		try{d.getElementById('submit_'+id).appendChild(img);}catch(e){}
}

function complete_submit(){
	setTimeout("complete_submit_2()",5);
}

function complete_submit_2(){
/*if there was an error the message is really long...so:*/
	if(d.getElementById('submit_form_'+id).innerHTML.substring( 0, 6 ) == 'ERROR:'){
		var re = new RegExp('<p>(.*?)</p>','gmi');
		
		var m = re.exec(d.getElementById('submit_form_'+id).innerHTML);
		if(m){
		d.getElementById('submit_form_'+id).innerHTML = m[1];}
	}else{
		var message = d.getElementById('submit_form_'+id).innerHTML.split('-');
		d.getElementById('submit_form_'+id).innerHTML = message[0];
		mrc = message[1];

		try{
			if (d.getElementById('post_comments_none_'+id).style.display != 'none'){
				d.getElementById('post_comments_none_'+id).style.display = 'none';
				d.getElementById('post_comments_link_'+id).innerHTML = 'Show Comments';
			}
		}catch(e){ var string ='';}

			type = 'addcomment';
			inap_request();

// Set up for the reload.
		d.getElementById('post_comments_'+id).parentNode.insertBefore(d.getElementById('post_addcomment_'+id), d.getElementById('post_comments_'+id));
		info[1] = 0;
		force = 1;
		try{
			var i = d.getElementById('post_comments_'+id).innerHTML;
			hide = com_hide;
			type = 'comments';
			inap_request();
		}catch(e){}

	}

	try{d.getElementById('submit_'+id).disabled = false;} catch(e){}
	try{d.getElementById('throbbersubmit'+id).parentNode.removeChild(d.getElementById('throbbersubmit'+id));}catch(e){}

}

function complete_paged(){
	window.parent.scrollTo(0,d.getElementById('inap_loop').offsetTop);
}


// start effects
/**
*	 Originally and Copyrighted 2007 by:
*	Aaron Dowden http://anthologyoi.com
*	The code is released under a Creative Commons Liscense
*	(Attribution-NonCommercial-ShareAlike 2.0)
*	TERMS: (Removal this section indicates agreement with these Terms.)
*	For Personal (non-distribution) this notice (sans Terms section) must remain.
*	For Distribution this notice must remain and attribution through
*	a publically accessible "followable" link on applicable information/download page is required.
*	No Commercial use without prior approval.
**/

var AOI_eff = function () {

/**
* The following are used consistantly throughout.
* Parameter and variable "i" is the ID of element for currently processing effect.
* Can have multiple "i"s at the same time,  but they do not overlap or interact.
* Variable "e" is the element itself.
**/
	/*
	*  Private "Global" Variables
	*  delay: Default time (in milliseconds) bewteen frames for all effects
	*  _d is an object with an index of i that holds currently active effect information
	*/
	var delay = 100;
	var _d = [];

	/*
	*  Private Function
	*  Returns the element for a given i.
	*  Is NOT related to prototype or jQUERY.
	*/
	var $ = function (id) {
		return document.getElementById(id);
	};

	return {
		/*
		*	This function sets up the effect
		*	It is a per-application function and will change depending on
		*	How the effects are called and proccessed.
		*/
		start: function () {
			var	i = arguments[0];

			if (!_d[i]) {//This stops the effects from being restarted in the middle

				//_d[i]['eff'] = effect; =  arguments[1];

				_d[i] = arguments[1] || [];

				if (!_d[i].queue) {
					_d[i].queue = '';
				}

				if (!_d[i].mode) {
					if ($(i).style.display === 'block') {
						_d[i].mode = 'hide';
					} else {
						_d[i].mode = 'show';
					}
				}
				AOI_eff.setup(i);
			}
		},

		/*
		* Setup is called when a new effect starts.
		* It does not literally "setup" the effect information
		* It just uses it,  and passes it on.
		* Effects always count to 0,  so "step" should get closer to 0 no matter what.
		* We use a negative step for "hiding" because the change in the display gets larger
		* as time goes by (10 - step),  and a positive step for "showing" so the effect gets
		* smaller as time goes by (step).
		* If neither showing or hiding we just use a positive for ease of use.
		* The individual effects will the determine what we are doing. EG flashing or highlighting.
		*/

		setup: function (i) {

			if ($(i)) { /*Stop for invalid ID*/
				if (_d[i].mode === 'hide') {
					_d[i].step = -10;

					AOI_eff.ready(i, 'hide');
				} else if (_d[i].mode === 'show') {

					_d[i].step = 10;
					AOI_eff.ready(i, 'show');
				} else if (_d[i].mode === 'other') {
					_d[i].step = 10;
					AOI_eff.ready(i, 'other');
				}

				if (!_d[i].delay) {
					_d[i].delay = delay; /* If a delay is not specifically set,  set it.*/
				}

				AOI_eff.doit(i);
			} else {
				return false;
			}
		},

		/*
		*	Ready is called just before the effects start.
		*	 e is The syles of the current element we are working with.
		*	It is used to make a "show" effect start were whe want it too
		*	It also is used to "remember" the style defaults,  so the effects don't change them.
		*	If the effect is a "show" it also ensures the element is showing before effects start.
		*	m is the passed mode passed from the setup function (saves a lookup.)
		*/

		ready: function (i, m) {
			var e = $(i).style;
			switch (_d[i].eff) {
				case 'Expand':

					_d[i]['overflow'] = e.overflow;
					_d[i]['lineHeight'] = e.lineHeight;
					_d[i]['letterSpacing'] = e.letterSpacing;

					if (m === 'show') {
						e.overflow = 'hidden';
						e.lineHeight = '300%';
						e.letterSpacing = '1em';
					}

					break;
				case 'SlideUp':
					_d[i]['height'] = $(i).offsetHeight;

					if (m === 'show') { /*We need an object to be displayed to retrieve height.*/
						e.position='absolute'; /*Pull the element out of its default location*/
						e.visibility='hidden'; /*Hide the element*/
						e.display='block';/*"Display" the hidden element*/
						_d[i]['height'] = $(i).offsetHeight;
						e.visibility=''; /*Show it*/
						e.position='relative'; /*Put it back where it was*/
						e.height = '0px'; /*shrink it for the effect.*/
					}

					break;

				case 'ScrollLeft':
					_d[i]['marginLeft'] = e.marginLeft;
					if (m === 'show') {
						e.marginLeft = 80+'%';
					}
					break;
				case 'Fade':
					e.zoom = 1;/*IE fix*/
					if (m === 'show') {
						e.filter = 'alpha(opacity=0)';
						e.opacity = 0;
					}
					break;
			}

			if (m === 'show') {
				e.display = 'block';
			}
		},
		/*
		* Function doit does the actual effects
		* e is The syles of the current element we are working with.
		* m is the mode: 'show',  'hide' or 'other'
		* s is the current step (number between -10 and 10) with 0 being the end of the effect
		* v is just an empty variable for effects to use.
		*/
		doit: function (i) {
			var e = $(i).style; /**/
			var m = _d[i].mode;
			var s = _d[i].step;
			var v = 0;

			if ( _d[i].step !== 0  ) {
				switch (_d[i].eff) {
					case 'Expand':
						if 	( m === 'hide' ) {
							v = (100+ (10+s)*20); /*IE fix*/
							e.lineHeight = v+'%';
							e.letterSpacing = ((10+s)*3)+'px';
							_d[i].step += 1;
						} else {
							v = (300 - (10-s)*20);/*IE fix*/
							e.lineHeight = v+'%';
							e.letterSpacing = s*2+'px';
							_d[i].step -= 1;
						}
					break;

					case 'SlideUp':
						if 	( m === 'hide' ) {
							e.height =  Math.floor( _d[i]['height']*s*-0.1)+'px';
							_d[i].step += 1;
						} else {
							e.height = Math.floor( _d[i]['height']*(10-s)*0.1)+'px';
							_d[i].step -= 1;
						}
					break;

					case 'ScrollLeft':

						if 	( m === 'hide' ) {
							if ((!window.innerHeight && s < -3) || window.innerHeight ) {/*IE fix*/
								e.marginLeft=((10 + s)*10)+'%';
							}
							_d[i].step += 1;
						} else {
							e.marginLeft=(s*8)+'%';
							_d[i].step -= 1;
						}
					break;

					case 'Fade' :
						if 	( m === 'hide' ) {
							e.opacity = (s)/-10;
							e.filter = 'alpha(opacity='+(s*-10)+')';
							_d[i].step+= 1;
						} else {
							e.filter = 'alpha(opacity='+((10-s)*10)+')';
							e.opacity = (10 - s)/10;
							_d[i].step -= 1;
						}
						break;
					default:
						_d[i].step = 0;
						break;

				}
					setTimeout("AOI_eff.doit('"+i+"');",  _d[i].delay); /*Call next frame after delay.*/
			} else {
				AOI_eff.finish(i); /*Clean up*/
			}
		},
		/*
		* Function finish performs any final duties:
		*	hides element when "hiding"
		*	Restores defaults after effects are finished:
		*	eg after shrinking an elelemnt it's height is returned to normal.
		* it will then process the queue and start the next effect if needed.
		* Variable "d2": dummy variable to temporarily hold next effects information (while_d[i] is still in use)
		* variable "var": an array of the values for the next effect.
		* e is The syles of the current element we are working with.
		*/
		finish: function (i) {
			var e = $(i).style; /**/
			if ( _d[i].mode === 'hide' ) {
				e.display = 'none';
			}

			switch (_d[i].eff) {
				case 'Expand':
					if ( _d[i]['overflow'] ) {
						e.overflow = _d[i]['overflow'];
					}

					e.lineHeight ="normal";
					e.letterSpacing ="normal";

					break;
				case 'SlideUp':
					e.height = _d[i]['height']+'px';
					break;
				case 'ScrollLeft':
					e.marginLeft = _d[i]['marginLeft'] ;
					break;
				default :
					e.opacity = 10;
					e.filter = 'alpha(Opacity=100)';
			}

			if ( _d[i].queue.length > 0 ) {/* Checks to see if there is another effect*/
				var val;

				val = _d[i].queue.shift().split('::'); /*Gets values for first queue'd item*/
				if (!val[2]) { /*Sets effect*/
					val[2] = _d[i].eff;
				}
				if (!val[3]) { /*Sets effect*/
					val[3] = _d[i].delay;
				}

				d2 = {'mode': val[0],  'eff': val[2],  'queue': _d[i].queue,  'delay': _d[i].delay}; /*Sets values in dummy variable*/

				_d[i] = null;
				_d[val[1]] = [];
				_d[val[1]] = d2;
				AOI_eff.setup(val[1]);
			} else {
				_d[i] = null;
			}
		}
	};
}();