$(document).ready(function() {

	//menus init
    $("#navigation ul li").hover(function() {
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
    }, function() {
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');
    });
    
	//homepage
	function cycle(what) {
	    var $active = $(what + ' .active');
	    if (!$active.length) $active = $(what).children().last();
	    var $next =  $active.next().length ? $active.next() : $(what).children().first();
	    $active.addClass('last-active');
	    $next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 1000, function() { $active.removeClass('active last-active'); });
	}
	var slides = setInterval(function() { cycle('#slideshow'); }, 4000);
	var newsti = setInterval(function() { cycle('#newsticker'); }, 2000);
    $("#slideshow").css('visibility', 'visible');
	
	//default text
	$(".default").focus(function() {
        if ($(this).val() == $(this)[0].title) {
			$(this).removeClass("inactive");
			$(this).val("");
        }
    });
    $(".default").blur(function() {
        if ($(this).val() == "") {
            $(this).addClass("inactive");
            $(this).val($(this)[0].title);
        }
    });
    $(".default").blur();        

	//open external links in new window
	$('a[href^="http://"]').attr("target", "_blank");
});

function display(id) {
	for( var i = 0; i < document.getElementById('sections').childNodes.length; i++ ) {
		if (document.getElementById('sections').childNodes[i].style) document.getElementById('sections').childNodes[i].style.display = "none";
	}
	document.getElementById(id).style.display = "block";
}

function validateAmount(amount){
	if (amount.value.match( /^[0-9]+(\.([0-9]+))?$/)) return true;
	
	alert('You must enter a valid donation.');
	amount.focus();
	return false;
}

function validateDownload(thisform){
    var error='';
	var elem =thisform.elements;

	for (var i = 0; i < thisform.elements.length; i++){
		//alert(thisform.elements[i].name+ ' '+ thisform.elements[i].value);
		if (thisform.elements[i].value == ''){
			if(thisform.elements[i].name != 'phone')
				error += 'error ';	
		}
	}
	if (error.length == 0){
		thisform.submit();
		return true;
	
	} else {
		alert ("Please enter all required fields");
		return false;
	}
}

function validateForm(){
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.contact.elements['news'].value;
   if (reg.test(address) == false) {
      alert('Invalid Email Address');
      return false;
   }
}
	
function toggleVisibility(me) {
	alert('hi');
	var childNodeArray = document.getElementById('stateTexts').childNodes;
	for (i=0;i<childNodeArray.length;i++) {
		if (childNodeArray[i].id != null) {
			var z = document.getElementById(childNodeArray[i].id);
			z.style.visibility = 'hidden';
		}
	}	
	if (me.style.visibility=="hidden") {
		me.style.visibility="visible";
	} else {
		me.style.visibility="hidden";
	}
}
	
	
function showHover(id,onOff){
	if (onOff) {
		document.getElementById(id).style.visibility = 'visible';
	} else {
		document.getElementById(id).style.visibility = 'hidden';
	}
}