$(document).ready(function () {
    $('body').addClass('domenabled');
    // Slidedowns
    // SIFR headers
    if (typeof sIFR == "function") {
        sIFR.bHideBrowserText = false;
        sIFR.bFixFragIdBug = false; // not recommended!
        sIFR.forceWidth = true;
        sIFR.setup();
        $('h1, h2, h3, p.currentMember').each(function () {
            var html = $.trim($(this).html());
            $(this).html(html);
        });
        sIFR.replaceElement("h1", named({ sFlashSrc: "./include/sifr/AnwbTheSans_bold.swf", sColor: "#002280", sWmode: "transparent" }));
        sIFR.replaceElement("h2.home", named({ sFlashSrc: "./include/sifr/AnwbTheSans_normal.swf", sColor: "#002280", sWmode: "transparent" }));
        sIFR.replaceElement("h2", named({ sFlashSrc: "./include/sifr/AnwbTheSans_normal.swf", sColor: "#002280", sWmode: "transparent" }));
        sIFR.replaceElement("h3", named({ sFlashSrc: "./include/sifr/AnwbTheSans_normal.swf", sColor: "#002280", sWmode: "transparent" }));
        sIFR.replaceElement("p.currentMember", named({ sFlashSrc: "./include/sifr/AnwbTheSans_normal.swf", sColor: "#002280", sWmode: "transparent" }));
    };

    // Open links in new window
    openInNewWindow();
    initSlider();

    $('#voteButton').one('click', function () {
    	var val = $(this).attr('href');
    	val = val.substring(1);
    	$.get('/Vote.ashx?id=' + val);
    	$(this).replaceWith('<img src="/include/images/btn-bedankt-voor-je-stem.png"/>');
    });
});

function openInNewWindow() {
	$("a[rel=external]").each(function(){
		$(this).attr('title','Link opent in een nieuw venster');
		$(this).click(function() {
			window.open(this.href);
			return false;
		});
	});
}

function openPopin() {
    tb_show(null, "#TB_inline?height=490&width=525&inlineId=newsletter", null);
}

function openPopinActievoorwaardenNieuwsbrief() {
    tb_show(null, "#TB_inline?height=490&width=525&inlineId=newsletterVoorwaarden", null);
}

function initSlider() {
    var totalSliderItems = -1;
    var activeSliderItem = 0;
    $(".slider").find("li").hide().each(function () {
        
        totalSliderItems++;
        $(this).addClass('item' + totalSliderItems);
    });
    $(".item0").show();
    $("#next").click(function () {
        //$(".item" + activeSliderItem).fadeOut();
        $(".item" + activeSliderItem).hide();
        activeSliderItem++;
        if (activeSliderItem > totalSliderItems) {
            activeSliderItem = 0;
        }
        $(".item" + activeSliderItem).fadeIn();
    });

    $("#back").click(function () {
        //$(".item" + activeSliderItem).fadeOut();
        $(".item" + activeSliderItem).hide();
        activeSliderItem--;
        if (activeSliderItem < 0) {
            activeSliderItem = totalSliderItems;
        }
        $(".item" + activeSliderItem).fadeIn();
    });
}

function showSocialSharing() {
    $(".shareBox").show();
}
function hideSocialSharing() {
    setTimeout(function () {
        $(".shareBox").fadeOut("slow");
    }, 1000);
}
function showEndButtons() {
	$("#endbuttons").css('visibility', 'visible');
	$('#endbuttons h3 .sIFR-flash').attr('style', 'visibility:visible !important');
}
