 /**
 * Write an email address to the screen. Helps so that bots can't parse email addresses from the site.
 *
 *     writeEmail("info", "info", "churchmedia.cc");
 *   <script type="text/javascript">writeEmail("info", "info", "mountainlake.tv");</script>
 * @param string
 * @param string
 * @param string
 */  
 
function writeEmail(contact, email, emailHost) {
  document.write("<a href=" + "&#109a&#105l" + "&#116&#111:" + email + "@" + emailHost+ ">" + contact + "@" + emailHost+"</a>");
}

jQuery(function($){
      
    // init tooltip (on bottom, centered) for any a href with class .tooltip
	$('a.tooltip_right').each(function(){
		$(this).qtip({ 
			content: {text: false},
			position: {
				corner: {target: 'rightMiddle',tooltip: 'leftMiddle'}
			},
			style: {
				title: { 'font-size': 11 },
				width: 'auto',
				tip: 'leftMiddle',
				color: '#F3F6F7',
				background: '#7DAB00',
				textAlign: 'center',
				border: {
					width: 'auto',
					radius: 4,
					color: '#7DAB00'
				},
			}		
		}); 
	});

     	$(".playtrailer").click(function() {
	$("#videoplayer").html('<iframe width="640" height="360" src="http://www.youtube.com/embed/HN0Ud75a3XI?modestbranding=1&version=3&hl=en_US&rel=0&theme=dark&color=red&hd=1&autoplay=1" frameborder="0" allowfullscreen></iframe>');
	return false;
	  });  
    
	  

	$("a.fade img").hover(function() {
		// animate opacity to full
		$(this).stop().animate({ opacity: 0.75 }, 200); 
	},
		// on mouse out
		function () {
			// animate opacity to nill
			$(this).stop().animate({ opacity: 1 }, 200);
		});




	/* Accordion menu */
	$('.menu-accordion').accordionMenu({ mode:'slide' });
	
	/* Smoothscroller */
	$('a[href="#page"]').smoothScroller({ duration: 500 });

	/* Spotlight */
	$('.spotlight').spotlight({fade: 300});

    var matchHeight = function(selector, deepest) {
        
        var deepest  = deepest || ".deepest";
        var elements = $(selector);
        var max      = 0;

        elements.each(function(){
            max = Math.max(max, $(this).outerHeight());
        });
        
        
        elements.each(function(){
            var box = $(this),
                ele = box.find(deepest+":first"),
                height = (ele.height() + (max - box.outerHeight()));

            ele.css("min-height", height+"px");
        });
    };  

	/* Match height of div tags */
	var matchHeights = function() {
		
		matchHeight('#top > .horizontal');
		matchHeight('#bottom .bottom-1 > .horizontal');
		matchHeight('#maintop > .horizontal');
		matchHeight('#mainbottom > .horizontal');
		matchHeight('#contenttop > .horizontal');
		matchHeight('#contentbottom > .horizontal');

   // Revive commented out next line, and added following 2 lines to hide frontpage articles, other code in template.php and custom.css
 	$('#middle,#left,#right').matchHeight(20);    
	//$('#middle,#left,#right').matchHeight(0);      
	   // Revive commented out next line, and added following line to hide frontpage articles, other code in template.php and custom.css
   	$('#mainmiddle,#contentleft,#contentright').matchHeight(20);   
 //   $('#mainmiddle,#contentleft,#contentright').matchHeight(0);

		$('.wrapper-3').matchHeight($(window).height());

	};
	
	$('#top').matchWidth(".horizontal");
	$('#maintop').matchWidth(".horizontal");
	$('#contenttop').matchWidth(".horizontal");
	$('#mainbottom').matchWidth(".horizontal");
	$('#contenttop').matchWidth(".horizontal");
	$('#contentbottom').matchWidth(".horizontal");
	
	$('#menu').css("visibility", "hidden");
	
	$(window).bind("load", function(){
		
		matchHeights();
		
		/* Dropdown menu */
		$('#menu').dropdownMenu({ mode: 'slide', dropdownSelector: 'div.dropdown:first', fixWidth: true}).css("visibility", "visible");	
		
	})
	
});
