



/////////////////////////
/* FUNCTIONS           */
/////////////////////////


function slideShow() {

		// get image count
		var imageCount = $(".singleImage").length;
		if (imageCount > 1) {
		    // get current index
		    currentImageIndex = parseInt($(".singleImage").index($(".singleImage:visible:first")));
		    // get next image by index
		    newImageIndex = (currentImageIndex + 1) % imageCount;
		    // hide all visible images and fade in the new image by index (using the selector :eq())
		    $(".singleImage:visible").fadeOut("slow");
		    $(".singleImage:eq(" + newImageIndex + ")").fadeIn("slow");
		}
}


/////////////////////////
/* DOM-READY           */
/////////////////////////

$(function() {


    var i;
    for (i in document.images) {
        if (document.images[i].src) {
            var imgSrc = document.images[i].src;
            if (imgSrc.substr(imgSrc.length-4) === '.png' || imgSrc.substr(imgSrc.length-4) === '.PNG') {
                document.images[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='crop',src='" + imgSrc + "')";
            }
        }
    }

    //HIDE ALL THAT SHOULD BE HIDDEN
    $(".hidden").hide();

    // External Links Wrapper for Valid XHTML
    $('a[rel*=external]').live("click", function(event) {
		window.open(this.href);
		return false;
	});

	// open and close content of boxes
	$("a.boxHeadingLink").click(function(event) {

	  	event.preventDefault();
		$($(this).attr("href")).slideToggle("slow");
		$(this).toggleClass('boxHeadingLinkActive');
	});


	// hide all but the first image
	$(".singleImage").not(":first").hide();
	// Slideshow starten
   	setInterval( "slideShow()", 5000 );

   	if ( $('#subnav').length ) {
   	$('#subnav').delay(500).slideDown('slow', function() {
        // Animation complete.
      });
   	}

   	$("a.mainNavLink").click(function(event) {
        event.preventDefault();
        href = $(event.target).attr("href");


        if ( $('#subnav').length ) {
       	$('#subnav').slideUp('slow', function() {
            window.location = href;
          });
       	} else {

       	    window.location = href;

       	}

    });

	// open and close content of boxes
	$("a.boxHeadingLink").click(function(event) {

	  	event.preventDefault();
		$($(this).attr("href")).slideToggle("slow");
		$(this).toggleClass('boxHeadingLinkActive');
	});


});
