/* Fragment Highlight version 0.1; this JavaScript highlight code is copyright 2003 by David Dorward; http://dorward.me.uk; this JavaScript library is copyright 2002 by Gavin Kistner and Refinery; www.refinery.com */


/* Adds a new class to an object, preserving existing classes */
function AddClass(obj,cName){ KillClass(obj,cName); return obj.className+=(obj.className.length>0?' ':'')+cName; }

/* Removes a particular class from an object, preserving other existing classes */
function KillClass(obj,cName){ return obj.className=obj.className.replace(new RegExp("^"+cName+"\\b\\s*|\\s*\\b"+cName+"\\b",'g'),''); }

/* Indicates area that has been linked to if fragment identifiers have been used. Especially useful in situations where a short fragment is near the end of a page. */
var fragHLed = '';
var fragExclude = ('header');
Array.prototype.search = function(myVariable) { for(x in this) if(x == myVariable) return true; return false; }

/* Highlight link target if the visitor arrives at the page with a # */
function fragHLload() {
	fragHL(location.hash.substring(1));
}

/* Highlight link target from an onclick event after unhighlighting the old one */
function fragHL(frag) {
	if (fragHLed.length > 0 && document.getElementById(fragHLed)) {
		KillClass(document.getElementById(fragHLed),'highlight');
	}
	if (frag.length > 0 && document.getElementById(frag) && frag != "top") {
		fragHLed = frag;
		AddClass (document.getElementById(frag),'highlight');
	}
}

/* Add onclick events to all <a> with hrefs that include a "#"  */
function fragHLlink() {
	if (document.getElementsByTagName) {
		var an = document.getElementsByTagName("a");
		for (i=0; i<an.length; i++) {
			if (an.item(i).getAttribute("href").indexOf("#") >= 0) {
				var fragment = an.item(i).getAttribute("href").substring(an.item(i).getAttribute("href").indexOf("#") + 1);
				if (fragExclude.search(fragment)) {
					var evn = "fragHL('" + fragment + "')";
					var fun = new Function('e',evn);
					an.item(i).onclick = fun;
				}
			}
		}
	}
}

/* Mark external links */
function extLinks () {

	if (document.getElementsByTagName) {
		var an = document.getElementsByTagName("a");
		var obj;
		for (var i=0; i<an.length; i++) {
			obj = an.item(i);
	    if (obj.href.indexOf(location.host) == -1 && obj.href && obj.className.indexOf("noLinkImg")) {
				obj.rel = "external";
				obj.title = "Externe site: " + obj.title;
				var mark = document.createElement("img");
				mark.src = "http://www.raadvoordewadden.nl/fileadmin/gen_rvdw/js/exit2.png";
				mark.alt = "(externe site)";
				mark.width = "10";
				mark.height = "8";
				mark.className = "exit";
				mark.border = "0";
				obj.appendChild(mark);
			}
		}
	}
}

function createTopButton () {
	var t = document.getElementById("rvdw");
	var div = document.createElement("div");
	div.id = "toThePageTop";
	t.appendChild(div);
	var a;
	var img;
	for(var u = 0; u < 2; u++) {
		a = document.createElement("a");
		a.className = "off";
		a.href = "#top";
		//a.title = "Top";
		if(u == 0) a.title = "top-links";
		else a.title = "top-rechts";
		//a.onclick = "return scrollToTop();"
		if(u == 0) a.id = "top-links";
		else a.id = "top-rechts";
		div.appendChild(a);
		img = document.createElement("img");
		img.alt = "Top";
		img.src = "http://www.raadvoordewadden.nl/fileadmin/gen_rvdw/js/top.png";
		img.width = "16";
		img.height = "16";
		img.border = "0";
		a.appendChild(img);
	}
}

function adjustTopButton() {

	var tl = document.getElementById("top-links");

	var tr = document.getElementById("top-rechts");
	var s = document.body.scrollTop || (document.documentElement && document.documentElement.scrollTop);
	
	if(s > 0) {
		tl.className = tr.className = "on";
		// determine support for position: fixed and apply hack if necessary
		var pos;
		if(document.getElementById("toThePageTop").currentStyle)
			pos = document.getElementById("toThePageTop").getElementsByTagName("a")[1].currentStyle.position;
			
		else
			pos = 0;

		if(pos == "absolute") {
			 var docHeight = document.getElementById("inner").clientHeight;
			var winHeight = document.documentElement.clientHeight;
			var p = s + winHeight - 413 + "px";
			tl.style.top = tr.style.top = p;
				
		}
	}
	else
		tl.className = tr.className = "off";
}

/* Init the script */
window.onload = function(){
	extLinks();
	fragHLload();
	/*fragHLlink();*/
	
	
	if (document.getElementById && document.documentElement) {
		createTopButton();
		setInterval("adjustTopButton()", 100);
	}
}
/* OPEN NEW WINDOW added later */
var WindowObjectReference = null; // global variable
var PreviousUrl; /* global variable which will store the
                    url currently in the secondary window */

function openSinPopup(strUrl)
{
  if(WindowObjectReference == null || WindowObjectReference.closed)
  {
   WindowObjectReference = window.open(strUrl, "SingleSecondaryWindowName",
         "toolbar=yes,resizable=yes,scrollbars=yes,status=yes,menubar=yes,location=yes");
  }
  else if(previousUrl != strUrl)
  {
   WindowObjectReference = window.open(strUrl, "SingleSecondaryWindowName",
      "toolbar=yes,resizable=yes,scrollbars=yes,status=yes,menubar=yes,location=yes");
    /* if the resource to load is different,
       then we load it in the already opened secondary window and then
       we bring such window back on top/in front of its parent window. */
   WindowObjectReference.focus();
  }
  else
  {
    WindowObjectReference.focus();
  };
  PreviousUrl = strUrl;
  /* explanation: we store the current url in order to compare url
     in the event of another call of this function. */
}
