
function PrayerHighlighter()
{
	this.map;

	this.init = function(mapElId)
	{
		this.map = mapElId;
	};

	this.over = function(parent)
	{
		for( var itr = 0; itr < parent.childNodes.length; itr++ )
		{
			var node = parent.childNodes[itr];
			if( node.nodeType == 1 )
			{
				if( node.className.toLowerCase().indexOf( 'tools') != -1 )
				{
					YAHOO.util.Dom.setStyle( node, 'display', 'block' );
				}
			}
		}		
	};

	this.out = function(parent)
	{
		for( var itr = 0; itr < parent.childNodes.length; itr++ )
		{
			var node = parent.childNodes[itr];
			if( node.nodeType == 1 )
			{
				if( node.className.toLowerCase().indexOf( 'tools') != -1 )
				{
					YAHOO.util.Dom.setStyle( node, 'display', 'none' );
				}
			}
		}		
	};

	this.click = function(node)
	{
		location.href = ZPBCONFIG.url + node.id.replace('prayer', '' );
	};
}


function setupDirCalls()
{
	var chigh      = new PrayerHighlighter();
	chigh.init('map');

	var highlights = new Highlighter();
	highlights.add( 'prayerresults', 'prayer', { 'overcallback' : chigh.over, 'outcallback' : chigh.out,  'clickcallback' : chigh.click,'highlight' : false } );
	highlights.init();
}

Loader.add( setupDirCalls );

function toggleSettings(elId, height, forceHide)
{
	var display = YAHOO.util.Dom.getStyle(elId, 'display');
	if(  display == 'block' || forceHide )
	{
		YAHOO.util.Dom.setStyle(elId, 'display', 'none'); 
		var attributes = { 
			'height': { to: 0 } 
		}; 
		var anim = new YAHOO.util.Anim(elId, attributes, 0.5, YAHOO.util.Easing.easeBoth); 
		anim.onComplete.subscribe( function() { YAHOO.util.Dom.setStyle(elId, 'display', 'none'); } );
	}
	else
	{
		YAHOO.util.Dom.setStyle(elId, 'display', 'block'); 
		var attributes = { 
			'height': { from : 0, to: height } 
		}; 
		var anim = new YAHOO.util.Anim(elId, attributes, 0.5, YAHOO.util.Easing.easeBoth); 
	}
	//anim.animate();
}

function addToPrayerList(elId, prayerId, args )
{
	var addcss = 'favorite-on';
	if( args.addclass )
	{
		addcss = args.addclass;
	}
	var removecss = 'favorite-icon';
	if( args.removecss )
	{
		removecss = args.removeclass;
	}
	fadeInOut( elId, { 'addclass' : addcss, 'removeclass' : removecss,'innerHTML' : ZPBCONFIG.prayer_added_label } );

	var fields = [ 'prayerid', 'userid', 'createdate' ];
	var values = [ prayerId, Z_USER.ID, Z_TODAY ];
	var config = { fields : fields ,values : values, url : ZPBCONFIG.base_url	};
	Utils.send( 'PrayerList', 'save', config );
}

function togglePrayer( elId, prayerId, args )
{
	var offclass = 'favorite-icon';
	if( args.offclass )
	{
		offclass = args.offclass;
	}
	var el = document.getElementById( elId );
	if( YAHOO.util.Dom.hasClass( el, offclass ) )
	{
		addToPrayerList( elId, prayerId, args );
	}
	else
	{
		removeFromPrayerList( elId, prayerId, args );
	}
}

function removeFromPrayerList(elId, prayerId, args )
{
	var addcss = 'favorite-icon';
	if( args.addclass )
	{
		addcss = args.addclass;
	}
	var removecss = 'favorite-on';
	if( args.removeclass )
	{
		removecss = args.removeclass;
	}
	fadeInOut( elId, { 'addclass' : addcss, 'removeclass' : removecss,'innerHTML' : ZPBCONFIG.list_removed_label } ); //, 'oncomplete' : 

	// 

		//	YAHOO.util.Dom.removeClass( el, 'listAdded' );

	var remove = ZPBCONFIG.remove_prayer_label;
	if( remove != '' )
	{	
		var el = document.getElementById( elId );
		var i = 0;
		while( ! YAHOO.util.Dom.hasClass( el, 'prayer' ) && i++ < 11 )
		{
			el = el.parentNode;
		}
		
		fadeOutRemove( el.id );
	}

	var fields = [ 'prayerid', 'userid'];
	var values = [ prayerId, Z_USER.ID ];
	var config = { fields : fields ,values : values, url : ZPBCONFIG.base_url	};
	Utils.send( 'PrayerList', 'delete', config );
}

function fadeInOut( elId, args )
{
	var el = document.getElementById( elId );
	var attributes = { 
		'opacity': { from : 1.0, to: 0 } 
	}; 
	if( args.attributes )
	{
		attributes = args.attributes;
	}
	var anim = new YAHOO.util.Anim(elId, attributes, 0.5, YAHOO.util.Easing.easeBoth); 
	anim.onComplete.subscribe( function() { 

		if( args.removeclass )
		{
			YAHOO.util.Dom.removeClass( el, args.removeclass);
		}
		if( args.addclass )
		{
			YAHOO.util.Dom.addClass( el, args.addclass);
		}
		if( args.replaceInnerHTML )
		{
			el.innerHTML = args.replaceInnerHTML;
		}
		var attributes2 = { 
			'opacity': { from : 0, to: 1.0 } 
		}; 
		var anim2 = new YAHOO.util.Anim(elId, attributes2, 0.5, YAHOO.util.Easing.easeBoth);
		
		if( args.oncomplete )
		{
			anim2.onComplete.subscribe( function() { eval( args.oncomplete ); } );
		}

		anim2.animate();  
	} );
	anim.animate();
}

function fadeOutRemove(elId, args )
{
	var el = document.getElementById( elId );
	var attributes = { 
		'opacity': { from : 1.0, to: 0 } 
	}; 
	var anim = new YAHOO.util.Anim(elId, attributes, 0.5, YAHOO.util.Easing.easeBoth); 
	anim.onComplete.subscribe( function() { 
		YAHOO.util.Dom.setStyle( el, 'display', 'none' );

		if( args.removeclass )
		{
			YAHOO.util.Dom.removeClass( el, args.removeclass);
		}
		if( args.addclass )
		{
			YAHOO.util.Dom.addClass( el, args.addclass);
		}

	} );
	anim.animate();
}

function deletePrayer(elId, prayerId,args )
{
	fadeOutRemove( elId );
	var fields = [ 'id', 'createuserid',];
	var values = [ prayerId, Z_USER.ID ];
	var config = { fields : fields ,values : values, url : ZPBCONFIG.base_url	};
	Utils.send( 'Prayer', 'delete', config );
}



function toggleSupport( elId, prayerId, args )
{
	if( args == 'nosupport' )
	{
		args = { 'offclass' : 'nosupport', 'addclass' : 'hassupport', 'removeclass' : 'nosupport', 'mode' : 'nosupport' };
	}
	else
	{
		args = {  'offclass' : 'nosupport', 'addclass' : 'nosupport', 'removeclass' : 'hassupport', 'mode' : 'hassupport' }; 
	}

	var offclass = 'favorite-icon';
	if( args.offclass )
	{
		offclass = args.offclass;
	}
	
	//new Dialog().showMessage('Dialog', 'Hello World2.' + elId);
	
	//var el = document.getElementById( elId );
	//new Dialog().showMessage('Dialog', 'Hello World.' + elId + ' | ' + offclass + el.hasClassName( offclass ));
	if( args.mode == 'nosupport' )
	{
		addSupport( elId, prayerId, args );
	}
	else
	{
		removeSupport( elId, prayerId, args );
	}
}

function addSupport(elId, prayerId, args )
{
	var addcss = 'favorite-on';
	if( args.addclass )
	{
		addcss = args.addclass;
	}
	var removecss = 'favorite-icon';
	if( args.removecss )
	{
		removecss = args.removeclass;
	}
	
	var supportlist = YAHOO.util.Dom.get( 'supporters' );
	var newNode     = document.createElement('div');
	newNode.id      = 'supporter' + Z_USER.ID;
	YAHOO.util.Dom.setStyle( newNode, 'padding', '5px' );
	YAHOO.util.Dom.setStyle( newNode, 'float', 'left' );
	newNode.innerHTML = '<a href="'+Z_USER.URL+'" rel="nofollow">'+Z_USER.LABEL+'</a>'

	var nosupport = YAHOO.util.Dom.get( 'blanksupporters' );
	if( nosupport && YAHOO.util.Dom.getStyle( nosupport, 'display' ) != 'none' )
	{	
		fadeOutRemove( nosupport.id );

		var newNodeh3       = document.createElement('h3');
		newNodeh3.innerHTML   = ZPBCONFIG.supporters_label;
		YAHOO.util.Dom.setStyle( supportlist, 'opacity', '0' );
		supportlist.insertBefore( newNodeh3, supportlist.firstChild );
		supportlist.appendChild( newNode );
		fadeInOut( supportlist, { 'addclass' : addcss, 'removeclass' : removecss, attributes : { 'opacity': { from : 0, to: 0 } } } );

	}
	else
	{
		YAHOO.util.Dom.setStyle( newNode, 'opacity', '0' );
		supportlist.appendChild( newNode );
		fadeInOut( newNode, { 'addclass' : addcss, 'removeclass' : removecss, attributes : { 'opacity': { from : 0, to: 0 } } } );
		newNode.innerHTML = '<a href="'+Z_USER.URL+'" rel="nofollow">'+Z_USER.LABEL+'</a>'
	}
	
	
	fadeInOut( elId, { 'addclass' : addcss, 'removeclass' : removecss,'replaceInnerHTML' : ZPBCONFIG.support_added_label } );
	
	var fields = [ 'prayerid', 'fromuserid', 'createdate', 'type', 'status' ];
	var values = [ prayerId, Z_USER.ID, Z_TODAY, '1', '2' ];
	var config = { fields : fields ,values : values, url : ZPBCONFIG.base_url	};
	Utils.send( 'PrayerSupport', 'save', config );
}


function removeSupport(elId, z_prayerId, args )
{
	var addcss = 'favorite-icon';
	if( args.addclass )
	{
		addcss = args.addclass;
	}
	var removecss = 'favorite-on';
	if( args.removeclass )
	{
		removecss = args.removeclass;
	}


	var fields = [ 'prayerid', 'fromuserid'];
	var values = [ z_prayerId, Z_USER.ID ];
	var config = { fields : fields ,values : values, url : ZPBCONFIG.base_url	};
	Utils.send( 'PrayerSupport', 'delete', config );

	fadeInOut( elId, { 'addclass' : addcss, 'removeclass' : removecss,'replaceInnerHTML' : ZPBCONFIG.support_removed_label } );
	fadeOutRemove( 'supporter' + Z_USER.ID );
}



(function() {
	

var els = YAHOO.util.Dom.getChildren('prayernav'), el =  YAHOO.util.Dom.getElementsByClassName('postprayerlink', 'a'), el2 =  YAHOO.util.Dom.getElementsByClassName('postchainwrap', 'div');

if (el && el[0])
{
	YAHOO.util.Event.addListener(el[0], 'mouseover', postnavover);
	YAHOO.util.Event.addListener(el[0], 'mouseout', postnavover);
}

if (el2 && el2[0])
{
	YAHOO.util.Event.addListener(el2[0], 'mouseover', postchainover);
	YAHOO.util.Event.addListener(el2[0], 'mouseout', postchainover);
}

for( var i=0; i < els.length; i++ )
{
	var kids = YAHOO.util.Dom.getChildren(els[i]);
	for( var k=0; k < kids.length;k++ )
	{
		if( kids[k].nodeName.toUpperCase() == 'A' )
		{
			YAHOO.util.Event.addListener(kids[k], 'mouseover', prayernavover);
			YAHOO.util.Event.addListener(kids[k], 'mouseout', prayernavover);
	}
	}
	//YAHOO.util.Event.addListener(els[i], 'mouseout', prayernavover);
}

})();

function prayernavover(e) {
	YAHOO.util.Event.stopEvent(e); 
	var i=0, el = YAHOO.util.Event.getTarget(e); 
	while( el.nodeName.toUpperCase() != "LI" && ++i<5) 
	{
		el = el.parentNode;
	}

	if( ! YAHOO.util.Dom.hasClass( el, 'forceon'  )  )
	{
		if( YAHOO.util.Dom.hasClass( el, 'myp'  )  )
		{
			if( ! YAHOO.util.Dom.hasClass( el, 'mypon'  ) )
			{
				YAHOO.util.Dom.addClass( el, 'mypon' );
				YAHOO.util.Dom.removeClass( el, 'mypoff' );
			}
			else
			{
				YAHOO.util.Dom.addClass( el, 'mypoff' );
				YAHOO.util.Dom.removeClass( el, 'mypon' );

			}
		}
		else if( YAHOO.util.Dom.hasClass( el, 'myr'  )  )
		{
			if( ! YAHOO.util.Dom.hasClass( el, 'myron'  ) )
			{
				YAHOO.util.Dom.addClass( el, 'myron' );
				YAHOO.util.Dom.removeClass( el, 'myroff' );
			}
			else
			{
				YAHOO.util.Dom.addClass( el, 'myroff' );
				YAHOO.util.Dom.removeClass( el, 'myron' );

			}
		}
		else if( YAHOO.util.Dom.hasClass( el, 'my'  )  )
		{
			if( ! YAHOO.util.Dom.hasClass( el, 'myon'  ) )
			{
				YAHOO.util.Dom.addClass( el, 'myon' );
				YAHOO.util.Dom.removeClass( el, 'myoff' );
			}
			else
			{
				YAHOO.util.Dom.addClass( el, 'myoff' );
				YAHOO.util.Dom.removeClass( el, 'myon' );

			}
		}
		else if( YAHOO.util.Dom.hasClass( el, 'pc'  )  )
		{
			if( ! YAHOO.util.Dom.hasClass( el, 'pcon'  ) )
			{
				YAHOO.util.Dom.addClass( el, 'pcon' );
				YAHOO.util.Dom.removeClass( el, 'pcoff' );
			}
			else
			{
				YAHOO.util.Dom.addClass( el, 'pcoff' );
				YAHOO.util.Dom.removeClass( el, 'pcon' );

			}
		}
		else if( YAHOO.util.Dom.hasClass( el, 'all'  )  )
		{
			if( ! YAHOO.util.Dom.hasClass( el, 'allon'  ) )
			{
				YAHOO.util.Dom.addClass( el, 'allon' );
				YAHOO.util.Dom.removeClass( el, 'alloff' );
			}
			else
			{
				YAHOO.util.Dom.addClass( el, 'alloff' );
				YAHOO.util.Dom.removeClass( el, 'allon' );

			}
		}
	}
}

function postnavover(e) {
	YAHOO.util.Event.stopEvent(e); 
	var i=0, el = YAHOO.util.Event.getTarget(e); 
	while( el.nodeName.toUpperCase() != "DIV" && ++i<5) 
	{
		el = el.parentNode;
	}
   
	if( YAHOO.util.Dom.hasClass( el, 'postprayer'  )  )
	{
		if( ! YAHOO.util.Dom.hasClass( el, 'postprayeron'  ) )
		{
			YAHOO.util.Dom.addClass( el, 'postprayeron' );
			YAHOO.util.Dom.removeClass( el, 'postprayeroff' );
		}
		else
		{
			YAHOO.util.Dom.addClass( el, 'postprayeroff' );
			YAHOO.util.Dom.removeClass( el, 'postprayeron' );

		}
	}
}

function postchainover(e) {
	YAHOO.util.Event.stopEvent(e); 
	var i=0, el = YAHOO.util.Event.getTarget(e); 
	while( ( el.nodeName.toUpperCase() != "DIV" || ! YAHOO.util.Dom.hasClass( el, 'postchain' ) )  && ++i<5) 
	{
		el = el.parentNode;
	}
   
	if( YAHOO.util.Dom.hasClass( el, 'postchain' )  )
	{
		if( ! YAHOO.util.Dom.hasClass( el, 'postchainon'  ) )
		{
			YAHOO.util.Dom.addClass( el, 'postchainon' );
			YAHOO.util.Dom.removeClass( el, 'postchainoff' );
		}
		else
		{
			YAHOO.util.Dom.addClass( el, 'postchainoff' );
			YAHOO.util.Dom.removeClass( el, 'postchainon' );

		}
	}
}
