
function checkDonation(){
    var dnValue = document.frmmhocfdonate.frmmhocfdonatesel.value;
    if(dnValue.match(/^\d+$/)){
        document.frmmhocfpaypalbuy.os0.value = dnValue;
        //document.frmmhocfpaypalbuy.submit();
        $("#frmmhocfpaypalbuy").find(":image")[0].click();
    }
    else{
        //display alert for selecting a value
    }
}
function OtherDonation(){
    $('#frmmhocfpaypaldonate').find(':image')[0].click();
    //document.frmmhocfpaypaldonate.submit();
    return false;
}
function getParameterByName( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}

function newArticle(article_id){
	var size = getBrowserWindowSize();
	var height = size.height * 0.75;
	var width = size.width * 0.75;
	var top = (size.height - height)/2;
	var left = (size.width - width)/2; 
	window.open('article_viewer.html?article=' + article_id, "article_viewer", "resizable=0,height="  + height + ",width=" + width +",top=" + top + ",left=" + left);
}

function getBrowserWindowSize()
{
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' )
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	
	return {width:myWidth, height:myHeight};
}

var currentSlide = 1;
$(document).ready(function(){
	
	$('a.top_link').mouseenter(function(){
		
		$(this).addClass('isOver');
		//Placing sub nav correctly relative to parent
		//Gather info about placement and height of parent
		var container = $(this).parents('li');
		var subNav = container.find('ul');
		var myOffset = $(this).position();
		var myHeight = $(this).height();
		//Sub nav will be wide enough to accomodate widest child
		var childWidth = "";
		subNav.children('li').each(function(){
			subWidth = $(this).width();
			if(childWidth < subWidth){
				childWidth = subWidth;
			}
											 
		});
		var newTop = Number(myOffset.top) + Number(myHeight);
		//Package up all placement and width info
		var cssObj = {
			'top': newTop,
			'left': myOffset.left,
			'width': childWidth,
			'z-index': '9999'
		}
		subNav.css(cssObj);	
		subNav.children('li').css('width',childWidth);
		
	});
	
	
	
	$('a.top_link').mouseleave(function(){
		$(this).removeClass('isOver');
		var container = $(this).parents('li');
		var subNav = container.find('ul');
  		$('#nav').oneTime(100, "subnav", function() {								  								
			if(!subNav.hasClass('isOver')){
				subNav.css('left','-5000px');
			}
  		});			
		
		
	});
	
	$('.subnav').mouseenter(function(){
		$(this).addClass('isOver');
									 
									 
	});
	
	
	$('.subnav').mouseleave(function(){
		
		$(this).removeClass('isOver');
		
		if($(this).parents('li').hasClass('isOver')){
			alert('Over parent');
		};
		$(this).css('left','-5000px');	
									 
									 
	});	
	


	
	//Show first slide by default
	$('#carousel').find('#slide_1').css('display','block');
	$('#carousel').find('#control_1').addClass('current');
	$('#carousel a.slider').click(function(e){
		e.preventDefault();
		var myId = $(this).attr('id');
		var mySlide = '';
		$('#carousel').find('.slide').hide();
		//If it's a number slide, just show its slide
		if(myId != 'previous' && myId != 'next'){
			
			$(this).addClass('current');
			var myNumArray = myId.split('_');
			var myNum = myNumArray[1];
			mySlide = 'slide_' + myNum;
			$('#carousel').find('a').removeClass('current');
			$(this).addClass('current');
			$('#' + mySlide).show();
			currentSlide = myNum;
		}
		//...if it's next or previous
		if(myId == 'next' || myId == 'previous'){
			var currentSlideObj = $('#carousel').find('a.current')
			var currentSlideString = currentSlideObj.attr('id');
			var currentSlideArray = currentSlideString.split('_');
			var currentSlide = Number(currentSlideArray[1]);
			var totalSlides = $('#carousel_control').find('li').length - 2;//remember to not count prev and next
			if(myId == 'next'){
				if(currentSlide < totalSlides){
					currentSlide++;
				} else if(currentSlide >= totalSlides){
					currentSlide = 1;
				}
			}
			if(myId == 'previous'){
				if(currentSlide > 1){
					currentSlide--;
				} else if(currentSlide == 1){
					currentSlide = totalSlides;
				}
			}
			mySlide = 'slide_' + currentSlide;
			var myCurrent = 'control_' + currentSlide;
			$('#carousel').find('a').removeClass('current');
			$('#' + myCurrent).addClass('current');
			$('#' + mySlide).show();
		}
		
		
		
		
								  
	});	
	
	function rotateMaryHassCarousel(){
	    currentSlide = (currentSlide >= 4) ? 1:(currentSlide + 1);
	    var slideID = "control_" + currentSlide;
        $('#' + slideID).click();
    }
    window.setInterval(rotateMaryHassCarousel, 10000);

});


