Event.observe(window, "load", function() {window.isLoaded = true;});
Event.onDOMReady(function() {window.isDOMReady = true;});
window._instruct = new Object();

var ItemScroller = Class.create();
ItemScroller.prototype = {

  initialize: function(element) {
    var options = Object.extend( {
      speed: 1000,
      skipclass: null
    }, arguments[1] || {} );

    this.element = $(element);
    this.options = options;

    this.eventMouseOver = this.mouseOver.bindAsEventListener(this);
    this.eventMouseOut  = this.mouseOut.bindAsEventListener(this);
    this.eventMouseMove = this.mouseMove.bindAsEventListener(this);

    Event.observe( this.element, "mousemove",  this.eventMouseMove);
  },

  scroll: function( arr ) {
    this.collection = $A(arr);

    var byID = $H()
    for( var i=0; i<this.collection.length; i++) {
        if( this.collection[i].entryID != null ) {
            //byID[this.collection[i].entryID] = this.collection[i];
            byID.set(this.collection[i].entryID, this.collection[i]);
        }
        // preload the images...
        if( this.collection[i].imageURL ) {
        	new Image().src = this.collection[i].imageURL;
        }
    }

    images = new Array();
    var allimgs = this.element.getElementsByTagName("img");
    for( var i=0; i<allimgs.length; i++) {
        if( this.options.skipclass && Element.hasClassName( allimgs[i], this.options.skipclass ) ) {
            continue;
        }
        images.push( allimgs[i] );

        var xx = byID.get(allimgs[i].name);
        if( xx ) {
            allimgs[i].item = xx;
            byID.set(allimgs[i].name, null); // remove it?
        }
        else {
            //alert("can not find: "+allimgs[i].name );
        }

        // observe the mouseover/out...
        Event.observe(allimgs[i], "mouseover", this.eventMouseOver);
        Event.observe(allimgs[i], "mouseout",  this.eventMouseOut);
    }

    var hidden = $A();
    var vvv = byID.values();
    for( var i=0; i<vvv.length; i++) {
        if( vvv[i] != null ) {
            hidden.push( vvv[i] );
        }
    }

    //alert( "IMAGES:"+images + "\nALL:" +byID.inspect()+"\nIN:"+arr+"\nCOL:"+this.collection+"\nHIDDEN:"+hidden   );


    if( this.looper ) {
        clearInterfal( this.looper );
    }
    var loopID = 0;
    var scroller = this;

    var rand = null;
    var lastrand = null;

    this.looper = setInterval( function() {
        for( var i=0; i<5; i++ ) {  // only try 5 times
            rand = images[ Math.floor( Math.random()*images.length ) ];
            if( rand && (rand != lastrand) && rand != scroller.overElement )
            {
                //alert( "RAND: "+rand + " : " + rand.name + " : " + rand.type + " : " + rand.item );

                lastrand = rand;

                if( rand.item ) {
                    var temp = rand.item;
                    rand.item = hidden[loopID];
                    rand.parentNode.href = rand.item.showURL;
                    hidden[loopID] = temp;

                    if( rand.item.imageURL ) {
                        new Effect.Fade( rand, { to:0.05, afterFinish: function() {
                          rand.src = rand.item.imageURL;
                          new Effect.Appear( rand );
                        } } );
                    }
                    loopID = (loopID+1)%hidden.length;
                }
                else {
                    //alert( "no item: "+rand + " : " + rand.name + " : " + rand.type );
                }
                return;
            }
        }
    }, this.options.speed );
  },


  mouseOver: function(event) {
     this.overElement = Event.element( event );
     if( this.overElement.item ) {
        if(!this.overlay ) {
            this.overlay = Builder.node( 'div',  { style:"text-align: left; width: 400px; position:absolute; border:1px solid black; background:#FFFFFF; padding: 5px; visibility: hidden;" }, "hello!" );
            document.body.appendChild( this.overlay );
        }
        var item = this.overElement.item;
        this.overlay.innerHTML = '<b>'+item.name+'</b><br/>'+item.abstract;
        this.mouseMove(event);
        this.overlay.style.visibility ='visible';
     }
  },

  mouseOut: function(event) {
     this.overElement = null;
     if (this.overlay) this.overlay.style.visibility ='hidden';
  },

  mouseMove: function(event, align) {
    if( this.overlay ) {
		var align = Element.readAttribute(Event.element(event), 'tip-align');
    	if(align != null && align == "left") {
	        this.overlay.style.left = (Event.pointerX(event)-410)+"px";
    	} else
    		this.overlay.style.left = (Event.pointerX(event)+10)+"px";
        this.overlay.style.top  = (Event.pointerY(event)+10)+"px";
    }
  }
}


var TagScroller = Class.create();
TagScroller.prototype = {   
      
  initialize: function(element) {
    var options = Object.extend( {
      speed: 1000,
      name: null,
      skipclass: null
    }, arguments[1] || {} );

    this.element = $(element);
    this.options = options;    
  },

  scroll: function( word ) {
    
    var tags = this.element.getElementsByTagName("a"); 
    
    if( this.looper ) {
        clearInterfal( this.looper );
    }
    var loopID = 0;
    var scroller = this;
    this.looper = setInterval( function() {
       var rand = tags[ Math.floor( Math.random()*tags.length ) ]; 
       var w = word[loopID];
       loopID = (loopID+1)%word.length;
       
       var baseURL = "/tag/"
       if( scroller.options.name ) {
           baseURL += scroller.options.name + ":";
       }
       new Effect.Fade( rand, { to:0.05, afterFinish: function() { 
         rand.href = baseURL+encodeURI(w)+"/";
         rand.innerHTML = w.escapeHTML();
         new Effect.Appear( rand );
       } } );
       
    }, this.options.speed );
  }
}


var Fabtabs = Class.create();
Fabtabs.prototype = {
   initialize : function(element) {
		this.element = $(element);
		var options = Object.extend({}, arguments[1] || {});
		if(this.element) {
			this.menu = $A(this.element.getElementsByTagName('a'));
			this.show(this.getInitialTab());
			this.menu.each(this.setupTab.bind(this));
		}
 },
        setupTab : function(elm) {
                Event.observe(elm,'click',this.activate.bindAsEventListener(this),false)
  },
        activate :  function(ev) {
                var elm = Event.findElement(ev, "a");
           Event.stop(ev);
           this.show(elm);
           this.menu.without(elm).each(this.hide.bind(this));
        },
        hide : function(elm) {
            $(elm).removeClassName('active-tab');
             $(this.tabID(elm)).removeClassName('active-tab-body');
    },
        show : function(elm) {
            $(elm).addClassName('active-tab');
                $(this.tabID(elm)).addClassName('active-tab-body');
  },
        tabID : function(elm) {
           return elm.href.match(/#(\w.+)/)[1];
      },
        getInitialTab : function() {
              if(document.location.href.match(/#(\w.+)/)) {
                     var loc = RegExp.$1;
                      var elm = this.menu.find(function(value) { return value.href.match(/#(\w.+)/)[1] == loc; });
                      return elm || this.menu.first();
          } else {
                  return this.menu.first();
         }
 }
}
Event.observe(window,'load',function(){ new Fabtabs('tabs'); },false);


function showHistory() {

	
}

var menuids=["treemenu"];
function buildSubmenus() {
	for (var i=0; i<menuids.length; i++) {
		var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
		for (var t=0; t<ultags.length; t++) {
			if (ultags[t].parentNode.parentNode.id==menuids[i]) {
				ultags[t].style.top=ultags[t].parentNode.offsetHeight+"px" //dynamically position first level submenus to be height of main menu item
				ultags[t].parentNode.getElementsByTagName("a")[0].className="mainfoldericon"
			} else { //else if this is a sub level menu (ul)
				ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
				ultags[t].parentNode.getElementsByTagName("a")[0].className="subfoldericon"
			}
			ultags[t].parentNode.onmouseover = function() {
				this.getElementsByTagName("ul")[0].style.visibility="visible"
			}
			ultags[t].parentNode.onmouseout = function() {
				this.getElementsByTagName("ul")[0].style.visibility="hidden"
			}
		}
	}
}

if (window.addEventListener)
window.addEventListener("load", buildSubmenus, false)
else if (window.attachEvent)
window.attachEvent("onload", buildSubmenus)


/*#################   Dreamweaver Code   ############################### */
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
	
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
	
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
	
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}	
			/*						
									// this function generates the actual toolbar buttons with localized text
									// we use it to avoid creating the toolbar where javascript is not enabled
									function addButton(imageFile, speedTip, tagOpen, tagClose, sampleText) {
									
										// Don't generate buttons for browsers which don't fully
										// support it.
										if(!document.selection && !is_gecko) {
											return false;
										}
										imageFile=escapeQuotesHTML(imageFile);
										speedTip=escapeQuotesHTML(speedTip);
										tagOpen=escapeQuotes(tagOpen);
										tagClose=escapeQuotes(tagClose);
										sampleText=escapeQuotes(sampleText);
										var mouseOver="";
									
										document.write("<a href=\"javascript:insertTags");
										document.write("('"+tagOpen+"','"+tagClose+"','"+sampleText+"');\">");
										document.write("<img width=\"23\" height=\"22\" src=\""+imageFile+"\" border=\"0\" alt=\""+speedTip+"\" title=\""+speedTip+"\""+mouseOver+">");
										document.write("</a>");
										return;
									}
									
									function escapeQuotes(text) {
										var re=new RegExp("'","g");
										text=text.replace(re,"\\'");
										re=new RegExp("\\n","g");
										text=text.replace(re,"\\n");
										return escapeQuotesHTML(text);
									}
									
									function escapeQuotesHTML(text) {
										var re=new RegExp('&',"g");
										text=text.replace(re,"&amp;");
										var re=new RegExp('"',"g");
										text=text.replace(re,"&quot;");
										var re=new RegExp('<',"g");
										text=text.replace(re,"&lt;");
										var re=new RegExp('>',"g");
										text=text.replace(re,"&gt;");
										return text;
									}

									function insertTags(tagOpen, tagClose, sampleText) {
										var txtarea = document.editform.text_data;
										// IE
										if(document.selection  && !is_gecko) {
											var theSelection = document.selection.createRange().text;
											if(!theSelection) { theSelection=sampleText;}
											txtarea.focus();
											if(theSelection.charAt(theSelection.length - 1) == " "){// exclude ending space char, if any
												theSelection = theSelection.substring(0, theSelection.length - 1);
												document.selection.createRange().text = tagOpen + theSelection + tagClose + " ";
											} else {
												document.selection.createRange().text = tagOpen + theSelection + tagClose;
											}
									
										// Mozilla
										} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
											var replaced = false;
									 		var startPos = txtarea.selectionStart;
											var endPos = txtarea.selectionEnd;
											if(endPos-startPos) replaced=true;
											var scrollTop=txtarea.scrollTop;
											var myText = (txtarea.value).substring(startPos, endPos);
											if(!myText) { myText=sampleText;}
											if(myText.charAt(myText.length - 1) == " "){ // exclude ending space char, if any
												subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
											} else {
												subst = tagOpen + myText + tagClose;
											}
											txtarea.value = txtarea.value.substring(0, startPos) + subst +
											  txtarea.value.substring(endPos, txtarea.value.length);
											txtarea.focus();
											//set new selection
											if(replaced){
												var cPos=startPos+(tagOpen.length+myText.length+tagClose.length);
												txtarea.selectionStart=cPos;
												txtarea.selectionEnd=cPos;
											}else{
												txtarea.selectionStart=startPos+tagOpen.length;   
												txtarea.selectionEnd=startPos+tagOpen.length+myText.length;
											}	
											txtarea.scrollTop=scrollTop;
									
										// All other browsers get no toolbar.
										// There was previously support for a crippled "help"
										// bar, but that caused more problems than it solved.
										}
										// reposition cursor if possible
										if (txtarea.createTextRange) txtarea.caretPos = document.selection.createRange().duplicate();
									}
*/


function openComponentWindow(url, width, height) {
	subwindow = window.open(url,"","width="+width+",height="+height+",location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=yes,status=no,dependent=yes");
}
	
function openSwf(url, width, height) {
	var resi;
	if(height == '' || height < 100)
		height = 637;
	if(width == '' || width < 100)
		width = 801;
							
	if (width < 801 && width != 0)
		resi = "no";
	else
		resi = "yes";
	test = window.open(url,"","width="+width+",height="+height+",location=no,menubar=no,toolbar=no,resizable="+resi+",status=no,dependent=yes");
}