var intTestimonials = 0;
var intTestimonyCounter = 0;
var testimonyTimer = null;
var bTimerIsOn = 0;

//jQuery.noConflict();

//Setup the click event handler
if (document.layers)
{
	document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=clickEventCatcher;

/**
  * Retrieve the number of testimonies from the database.
 **/
Event.observe(window, 'load', function() {

	
	oMySlides = new iSlideShow({
 	autostart 	: true,		// optional, boolean (default:true)
 	start		: 0,	 	// optional, slides[start] (default:0) 
 	wait 		: 10000, 	// optional, milliseconds (default:4s)
 	slides 		: [
 					'image-1', 
 					'image-2'					
 				  ]
	});	
});

/**
  * Capture the click events of the mouse
 **/
function clickEventCatcher(e)
{
	var strMessage = "Powered by NacSoft LLC.";
	
	if (document.all)
	{
		if (e.button==2 || e.button == 3 || e.button == 6 || e.button ==7)
		{
			alert(strMessage);
			//return false;
		}
	} else {
		if (e.button==2 || e.button == 3 || e.button == 6 || e.button ==7)
		{
			alert(strMessage);
			//return false;
		}
	}
	
	if (document.layers)
	{
		alert('Layers');
		if (e.which == 3)
		{
			//alert(strMessage);
			return false;
		}
	}
}

/**
  * Starts the testimonials.
  * This is loaded from the home page (home.ctp)
**/
function startTestimonialLoader()
{
	//Setup the testimonial loader
	new Ajax.Request('/testimonials/countfeedback', 
	{
		method: 'get',
		onSuccess: function (transport)
		{
			intTestimonials = transport.responseText.evalJSON();
			intTestimonyCounter = 1;
			bTimerIsOn = 1;			
			loadTestimonies();
		}
	});
}
/**
  * Loads a tetimonial entry from the database 
  * on the home page every 15 seconds.
 **/
function loadTestimonies()
{
	new Ajax.Request('/testimonials/feedback/'+intTestimonyCounter, {
		method: 'get',
		onSuccess: function(transport)
		{
			var response = transport.responseText.evalJSON();						
			$('client_feedback').innerHTML = '<p id="comment_' + intTestimonyCounter  + '" class="regular">"' + response.comment + '"<br/><span class="location">' + response.location + '</span></p>' + $('client_feedback').innerHTML;
			//new Effect.Appear('comment_'+intTestimonyCounter, {duration: 5.0 });			
		}
	});
	intTestimonyCounter++;
	if (intTestimonyCounter == intTestimonials) intTestimonyCounter = 1
	testimonyTimer = setTimeout("loadTestimonies()", 15000);
}


/**
  * Toggles (shows/hides) the given element.
  * @param: element ID
**/
function toggleElement(objElement)
{
	if (objElement == null) return false;
	
	var e = document.getElementById(objElement);
	
	if (e.style.display == 'none') 
	{		
		e.style.display = 'block';
	} else {
		e.style.display = 'none';
	}
}

/**
  * Displays the credit card info elements 
  * on the signup page
 **/
function showCCInfo()
{	
	var e = document.getElementById('UserPaymentMethod');	
	if (e.options[e.selectedIndex].value  == '3' || e.options[e.selectedIndex].value == '4')
	{
		toggleElement('ccinfo');
	} else {		
		if (document.getElementById('ccinfo').style.display == 'block')
		{
			toggleElement('ccinfo');
		}
	}	
}
