
var DEBUG = false;

var _DEBUG = [
  false, // alert rollover img src paths
  false, // alert sq2 and sq3
	false,  // alert invokation of swap()
	
]

var d = document;

Array.prototype.foreach = function(fn) {
  var l = this.length;
  for (var i=0; i<l; i++) {
		this.currIter = i;
    fn(this[i])
  }
}



function 
setCookie(name, value, expires, path, domain, secure) { 
	 var curCookie = name + "=" + escape(value) + 
		((expires) ? "; expires=" + expires.toGMTString() : "") + 
		((path) ? "; path=" + path : "") + 
		((domain) ? "; domain=" + domain : "") + 
		((secure) ? "; secure" : ""); 
	 document.cookie = curCookie; 
}


function swap( e, imgPath ) {
	 if( DEBUG && _DEBUG[2] ) {
		 alert( "swap: " +  e.id + " " + imgPath ); 
	 }
	 var img = new Image();
	 img.src = imgPath;
	 e.src = img.src;
}

function installRollover(t) {

   var img = document.getElementById( t[0] ); 

	 if( img == null ) {
		 if( DEBUG ) alert( "could not find element for ID: " + t[0] );
		 return;
	 }
	 	 
	 img.out  = new Image(); img.out.src  = t[1];
	 img.over = new Image(); img.over.src = t[2];

	 img.onmouseover = function() { 
	   img.src = img.over.src; 
   }	 
	 img.onmouseout = function() { 
	   img.src = img.out.src; 
	 } 
	 
   if( t[3] ) { 
		 img.click = new Image(); img.click.src = t[3];
		 img.onmousedown = function() { 
		   img.src = img.click.src;
		 }
		 img.onmouseup = function() { 
		   img.src = img.over.src;
		 }		 
	 }
	 
	 //img.onfocus = function() { img.blur() }
}

function installRollovers(tt) {
  tt.foreach( 
	  function(i) { 
		  installRollover(i);
		}
	);
}

function installPopup(t) {

   var e = document.getElementById( t[0] ); 
	 if( e == null ) {
		 if( DEBUG ) alert( "could not find element for ID: " + t[0] );
		 return;
	 }
	 	 
	 e.onclick = function() {
		 	window.open( t[1], t[2], t[3] ).focus();
	 }
}

function installPopups(tt) {
  tt.foreach( 						 
	  function(i) { 
		  installPopup(i);
		}
	);
}
	
	var currentCaptionID = "c4";
	var currentCaption; 
	
	function installOnclickInner(t, target, c) {

   var target = document.getElementById( target ); 

   var e = document.getElementById( t[0] ); 
	 if( e == null ) {
		 if( DEBUG ) alert( "could not find element for ID: " + t[0] );
		 return;
	 }
	 	 
	 e.onclick = function() {
		 	target.src = t[1]; 

   var captionID = "c" + c; 
	 var caption = document.getElementById( captionID );
	 var currentCaption = document.getElementById( currentCaptionID );

   currentCaptionID = captionID;
	 currentCaption.style.display = "none";
	 caption.style.display = "block";

  }
}

function installOnclick(tt, target) {
	 var currentCaption = document.getElementById( currentCaptionID );
	 
var c = 0;
  tt.foreach( 
	  function(i) { 
		  installOnclickInner(i, target, c ); 
			c++;
		}
	);
}
	
function installButton( r ) {
	
    var id = r[0];
		var bSrc = r[1]; 
		var roSrc = r[2]; 

    //alert( id );alert(bSrc);alert(roSrc);
		var img = d.getElementById( id );
				
		img.o = new Image();
		img.o.src = bSrc
		
		img.ro = new Image();
		img.ro.src = roSrc;
		
		img.onfocus = function() { this.blur() }
		
		img.onmousedown = function() {
		  this.src = this.ro.src;
		}
		img.onmouseout = function() {
			this.src = this.o.src;
		}
		img.onmouseup = function() {
			this.src = this.o.src;
		}		
}


function installButtons( tt ) {
	  tt.foreach( 
	  function(i) { 
		  installButton(i);
		}
	);
}



function installEmail() {

	var s4 = "mai";
	var s2 = "lto:";
	var s7 = "bre";
	var s1 = "n@br";
	var s3 = "en-ag";
	var s6 = "ain.n";
	var s5 = "et";

  var link = d.getElementById( "mlink" );
  link.setAttribute( "href", s4+s2+s7+s1+s3+s6+s5 );

  //var link = d.getElementById( "mspanlink" );
  //link.setAttribute( "href", s4+s2+s7+s1+s3+s6+s5 );

  //var span = d.getElementById( "mspan" );
	//span.appendChild( d.createTextNode( s7+s1+s3+s6+s5 ));
}



function show( e ) {
	var ee = d.getElementById(e); 
  ee.style.visibility = "visible";
}




function hide( e ) {
	var ee = d.getElementById(e); 
  ee.style.visibility = "hidden";
}
