function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
    }
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


function winHeight(){
    var winHeight = "innerHeight" in window
        ? window.innerHeight
        : document.documentElement.offsetHeight;
    return winHeight;
}

function goNav(){
	var url = window.location.pathname.split('/');
    var parent = url[1];
    var child = url[2];
    if (parent != ""){
        $('#menu-side-nav li').find("a[href*='" + parent + "']").first().html('Overview');
    }
    if(child == "employment-opportunities"){
        $('#menu-item-42').removeClass('current-menu-ancestor');
        $('#menu-item-42').removeClass('current-menu-parent');
        $('#menu-item-42').removeClass('current_page_parent');
        $('#menu-item-42').removeClass('current_page_ancestor');
    }
    if(child == "matching-gift-program"){
        $.colorbox.remove();
    }

}



function bgSwap(){
    var imgString = 'url(/wp-content/themes/hopetree/images/backgrounds/header/bg' + Math.ceil(Math.random()*4) + '.jpg) fixed 50% 0 no-repeat #D9BD9F';
    $("body").css('background', imgString);
}




    $(document).ready(function(){
        bgSwap();
        goNav();
        Cufon.replace('h2 em');
        Cufon.replace('h3', { textShadow: '1px 1px #444' });

        $('#submit_join').click(function(){
            var email = $('#subscribe').val();
            var dataString = 'email=' + email;

			$.ajax({
				type: "POST",
				url: "/wp-content/themes/hopetree/includes/functions/constant-contact.php",
				data: dataString,
				success: function(msg) {
					$("#join_list").fadeOut('slow', function(){
                        $("#join_list").css("background", "none");
                        $("#join_list").html('Thank you. <a href="/contact-us/information-request-form/?email='+email+'">Click here for more options</a>.');
                        $("#join_list").fadeIn();
                        $("#join_list").delay(3000).fadeOut();
                            createCookie('status','loggedin',21);
					});
				}
			});

		return false;
        });


    $('#menu-side-nav > li > a').first().html('Overview');

    $('.gallery-icon a').colorbox({speed:100, initialHeight: 0});
    $('#attachment_245 a').colorbox({speed:100, initialHeight: 0});


    $('.colorbox').colorbox({speed:100, initialHeight: 0, iframe: true, width: 900, height: winHeight() });

    var status = readCookie('status');
    if (status) { $("#join_list").hide(); }

    if((navigator.userAgent.match(/iPhone/i))
    || (navigator.userAgent.match(/iPad/i))
    || (navigator.userAgent.match(/iPod/i))
    || (navigator.userAgent.match(/iemobile/i))
    || (navigator.userAgent.match(/android/i))) {
        $('.logo_wrap').attr('id', 'logo').html('');
    }

});




















