// start by getting all the questions and answers
// these will be put into arrays

var questions = document.getElementsByTagName('dt');
var answers = document.getElementsByTagName('dd');

// function for the link that turns them all off
function toggleAllOff()
{
	for (var i = 0; i < answers.length; i++)
	{ 
		answers[i].className = 'hide';
	}
}

// function for the link that turns them all on
function toggleAllOn()
{
	for (var i = 0; i < answers.length; i++)
	{ 
		answers[i].className = 'show';
	}
}


function toggleNext(el)
{
	 var next=el.nextSibling;
	 next.style.display=((next.style.display=="none") ? "block" : "none");
}


//makes the definition lists click-able
function displayToggle()
{
	
	toggleAllOff(); // calls the toggle all off function to turn all the answers off when the page is loaded	
	 
	 for (i=0; i<questions.length; i++)
	 { // loops through the questions a
		 questions[i].onclick=function()
		 { // shows the answers onclick
		 	var next = this.nextSibling;
			while(next.nodeType != 1) next=next.nextSibling; // if it gets to a non-element node, go to the next one
			next.className=((next.className=="hide") ? "show" : "hide");
		}
	 }
}

// initiates the click-able dt's when the page loads
window.onload=function() 
{
	displayToggle();
}

function show_toggle()
{
    $('#videos-sn').show('slow');
    $('.toggle').removeClass('hidden');
    $('.toggle').addClass('showing');
    $('#videos-sn').css('background','url("./Images/left_nav_box_dark_grey.png")'); 
    return false;
}	

function view_toggle(toggle, field)
{
	if( $(toggle).is('.showing') )
	{
    $(field).hide('slow');
    $(toggle).removeClass('showing');
    $(toggle).addClass('hidden');
   }
   else 
   {
    $(field).show('slow');
    $(toggle).removeClass('hidden');
    $(toggle).addClass('showing');
   }
   return false;
}

function slideShow() 
{
	$('#sponsorList a').css({opacity: 0.0});
	
	$('#sponsorList a:first').css({opacity: 1.0});

	setInterval('sponsorList()',3000);
}

function sponsorList()
{
	var current = ($('#sponsorList a.show')?  $('#sponsorList a.show') : $('#sponsorList a:first'));

	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#sponsorList a:first') :current.next()) : $('#sponsorList a:first'));

	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);

	current.animate({opacity: 0.0}, 1000).removeClass('show');
}

function slideShow1() 
{
	$('#gallery a').css({opacity: 0});

	$('#gallery a:first').css({opacity: 1.0});

	$('#gallery .caption').css({opacity: 0.8});

	$('#gallery .caption').css({width: $('#gallery a').find('img').css('width')});

	$('#gallery .content').html($('#gallery a:first').find('img').attr('rel')).animate({opacity: 0.8}, 400);

	setInterval('gallery()',8000);
}

function gallery()
{
	var current = ($('#gallery a.show')?  $('#gallery a.show') : $('#gallery a:first'));

	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery a:first') :current.next()) : $('#gallery a:first'));

	var caption = next.find('img').attr('rel');

	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1500);

	current.animate({opacity: 0.0}, 1000).removeClass('show');

	$('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });

	$('#gallery .caption').animate({opacity: 0.8},200 ).animate({height: '90px'},1000 );

	$('#gallery .content').html(caption);
}


	$(function()
	{
		// The height of the content block when it's not expanded
		var adjustheight = 25; //71
		// The "more" link text
		var moreText = "Show More";
		// The "less" link text
		var lessText = "Hide";

		// Sets the .more-block div to the specified height and hides any content that overflows
		$(".more-less .more-block").css('height', adjustheight).css('overflow', 'hidden');

		// The section added to the bottom of the "more-less" div
		$(".more-less").append('<a style="margin-top:6px" href="#" class="adjust"></a>');

		$("a.adjust").text(moreText);

		$(".adjust").toggle(function()
		{$
			$(this).parents("div:first").find(".more-block").css('height', 'auto').css('overflow', 'visible').css('display', 'block');
		
			$(this).text(lessText);
		},
		function() 
		{
			$(this).parents("div:first").find(".more-block").css('height', adjustheight).css('overflow', 'hidden').slideUp();
			
			$(this).text(moreText);
		});
	});

//for scrolling quotes

var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;

$(document).ready(function()
{
  headline_count = $("div.headline").size();
  $("div.headline:eq("+current_headline+")").css('top', '5px');
  headline_interval = setInterval(headline_rotate,4000);
  $('#scrollup').hover(function() 
  {
	 clearInterval(headline_interval);
  },
  function()
  {
 	headline_interval = setInterval(headline_rotate,4000);
 	headline_rotate();
  });  
});

function headline_rotate()
{
  current_headline = (old_headline + 1) % headline_count;
  $("div.headline:eq(" + old_headline + ")")
 .animate({top: -205},"slow", function() 
 {
   $(this).css('top', '210px');
 });
 $("div.headline:eq(" + current_headline + ")").animate({top: 5},"slow");
 old_headline = current_headline;
}


// to insert date
$(function($) 
{
	 var options3 =
	 {
	   format: '%A, %B %d, %Y '
	 }
	 
	 $('.date').jclock(options3);
});

function echeck(str) 
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1)
	{
		$('#errorlbl').html("Invalid E-mail ID");
   		return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	{
	   $('#errorlbl').html("Invalid E-mail ID");
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
	{
		$('#errorlbl').html("Invalid E-mail ID");
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1)
	 {
		$('#errorlbl').html("Invalid E-mail ID");
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	 {
		$('#errorlbl').html("Invalid E-mail ID");
	    return false
	 }

 	if (str.indexOf(dot,(lat+2))==-1)
 	{
	   $('#errorlbl').html("Invalid E-mail ID");
 	   return false
	}

	if (str.indexOf(" ")!=-1)
	{
		$('#errorlbl').html("Invalid E-mail ID");
    	return false
 	}

  	return true
}

$(document).ready(function()
{
	$('#submit').click(function()
	{
		if (echeck($('.emailTxt').val())==false)
		{	
			$('.emailTxt').focus();
			return false
		}
		else
		{
			$('#errorlbl').html("");
			return true
		}
	});
});
