// JavaScript Document


/****************************************************************** Defaults */
if (!kRoll)          var kRoll = "roll"; 
if (!kSelected)      var kSelected = "sel"; 
if (!kUnselected)    var kUnselected = "unsel"; 
if (!kRollClass)     var kRollClass = "hasRolloverImg";
if (!kDownloadSetId) var kDownloadSetId = "Downloads";
                     var kState = "state";
                     var kRegexImg = "^(.+)([^\/]+)-([a-zA-Z0-9]+)\.(gif|jpg)$";

/************************************************ Structures for sIFR styles */
var header_color = {
	'cycling' : '#DB8900',
	'default' : '#71C41D'
	//'press'   : '#ffa500;',
	//'events'  : '#ffa500;',
};


/***************************************************************** Functions */
function showHoverImg (img) {
    img.src = img[kRoll].src;
}

function showStateImg (img) {
    img.src = img[kState].src;
}

function launch (page) {
  	openwin = this.open( page,"map_with_pops","toolbar=no,menubar=no,scrollbars=no,location=no,width=420,height=395");
}

function shuffle ( myArray ) {
    // fisher-yates shuffling algorithm: shuffles an array in place
    var i = myArray.length;
    if ( i == 0 ) return false;
    while ( --i ) {
        var j = Math.floor( Math.random() * ( i + 1 ) );
        var tempi = myArray[i];
        var tempj = myArray[j];
        myArray[i] = tempj;
        myArray[j] = tempi;
    }
}

function popup( href, dimensions, return_type ) {
	// dimensions has a default value of 400x400 pixels
	var dimensions = typeof(dimensions) != 'undefined' ? dimensions : [420,395]; 
	
	var return_type = typeof(return_type) != 'undefined' ? return_type : 0; // 0: return a false value for an onclick handler
	                                                                      // 1: return the resultant window object
	var features  = [
		'directories=no',
		'width='  + dimensions[0],
		'height=' + dimensions[1], 
		'location=no',
		'scrollbars=no',
		'status=yes',
		'toolbar=no',
		'resizable=yes'
	];
	var win = this.open( href, 'MM_Popup', features.join(','), true );
  		
	if ( return_type == 0 ) {
		return false;	
	}
}

function popup_flash( href, dimensions ) {
	var result = popup( href, dimensions );
}

function launch2 (page, width, height ) {
  	openwin = this.open( page,"map_with_pops","toolbar=no,menubar=no,scrollbars=no,location=no,width=" + width + ",height=" + height );
}


/************** Runtime *********************************/
window.onload = function(){
    // prototype should load before this
    $$(".select-one .quote").each(
        function( el ) {
            Element.setOpacity(el,0.0);
            el.style.visibility = 'visible';
            Effect.Appear(el);
        }
    );
    
    // set rollovers
    $$("." + kRollClass).each(
        function (el) {
            // add extra image elements:
            // each rollover image has two keys: the named rollover state
            // and the named non-rollover state
            el[kRoll]  = new Image();
            el[kState] = new Image();
            
            // using a regexp to get the name of the image file, 
            // generate (guess) the name of the rollover image.
            // store both in a property of the image itself
            var re = new RegExp( kRegexImg );
            if (re.test(el.src)) {
                // RegExp.test returns true if the regexp matched the string you sent it
                el[kRoll].src  
                    = el.src.replace( re, "$1$2-" + kRoll + ".$4");
                el[kState].src 
                    = el.src;
            }

            // add event handlers
            Event.observe(el, 'mouseover', new Function("showHoverImg(this);"));
            Event.observe(el, 'mouseout', new Function("showStateImg(this);"));
        }
    );
}

	