/* Add Second Level Menu */
$(document).ready(function(){  	  	
	$("ul.subnav").parent().append("<span></span>");
	
	//Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)
	$("ul.topnav li span").click(function() { //When trigger is clicked...
	
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	
	//Download and Purchase Links on Sermon Archives
	if ($('body').hasClass('ntype-kaltura-entry')){
		//Check for Purchase CD link
		if ($('.field-field-purchase-link').length > 0){
			$('#content-wrapper .node .content').addClass('purchase-present');
        	var link = $('.field-field-purchase-link .field-item').html();
            $('.field-field-purchase-link').append("<a href='" + link + "' target='_blank'>Purchase This Sermon CD</a>");
		}
		//Check for Download link
		if ($('.field-field-download-link').length > 0){
			$('#content-wrapper .node .content').addClass('download-present');
        	var link = $('.field-field-download-link .field-item').html();
            $('.field-field-download-link').append("<a href='" + link + "' target='_blank'>Download This Sermon</a>");
		}
	}
});
        


/* This writes out the email address in the bottom right Contact Us block */
function write_email(){
	var a = new Array('nfo', '@wrck', 'wrc-i', 'c.c', 'om');
	document.write("<a title='Send Email to wrc-info@wrckc.com' href='mailto:"+a[2]+a[0]+a[1]+a[3]+a[4]+"'>" +a[2]+a[0]+a[1]+a[3]+a[4]+"</a>");
}
