var TractBehavior = Class.create();

TractBehavior.Apply = function() {

	var page = 1;
	var maxpage = 8;
	
	var textarray = $A();
	textarray[1] = '<span class="blackwhite_large">Earthquake<br><br>August 15, 2007</span>';
	textarray[2] = '<span class="blackwhite_normal">On August 15th, 2007, residents in the Department of Ica, Peru, went about their business as usual: shopping, selling, studying, etc.  As evening approached, a group of Pisco residents gathered at the San Clemente Church for a mass commemorating the deceased.  At 6:40pm, the ground slowly began to move back and forth.  Most people paused for a moment as is typical in this region where tremors are as common as street vendors.  Most soon realized that this was not a typical tremor; instead, it was quickly turning into a full-blown earthquake.  As the movement intensified, buildings began to succumb to the powerful pressure exerted by the 8.0 magnitude earthquake.  People stood, gripped with terror, as buildings began to fall around them.  Many fled their homes and watched from the street as their houses collapsed.  Others huddled together crying out to God as they listened to the screams around them.  When the earth finally stopped its awful waves, people paused, afraid, trying to grasp what they had just experienced.  Then began the frantic search for loved ones.  People, numb with terror, began desperately trying to make contact with family and friends, everyone fearing the worst.</span>';
	textarray[3] = '<span class="blackwhite_large">The Results</span><br><br><span class="blackwhite_normal">In the hours that followed, the extent of the damage, both in physical destruction and in loss of life, began to reveal itself.  An estimated 80% of the homes in Pisco became uninhabitable.  Many people would live days and weeks without running water or electricity.  The non-stop replicas forced people to seek dwelling out of their homes, in the cold, for fear that a wall or roof still standing would collapse.  Food prices doubled and tripled immediately, and then vendors ceased selling all together not knowing when they would be re-supplied.  A state of emergency was declared, but as aid began to arrive, looters began to take advantage almost as soon as the first trucks crossed into the region.  Long lines formed behind aid trucks that did arrive as folks waited to receive something to help them through the next cold night.  The death count rose quickly over the next few days indicating that over 500 people had died as a result of the earthquake.  In Pisco, the bodies of those who died inside the collapsed San Clemente Church were lined up at the front of the plaza as people began identifying the deceased.</span>';
	textarray[4] = '<span class="blackwhite_large">Why?</span><br><br><span class="blackwhite_normal">In the days that followed, the most pressing question in the hearts of folks throughout the country has been, <b>WHY</b>?  Do you wonder where God was?  Do you wonder why God would allow something so tragic and devastating to occur?  Rest assured, you are not alone in asking such questions.<br><br>God says in <b>Isaiah 55:8-9</b>, “For my thoughts are not your thoughts, neither are your ways my ways, declares the Lord.  For as the heavens are higher than the earth, so are my ways higher than your ways and my thoughts that your thoughts.”  Though this tragedy makes little sense to us, we must accept that it has taken place completely within the control of a sovereign, loving God.  Some people may be tempted to think that the Lord is evil or harsh for allowing this to happen.  <b>Psalm 92:15</b> tells us that “…the Lord is upright, he is my rock, and there is no unrighteousness in him.”  <b>Psalm 18:30</b> continues, “This God- his way is perfect…”</span>';
	textarray[5] = '<span class="blackwhite_large">What do I do now?</span><br><br><span class="blackwhite_normal">You may wonder what to do when you feel overwhelmed with grief, hurt or pain.  These feelings are natural as you try to make sense of such life-changing devastation.  Remember what the psalmist said in <b>Psalm 138:3</b>, “On the day I called, you answered me; my strength of soul you increased.”  You may think that God has abandoned you.  Nothing could be further from the truth.<br><br>Many times God allows difficult circumstances to unfold because he wants to get our attention.  He has allowed many to suffer during this time.  You may be one of those.  A portion of suffering in this life is good if it motivates you to make peace with God for eternity.</span>';	
	textarray[6] = '<span class="blackwhite_large">How does God want you to respond to this tragedy?</span><br><br><span class="blackwhite_normal"><b>First</b>, <u>you need to see God as he really is:</u> an all-powerful, holy God who holds the power of life and death in his hands.  <b>Psalm 66:3</b> says, “Say to God, ‘How awesome are your deeds!  So great is your power that your enemies come cringing to you.’”<br><br><b>Secondly</b>, <u>you ought to know that God is a loving God</u> who will extend his mercy to all who come humbly to him.  <b>Psalm 9:10</b> says, “And those who know your name put their trust in you, for you, O Lord, have not forsaken those who seek you.”</span>';
	textarray[7] = '<span class="blackwhite_normal"><b>Thirdly</b>, <u>God wants you to address the issue of your sin</u>.  Your sin is what separates you from God.  The Bible teaches that all people have sinned, “as it is written: None is righteous, no, not one.” (<b>Romans 3:10</b>).  Sin is rebellion against God, and we are not at peace with God until our sin issue has been dealt with.  However, God has provided the means for you to make peace with him.  When Jesus died on the cross, he died for us as sinners, “But God shows his love for us in that while we were still sinners, Christ died for us.” (<b>Romans 5:8</b>).  We are enemies of God, but because Jesus died for our sin we can be reconciled to God and be at peace with Him, “For if while we were enemies we were reconciled to God by the death of his Son, much more, now that we are reconciled, shall we be saved by his life.” (<b>Romans 5:10</b>).</span>';
	textarray[8] = '<span class="blackwhite_normal"><b>Finally</b>, <u>God wants you to make the decision to make peace with Him.</u>  God allowed his own son to suffer and die so that you could be saved from your sin and have peace with God.  How do you do that?  You make peace with God, by calling on Him to save you from your sin and to give you the privilege of spending eternity in heaven with Him.  <b>Romans 10:13</b>	 says, “For everyone who calls on the name of the Lord will be saved.”<br><br>If you are willing to trust Jesus to save you, give you peace, and restore hope in your life simply ask Him to do that.  Believe that He really is there, that He loves you, and that He will do what He promises.</span>';	
	
	var lnkNext = $('tract').down('.next');
	lnkNext.onclick = function() {
		if (page == maxpage) {
			page = 1;
	    }
		else {
			page++;
		}
		
		// Insert new pic
		var ePic = $('tract').down('.pic');
		Element.update(ePic, '<img src="images/tract/tract'+page+'.jpg" />');
		
		// Insert new text
		var ePic = $('tract').down('.text');
		Element.update(ePic, textarray[page]);

		checkPrevNext();

	};
	
	var lnkPrev = $('tract').down('.prev');
	if (page == 1) {
		Element.addClassName(lnkPrev, 'hidden');
	}
	lnkPrev.onclick = function() {
		if (page == 1) {
			page = maxpage;
	    }
		else {
			page--;
		}
		
		// Insert new pic
		var ePic = $('tract').down('.pic');
		Element.update(ePic, '<img src="images/tract/tract'+page+'.jpg" />');
		
		// Insert new text
		var ePic = $('tract').down('.text');
		Element.update(ePic, textarray[page]);

		checkPrevNext();

	};
	
	function checkPrevNext() {
		// Check if need next link
		var lnkNext = $('tract').down('.next');
		if (page == maxpage) {
			Element.addClassName(lnkNext, 'hidden');
		}
		else {
			Element.removeClassName(lnkNext, 'hidden');
		}
		
		// Check if need prev link
		var lnkPrev = $('tract').down('.prev');
		if (page == 1) {
			Element.addClassName(lnkPrev, 'hidden');
		}
		else {
			Element.removeClassName(lnkPrev, 'hidden');
		}
	}
	
};