// Random UL Slides (Single Page Load)
jQuery.fn.randomSlides = function () {
    var slides = $(this).children().css('display', 'none');
    var slideIndex = Math.floor(Math.random() * slides.length);
    $(slides[slideIndex]).css('display', 'block');
};

// Cufon Settings
$(function () {

    // DIN Stuff
    Cufon.set('fontFamily', 'din');
    $('.din').each(function () { Cufon.replace($(this)); });

    Cufon.replace('#header #nav a', {
        color: 'rgb(50,49,47)',
        hover: { color: 'rgb(50,49,47)' }
    });

    Cufon.replace('#footer #nav a', {
        color: 'rgb(166,164,164)',
        hover: { color: 'rgb(244,244,244)' }
    });

    Cufon.replace('#events #content h4');
    Cufon.replace('#content h1', { color: 'rgb(56,50,50)' });
    Cufon.replace('#nav-side li a', { color: 'rgb(67,63,63)' });
    Cufon.replace('#nav-side li li a', { color: 'rgb(255,255,255)' });
    Cufon.replace('#all-news-link', { color: 'rgb(255,255,255)' });

});


$(document).ready(function () {



    // Activate Cufon
    Cufon.now();

    // Random Slides/Lightbox
    if ($('#random-slides').length > 0) { $('#random-slides').randomSlides(); }
    if ($('#slideshow-slides').length > 0) { $('#slideshow-slides').randomSlides(); }
    if ($('#home-slideshow').length > 0) { $("a[rel='lightbox']").colorbox({ iframe: true, innerWidth: 480, innerHeight: 390, rel: "nofollow" }); }
    if ($('#project-gallery').length > 0) { $("#project-gallery a").lightbox(); }

    // Subscribe Iframe Anti Scrollin!
    if ($('#blog-scubscribe-iframe').length > 0) { $('#blog-scubscribe-iframe').attr('scrolling', 'no'); }

});

// External Link Handling
function externalLinks() {  
	if (!document.getElementsByTagName) return;  
	var anchors = document.getElementsByTagName("a");  
	for (var i=0; i<anchors.length; i++) {  
		var anchor = anchors[i];  
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
	}
}
window.onload = externalLinks;
