
// Cufon
Cufon.replace("#topMenu a, .tabsContainer .tabControl ul li, #submenu>ul>li>a", { fontFamily: "Triplex", hover: true });
Cufon.replace("a.cta, div.title", { fontFamily: "TriplexBold", hover: true });
Cufon.replace("div#usp li", { fontFamily: "Triplex", hover: true });
Cufon.replace("h1, h2, h3, h4, h5, h6", { fontFamily: "Triplex" });

// Alert
$(function() {
	$.alerts.overlayOpacity = 0.75;
	$.alerts.overlayColor = "#000";
});

// AddThis
var addthis_share = {
	templates: {
		twitter: "{{title}} - {{url}} (via @NVDtweet)"
	}
}

// PrettyPhoto
$(function() {
	$("a[rel^='prettyPhoto']").prettyPhoto({
		callback: function() {
			document.location.href = document.location;
		}
	});
});

// Header wrapper resize
$(function() {
	$(window).bind("load resize", headerWrapperResize);
});
function headerWrapperResize() {
	$("#headerWrapper").css({ "max-width": ($(window).width() > 960 ? $(window).width() : 960) });
}

// Tabs 
$(function() {
	$(".tabsContainer .tabControl li:first-child").addClass("selected");
	$(".tabsContainer .tabControl li").click(function() {
		$el = $(this).closest(".tabsContainer").find(".tabs .tab:nth-child(" + ($(this).index() + 1) + ")");
		if (!$el.is(":visible")) {
			$(this).closest(".tabControl").find("li").removeClass("selected");
			$(this).addClass("selected");

			Cufon.refresh();

			$(this).closest(".tabsContainer").find(".tabs .tab:visible").stop(true, true).slideUp();
			$el.slideDown();
		}
		return false;
	});
});

// DOM adjustments
$(function() {
	
	// Max width Youtube
	$("#content iframe[src*='youtube']").css({"max-width": 460, "max-height": 380});
	$("#content embed[src*='youtube']").attr("width", 460).attr("height", 380);
	$("#content object param[value*='youtube']").closest("object").css({"width": 460, "height": 380});
	$(".item iframe[src*='youtube']").css({"max-width": 198, "max-height": 175});

	// Rounder corners
	$(".item.singleNews figure").append("<div class=\"borderWhite TL\"></div>").append("<div class=\"borderWhite BL\"></div>");

	$(".no-borderradius nav#topMenu ul:not(.intranet) li:first-child").append("<div class=\"borderWhite TL\"></div>");
	$(".no-borderradius nav#topMenu ul:not(.intranet) li:last-child").append("<div class=\"borderWhite TR\"></div>");
	$(".no-borderradius nav#topMenu ul.intranet li:first-child").append("<div class=\"borderWhite TL\"></div>");

	$(".no-borderradius .item.singleNews").append("<div class=\"borderWhite TR\"></div>").append("<div class=\"borderWhite BR\"></div>");
	$(".no-borderradius #itemsRight .item:not(.ad, .singleNews)").append("<div class=\"borderGrey TL\"></div>").append("<div class=\"borderGrey BL\"></div>").append("<div class=\"borderGrey BR\"></div>").append("<div class=\"borderGrey TR\"></div>");

	$(".no-borderradius .tabControl li").append("<div class=\"borderGrey TL\"></div>").append("<div class=\"borderGrey TR\"></div>");

	$(".ie a.cta").each(function() {
		$(this).html("<span class=\"start\">" + $(this).html() + "</span><span class=\"end\"></span>");
	});

	// Clearfixes
	$("#content").append("<div class=\"clear\"></div>");

	$("#itemsRight").find(".item:nth-child(2n)").not(".singleNews").css({"clear": "both"});


});

// Twitter
$(function() {
	$(".tweet").tweet({
		// username: "NVDtweet",
		query: "NVDTweet",
		join_text: "auto",
		avatar_size: 32,
		count: 1,
		auto_join_text_default: "we said,", 
		auto_join_text_ed: "we",
		auto_join_text_ing: "we were",
		auto_join_text_reply: "we replied to",
		auto_join_text_url: "we were checking out",
		loading_text: "loading tweets..."
	}).bind("empty", function() { $(this).append("Er zijn geen recente tweets gevonden"); });;
});

var selectedBanners = new Array();
$(function() {	
	$.each(selectedBanners, function(index, banner) {
		_gaq.push(['_trackEvent', banner.ID, 'view', $("body").hasClass("home") ? "home" : "pagina"]);
	});
	$("section.item.ad img").click(function() {
		_gaq.push(['_trackEvent', $(this).attr("data-bannerid"), 'click', $("body").hasClass("home") ? "home" : "pagina"]);
	});
});

// Locatie bijhouden voor inloggen
$(function() {
	if (Modernizr.localstorage) {
		if (!$("body").hasClass("login")) {
			localStorage["location"] = document.location;
		}
		if (localStorage["location"] == "") {
			localStorage["location"] = document.location;
		}
	} 
});

// Popup in content mogelijk maken
$(function() {
	$("a[data-rel='popup']").each(function() {
		$(this).attr("href", $(this).attr("href") + "?iframe=true");
	});
});

// Ken Burns
var kbApi;
$(function() {
	kbApi = $(".peKenBurns").peKenburnsSlider({api:true});
	
	$(".kenBurnsNext").click(function() {
		kbApi.next();
	});
	$(".kenBurnsPrev").click(function() {
		kbApi.prev();
	});
});
