// Hide the Google watermark when you click in the search box
// This code is currently embedded in a faux custom module. AH (FPM) 090507.

/*(function () {
    var f = document.getElementById("searchbox_004519335225175341333:qqryuvkxnvm");
    if (!f) {
        f = document.getElementById("googlesearchbox");
    }
    if (f && f.q) {
        var q = f.q;
        var n = navigator;
        var l = location;
        if (n.platform == "Win32") {
            q.style.cssText = "";
        }
        var b = function () {if (q.value == "") {q.style.background = "#FFFFFF url(/templates/greenmaven/images/google_custom_search_watermark.gif) left no-repeat";}};
        var f = function () {q.style.background = "#ffffff";};
        q.onfocus = f;
        q.onblur = b;
        if (!/[&?]q=[^&]/.test(l.search)) {
            b();
        }
    }
})();*/

// Add the value to the Search box
// Not required as we will using the Google Watermark - We will have to implement a more discriminating selector to prevent JS // errors. AH (FPM) 090507.
/*search={
	
	activeClass:'active_menu',
	searchboxSize: 38,
	searchtext: 'search the news . . .',
	
	init:function(){
		
		var searchbox = document.getElementById('searchbox');
		if (searchbox.value == ''){
		searchbox.value = search.searchtext ;
		}
		
		// Functions to set text on blur / focus
		searchbox.onfocus=function(){
			if (searchbox.value == search.searchtext){
			searchbox.value = '';
			}
		}
		searchbox.onblur=function(){
			if(this.value ==''){
				searchbox.value = 'search the news . . .';
				}
		}
	}
}

DOMhelp.addEvent(window, 'load', search.init, false);*/


pop={
	triggerClass:'iframepop',
	popupClass:'popup',
	openPopupLinkClass:'popuplink',
	displayPrefix:'Close ',
	ifrContainer:null,
	init:function(){
		if(!document.getElementById || !document.createTextNode){return;}
		var allLinks=document.getElementsByTagName('a');
		for(var i=0;i<allLinks.length;i++){
			if(!DOMhelp.cssjs('check',allLinks[i],pop.triggerClass)){continue;}
			DOMhelp.addEvent(allLinks[i],'click',pop.openPopup,false);			
			allLinks[i].preset=allLinks[i].innerHTML;
			allLinks[i].onclick=DOMhelp.safariClickFix;
		}
	},
	openPopup:function(e){
		var t=DOMhelp.getTarget(e);
		if(t.nodeName.toLowerCase()!='a'){
			t=t.parentNode;	
		}
		if(pop.ifrContainer){
			pop.killPopup();
			t.innerHTML=t.preset;
			DOMhelp.cssjs('remove',t,pop.openPopupLinkClass);
		} else {		
			DOMhelp.cssjs('add',t,pop.openPopupLinkClass);
			t.innerHTML=pop.displayPrefix+t.preset;
			pop.ifrContainer=document.createElement('div');
			DOMhelp.cssjs('add',pop.ifrContainer,pop.popupClass);
			var ifr=document.createElement('iframe');
			pop.ifrContainer.appendChild(ifr);
			ifr.setAttribute('src',t.getAttribute('href'));
			document.body.appendChild(pop.ifrContainer);
			pop.positionPopup(t);
		}
		DOMhelp.cancelClick(e);
	},
	positionPopup:function(o){
		var x=0;
		var y=0;
		var h=o.offsetHeight;
		while (o != null){
			x += o.offsetLeft;
			y += o.offsetTop;
			o = o.offsetParent;
		}
		pop.ifrContainer.style.left=(x-315)+'px';
		pop.ifrContainer.style.top=(y+h)-1+'px';
	},
	killPopup:function(e){
		pop.ifrContainer.parentNode.removeChild(pop.ifrContainer);
		pop.ifrContainer=null;
		DOMhelp.cancelClick(e);
	}
}
DOMhelp.addEvent(window,'load',pop.init,false);

treehug={
	init:function(){
		var content = document.getElementById("main-content");
		var images = content.getElementsByTagName("img");
		for (var i=0; i<images.length; i++){
			var imgsrc = images[i].getAttribute("src");
			var imgsrcslice = imgsrc.substring(11,15);
			if (imgsrcslice == "tree"  && images[i].className != "left"){
				var br = document.createElement("br");
				images[i].parentNode.insertBefore(br,images[i].nextSibling);
			}
		}
	}
}
DOMhelp.addEvent(window,'load',treehug.init,false);
	
links={
	init:function(){
		var links = document.getElementsByTagName("a");
		for (i=0;i <links.length;i++){
			links[i].setAttribute("target","_self");
		}
	}
}
DOMhelp.addEvent(window,'load',links.init,false);
