/* For testimonial */
var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;

/* For menu */
var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

$(document).ready(function(){
	
	// Fix the png issue in IE < 6
	//$(document).pngFix(); 
	
	// Register testimonial events
	headline_count = $("div.testimonial-data").size();
	if(headline_count > 0)
	{
		$("div.testimonial-data:eq("+current_headline+")").css('top', '5px');
			headline_interval = setInterval(headline_rotate,5000);
			$('#style-testimonial').hover(function() {
			clearInterval(headline_interval);
		}, function() {
			headline_interval = setInterval(headline_rotate,5000);
			headline_rotate();
	   });
	}
	
	// Register menu functionality
	$('#jsddm > li').bind('mouseover', jsddm_open);
	$('#jsddm > li').bind('mouseout',  jsddm_timer);
});

function headline_rotate()	// Rotate the testimonials
{
	current_headline = (old_headline + 1) % headline_count;
	$("div.testimonial-data:eq(" + old_headline + ")").animate({top: -105},"slow", function() {
		$(this).css('top', '110px');
	});
	$("div.testimonial-data:eq(" + current_headline + ")").animate({top: 5},"slow");
	old_headline = current_headline;
}

function Trim(s)	// Remove the spacing from the start and end.
{
	if(s != null && s != '' && s != ' ' && s.length > 0)
	{
		// Remove leading spaces and carriage returns
		while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
		{
		s = s.substring(1,s.length);
		}
		// Remove trailing spaces and carriage returns
		while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
		{
		s = s.substring(0,s.length-1);
		}
	}
	return s;
}

/* Menu functionality functions */
function jsddm_open()
{
	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').css('visibility', 'visible');
}

function jsddm_close()
{
	if(ddmenuitem)
		ddmenuitem.css('visibility', 'hidden');
}

function jsddm_timer()
{
	closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer()
{
	if(closetimer)
   	{
		window.clearTimeout(closetimer);
      	closetimer = null;
	}
}
document.onclick = jsddm_close;
/* Menu functionality functions end */
