	// Open links in nieuw venster script
	// Wietse Sluimer en Henri Kaper, Seneca B.V.

var $nw=jQuery.noConflict();

function openBlank(){
	// Plaats cookie
	$nw.cookie("newwindow","checked");
	// Vink checkbox aan
	$nw("#extLinks").attr("checked","checked");
	// Acties
	$nw("a[href^=http:]").attr("target","_blank");
	$nw("a[href^=http:]").attr("title","Link opent in nieuw venster");
	$nw("a[href^=http:]").append($nw('<img src="/scripts/jquery-newwindow-icon.gif" class="nwicon" alt="" width="15" height="12" />'));
	$nw("a[href$=.pdf]").attr("target","_blank");
	$nw("a[href$=.pdf]").attr("title","PDF bestand opent in nieuw venster");
	$nw("a[href$=.pdf]").append($nw('<img src="/scripts/jquery-newwindow-icon.gif" class="nwicon" alt="" width="15" height="12" />'));
	$nw("a[href$=.jpg]").attr("target","_blank");
	$nw("a[href$=.jpg]").attr("title","Afbeelding opent in nieuw venster");
	$nw("a[href$=.jpg]").append($nw('<img src="/scripts/jquery-newwindow-icon.gif" class="nwicon" alt="" width="15" height="12" />'));
	$nw("a[href$=.gif]").attr("target","_blank");
	$nw("a[href$=.gif]").attr("title","Afbeelding opent in nieuw venster");
	$nw("a[href$=.gif]").append($nw('<img src="/scripts/jquery-newwindow-icon.gif" class="nwicon" alt="" width="15" height="12" />'));
	$nw("a.reflink").attr("target","_blank");
	$nw("a.reflink").attr("title","Link opent in nieuw venster");
	$nw("a.reflink").append($nw('<img src="/scripts/jquery-newwindow-icon.gif" class="nwicon" alt="" width="15" height="12" />'));
	$nw("a.refpdf").attr("target","_blank");
	$nw("a.refpdf").attr("title","PDF bestand opent in nieuw venster");
	$nw("a.refpdf").append($nw('<img src="/scripts/jquery-newwindow-icon.gif" class="nwicon" alt="" width="15" height="12" />'));
}

function openSelf(){
	// Verwijder cookie
	$nw.cookie("newwindow", null);
	// Vink checkbox uit
	$nw("#extLinks").removeAttr("checked");
	// Acties
	$nw("img.nwicon").remove();
	$nw("a[href]").removeAttr("target");
	$nw("a[href^=http:]").removeAttr("title");
	$nw("a[href$=.pdf]").attr("title","PDF bestand");
	$nw("a[href$=.jpg]").attr("title","Afbeelding");
	$nw("a[href$=.gif]").attr("title","Afbeelding");
	$nw("a.refpdf").attr("title","PDF bestand");
}

function checkbox(){
	$nw('#topmenu').append($nw('<label for="extLinks">Links in nieuw venster</label><input type="checkbox" id="extLinks" name="extLinks" title="Open externe links en bestanden in nieuw venster" />'));
}

function initialiseExtLinks(){
	if($nw.cookie("newwindow")) {
		openBlank();
	}
	else{
		openSelf();
	}
}

// Na het laden van de pagina, de volgende code uitvoeren
$nw(document).ready(function() {
							 
	// Plaats checkbox in div id=newwindowcheck
	checkbox();

	// Initialiseer de status bij het laden van de pagina
	initialiseExtLinks();

		// Functies na klik op de checkbox
	$nw("#extLinks").click(function(){
		if($nw(this).is(":checked")){
			openBlank();
		}
		else{
			openSelf();
		}
	});
	});
