// media viewer

// amount of thumb nails visible
var viewable=4;
// width of each thumb nail including side margin
var itemwidth=79;

$(document).ready(function () {
    // test if page contains media viewer
    if ($("#slideshow").length > 0) {
        // hide all media
        $("#slideshow #screen .screenitem").hide();
        // show first
        $("#slideshow #screen .screenitem:first").show();
        $("#slideshow #screen .screenitem:first").addClass("active");
        var itemcount = $("#slideshow #screen .screenitem").length;
        var viewable = 4;
        // make thumb nails for each content item
        for (var i = 0; i < itemcount; i++) {
            imgsrc = $("#slideshow #screen .screenitem:eq(" + i + ") img").attr("src");
            // if media is an image, make a thumb nail of the image
            if (imgsrc) {
                $("#slider").append("<div  class=\"thumb\"><img src=\"" + imgsrc.replace('Detail', 'Thumbnail') + "\" height=\"48\" /></div>");
            }
            // if media is a you tube video, use a video icon for the thumb nail and adjust the size and add wmode transparent
            else {
                if ($("#voorstelling").length > 0) {
                    $("#slideshow #screen .screenitem:eq(" + i + ") object").attr("height", "420");
                    $("#slideshow #screen .screenitem:eq(" + i + ") embed").attr("height", "420");
                } else {
                    $("#slideshow #screen .screenitem:eq(" + i + ") object").attr("height", "348");
                    $("#slideshow #screen .screenitem:eq(" + i + ") embed").attr("height", "348");
                }
                $("#slideshow #screen .screenitem:eq(" + i + ") object").attr("width", "100%");
                $("#slideshow #screen .screenitem:eq(" + i + ") object").append("<param name=\"wmode\" value=\"transparent\"></param>");
                $("#slideshow #screen .screenitem:eq(" + i + ") embed").attr("width", "100%");
                $("#slideshow #screen .screenitem:eq(" + i + ") embed").attr("wmode", "transparent");
                var youtubecode = $("#slideshow #screen .screenitem:eq(" + i + ")").attr("name");
                $("#slider").append("<div  class=\"thumb\" style=\"background-image: url('http://img.youtube.com/vi/" + youtubecode + "/default.jpg');\"><img src=\"/images/icon_vid.png\" height=\"48\" /></div>");
            }
            // add an click event to the new thumb nail so it shows the corresponding media
            $("#slider .thumb:last").click(function () {
                $("#slideshow #screen .active").hide().removeClass("active");
                $("#slider .thumb.active").removeClass("active");
                var itemnr = $(this).prevAll().length;
                $("#slideshow #screen .screenitem:eq(" + itemnr + ")").addClass("active").fadeIn("fast");
                $(this).addClass("active");
                actthumb = $("#slideshow #slider .active").prevAll().length;
            });
        }
        //itemcount = itemcount + viewable;
        var framewidth = itemwidth * viewable;
        var sliderend = ((itemwidth * -itemcount) + framewidth) + "px";
        //alert(itemcount + ',' + viewable);
        $("#slideshow").append("<div style='display:none;'>" + itemcount + "," + viewable + "</div>");
        // add click events to the previous and next button
        $("#btn_magazine_right").click(function () {
            if ($("#slider").css("left") != sliderend && itemcount > viewable) {
                $("#slider").animate({ "left": "-=" + itemwidth + "px" }, "slow", function() { $(this).stop(true); });
            }
            var actitem = $("#slideshow #screen .active").prevAll().length;
            var lastitem = $("#slideshow #screen .screenitem").length - 1;
            if (actitem < lastitem) {
                $("#slideshow #screen .active").hide().removeClass("active").next().addClass("active").fadeIn("fast");
                actthumb = $("#slideshow #slider .active").prevAll().length;
                $("#slider .thumb.active").removeClass("active").next().addClass("active");
            }
        });
        $("#btn_magazine_left").click(function () {
            if ($("#slider").css("left") < "0px" && itemcount > viewable) {
                $("#slider").animate({ "left": "+=" + itemwidth + "px" }, "slow", function () { $(this).stop(true); });
            }
            var actitem = $("#slideshow #screen .active").prevAll().length;
            var lastitem = $("#slideshow #screen .screenitem").length - 1;
            if (actitem > 0) {
                $("#slideshow #screen .active").hide().removeClass("active").prev().addClass("active").fadeIn("fast");
                actthumb = $("#slideshow #slider .active").prevAll().length;
                $("#slider .thumb.active").removeClass("active").prev().addClass("active");
            }
        });
        $("#slider .thumb:first").addClass("active");
    }
});

// ie7 drop down menu fix
$(document).ready(function () {
    if ($.browser.msie && parseInt($.browser.version) <= 7) {
        $("#nav li").mouseover(function () {
            $(this).addClass("sfhover");
            $("#nav li ul").css("top", "-999px");
            $("#nav li.sfhover ul").css("top", "30px");
        });
        $("#nav li").mouseleave(function () {
            $(this).removeClass("sfhover");
            $("#nav li ul").css("top", "-999px");
        });
        $("#nav li li").unbind();
    }
});

// preview productions
var previewtimer;
$(document).ready(function() {
	if ($(".prodpreview").length > 0) {		
		$(".prodpreview .prodfoto").hide();
		$(".prodpreview .prodinfo").hide();
		$(".prodpreview .prodfoto:first").addClass("active").fadeIn("fast");
		$(".prodpreview .prodinfo:first").addClass("active").fadeIn("fast");
		previewtimer=setInterval("showNextPreview()",5000);
	}
});
function showNextPreview() {
	var previewcount = $(".prodpreview .prodfoto").length-1;
	var previewcurr	= $(".prodpreview .prodfoto.active").prevAll().length;
	$(".prodpreview .prodfoto.active").removeClass("active").fadeOut("fast");
	$(".prodpreview .prodinfo.active").removeClass("active").fadeOut("fast");
	if (previewcurr < previewcount) {
		$(".prodpreview .prodfoto:eq("+(previewcurr+1)+")").addClass("active").fadeIn("fast");
		$(".prodpreview .prodinfo:eq("+(previewcurr+1)+")").addClass("active").fadeIn("fast");
	} else {	
		$(".prodpreview .prodfoto:eq(0)").addClass("active").fadeIn("fast");
		$(".prodpreview .prodinfo:eq(0)").addClass("active").fadeIn("fast");
	}
}

$(document).ready(function () {
    $('#sponsors a[href^="http://"]').each(function () {
        $(this).attr('target', '_blank')
    })
});

