function str_replace( r, w , s){
     return s.split(r).join(w);
}




try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

function addDOMLoadEvent(f){if(!window.__ADLE){var n=function(){if(arguments.callee.d)return;arguments.callee.d=true;if(window.__ADLET){clearInterval(window.__ADLET);window.__ADLET=null}for(var i=0;i<window.__ADLE.length;i++){window.__ADLE[i]()}window.__ADLE=null};if(document.addEventListener)document.addEventListener("DOMContentLoaded",n,false);/*@cc_on @*//*@if (@_win32)document.write("<scr"+"ipt id=__ie_onload defer src=//0><\/scr"+"ipt>");var s=document.getElementById("__ie_onload");s.onreadystatechange=function(){if(this.readyState=="complete")n()};/*@end @*/if(/WebKit/i.test(navigator.userAgent)){window.__ADLET=setInterval(function(){if(/loaded|complete/.test(document.readyState)){n()}},10)}window.onload=n;window.__ADLE=[]}window.__ADLE.push(f)}


 function externalLinks() {

 if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
 var anchor = anchors[i];
 if (anchor.getAttribute("href") &&
    anchor.getAttribute("rel") == "external")
	 anchor.target = "_blank";
}
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
 }	


function sifr_init () {
if(typeof sIFR == "function"){

// This is the preferred "named argument" syntax
	//sIFR.replaceElement(named({sSelector:"body h1", sFlashSrc:"vandenkeere.swf", sColor:"#000000", sLinkColor:"#000000", sBgColor:"#FFFFFF", sHoverColor:"#CCCCCC", nPaddingTop:20, nPaddingBottom:20, sFlashVars:"textalign=center&offsetTop=6"}));

// This is the older, ordered syntax
	//sIFR.replaceElement("h5#pullquote", "vandenkeere.swf", "#000000", "#000000", "#FFFFFF", "#FFFFFF", 0, 0, 0, 0);
	//sIFR.replaceElement("h2", "tradegothic.swf", "#000000", null, null, null, 0, 0, 0, 0);
	//sIFR.replaceElement("h4.subhead", "tradegothic.swf", "#660000", null, null, null, 0, 0, 0, 0);
	//sIFR.replaceElement("h3.sidebox","tradegothic.swf","#000000", "#000000", "#DCDCDC", "#DCDCDC", 0, 0, 0, 0, null);
	
	
	sIFR.replaceElement(named({sSelector:".homepage h1, .innerpage #main-info h1", sFlashSrc:"flash/agForeignerRomanMedium.swf", sColor:"#010101", sWmode:"transparent"}));
	sIFR.replaceElement(named({sSelector:".modules1 h2", sFlashSrc:"flash/agForeignerRomanMedium.swf", sColor:"#6d6d6d", sWmode:"transparent"}));
	sIFR.replaceElement(named({sSelector:".modules2 h2", sFlashSrc:"flash/agForeignerRomanMedium.swf", sColor:"#1c6093", sWmode:"transparent"}));
	sIFR.replaceElement(named({sSelector:"#login h2", sFlashSrc:"flash/agForeignerRomanMedium.swf", sColor:"#262626", sWmode:"transparent"}));
	sIFR.replaceElement(named({sSelector:"h2.gallery, .sidebar_module h2", sFlashSrc:"flash/agForeignerRomanMedium.swf", sColor:"#262626", sWmode:"transparent"}));
	sIFR.replaceElement(named({sSelector:"#footer-modules h3", sFlashSrc:"flash/agForeignerRomanMedium.swf", sColor:"#ababab", sWmode:"transparent"}));
	sIFR.replaceElement(named({sSelector:".innerpage h1", sFlashSrc:"flash/agForeignerRomanMedium.swf", sColor:"#c53a40", sEmColor:"#174f7a", sWmode:"transparent"}));
	sIFR.replaceElement(named({sSelector:".section_title h2", sFlashSrc:"flash/agForeignerRomanMedium.swf", sColor:"#6d6d6d", sWmode:"transparent", nPaddingLeft:45}));
	sIFR.replaceElement(named({sSelector:".h2-wrapper h2", sFlashSrc:"flash/agForeignerRomanMedium.swf", sColor:"#010101", sWmode:"transparent"}));
}

}


function even_modules () {
	var channels_modules = document.getElementById('channels-modules');
	if(!channels_modules) {return false}
	var channels_modules = getElementsByClass('module-content',channels_modules,'div');
	var heights = [];
	for (i=0; i<channels_modules.length; i++) {
		heights.push(channels_modules[i].offsetHeight-15);
	}
	heights.sort(function(a,b){return a - b});
	for (i=0; i<channels_modules.length; i++) {
		channels_modules[i].style.minHeight =  heights[heights.length-1] + 'px';
		if (typeof document.body.style.maxHeight == "undefined") {
			channels_modules[i].style.height =  heights[heights.length-1] + 'px';
		}
	}
	
}

function mini_gallery () {
	var minigallery = document.getElementById('mini-gallery');
	if(!minigallery) {return false;}
	var mini_gallery_photo = document.getElementById('mini-gallery').getElementsByTagName('img')[0];
	var zoom = document.getElementById('zoom');

	try{
		var mini_gallery_thumbs = document.getElementById('mini-gallery-thumbs').getElementsByTagName('a');
		for(i=0; i<mini_gallery_thumbs.length; i++) {
			mini_gallery_thumbs[i].onclick = function () {
				mini_gallery_photo.setAttribute('src',this.getAttribute('href'));
				document.getElementById("zoom").setAttribute("href" , str_replace("mid" , "large" , this.getAttribute('href')));
				zoom.setAttribute('href',this.getAttribute('rel'));
				return false;
			}
		}
	} catch (e) {};
	
}

addDOMLoadEvent(externalLinks);
addDOMLoadEvent(sifr_init);
addDOMLoadEvent(even_modules);
addDOMLoadEvent(mini_gallery);
