/* Randomly changing the header background image */

function randomRotate() {
	
    var items = $$("ul#callouts li.bucket-03 ul li");
	
    var randomNumber = Math.floor(Math.random() * items.length);
	
	for(var i=0; i < items.length; i++) {
		items[i].addClassName("displayNone");
	}
	
	items[randomNumber].removeClassName("displayNone");
}

function jsSendImgToFlash(wrapperElement) {
    var element = document.getElementById(wrapperElement);
    // hide the images on the dom
    element.className = "offscreen";

    // make a variable to save as the images we are grabbing info from
    var images = element.getElementsByTagName("img");
    // createa  global variable to the function that will serve as the final hand off array
    var imageArray = [];
    // loop through the image paths and push it to the imageArray
    for (var i = 0; i < images.length; i++) {
        imageArray.push(images[i].src);
    }
    // same deal with the anchors
    var links = element.getElementsByTagName("a");
    var linksArray = [];
    for (var i = 0; i < links.length; i++) {
        linksArray.push(links[i].href);
    }
    // swfobject
    var flashvars = {};
    // Handing off the image sources to flash
    flashvars.imgPath = imageArray;
    flashvars.urlPath = linksArray;
    var params = {};
    params.wmode = "transparent";
    var attributes = {};
    attributes.id = "flash_banner";
    swfobject.embedSWF("_ui/swf/gallery.swf", "flash_banner", "939", "295", "9.0.0", false, flashvars, params, attributes);
}


var POP_popup = Class.create();
POP_popup.prototype = {
    initialize: function() {
        var popup_class = $$('a.popup');
        var target_blank = $$('a[target^=_blank])');
        popup_class.invoke('observe', 'click', this.__Click.bindAsEventListener(this));
        target_blank.invoke('observe', 'click', this.__Click.bindAsEventListener(this));
    },

    __Click: function(e) {

        var el = Event.element(e);
        var url = el.readAttribute('href');

        // Does the element have a title? If so use that as the window name
        if (el.readAttribute('title')) {
            var windowName = escape(el.readAttribute('title'));
        }
        else {
            var windowName = "popup";
        }

        // Check for options set in the rel
        if (el.readAttribute('rel')) {
            var options = el.readAttribute('rel');
        }
        // if not use some default values
        else {
            var options = "width=800,height=600,location=yes,menubar=yes,status=yes,toolbar=yes,scrollbars=yes";
        }

        // Open window and give it focus
        var win = window.open(url, windowName, options);
        if (window.focus) {
            win.focus()
        }

        // Stop default browser event
        Event.stop(e);
    }
}
