/* Author: The Dam of Knowledge
	http://www.damofknowledge.com

*/

//autoload external links in new window
		$("a[href^='http:']:not([href*='" + window.location.host + "'])").each(function() {               
			$(this).attr("rel", "external");
		});
		
		$('a[rel="external"]').click( function() {
			window.open( $(this).attr('href') );
			return false;
		});
		$('a[rel="external nofollow"]').click( function() {
			window.open( $(this).attr('href') );
			return false;
		});

$('a.sermon').click( function(ev) {
	window.open( $(this).attr('href'),'SermonWindow','width=575,height=215,location=no');
	ev.preventDefault();
	return false;
});

$('a.video').click( function(ev) {
	window.open( $(this).attr('href'),'VideoWindow','width=640,height=390,location=no');
	ev.preventDefault();
	return false;
});

// IE8 remove generated content on all elements + :last-child with CSS, add it to siblings of :last-child with jQuery
// Fixes possible bug with IE8, (nav ul li:last-child:after) not recognized in CSS when used with IE9.js support
if($.browser.msie && jQuery.browser.version.substr(0,1)=="8") {
	$("nav ul li").last().siblings().append('/');
	$("#nav ul li").last().siblings().append('/');
	$("#upcoming-events .col:last-child, #latest-videos .col:last-child, #latest-sermons .col:last-child").css({margin:'0'});
};

if ($('article#page').height() > 500 || $('section#page').height() > 500) {
	$('section#page, article#page').css('background-position','301px top');
}

// Hacky hack to get #main padding correct, when #main positioned relative and moved up above header -199px. Negative margin-bottom not correcting issue.
$('.page-template-calendar-php #main, .events #main').height($('.page-template-calendar-php #main, .events #main').height() - 95);


$("div#slides").slideView({ easeFunc: "easeInOutSine", easeTime: 500});

var theLinks;
var nCount = 0;
var theTimerID;

function init(){
    theLinks = jQuery('div#slide-nav a');

        //for kill interval purposes
        theTimerID = setInterval("autoSlide()", 8000);
}
function autoSlide(){
    jQuery.each(theLinks, function(i){
        if(jQuery(this).hasClass('current')){
            jQuery(theLinks[((i+1 < theLinks.length) ? (i+1) : 0)] ).trigger("click");
            return false;
        }
    });
}

$('div#slides').hover(function() {
  theTimerID = clearInterval(theTimerID);
}, function() {
  theTimerID = setInterval("autoSlide()", 8000);
});


$(window).bind("load", init );

















