
// ****** start: misc ******

function printPage()
{
    if (window.print){window.print();}
}

function hide(element)
{
	document.getElementById(element).style.display = 'none';
	return;
}
function show(element)
{
	document.getElementById(element).style.display = 'block';
	return;		
}

// ****** end: misc ******


// *** start: popup links ***

function doPopups()
{

	if (document.getElementById('my_popup_link')) //example
	{
		var my_popup_link = document.getElementById('my_popup_link');
		var my_popup_link_Href = my_popup_link.getAttribute('href');
		my_popup_link.onclick = function()
		{
			return(popuplink(my_popup_link_Href, this, 600, 400, false));
		}
	}

}

// start: popup window
// usage: popuplink(['js-only url',] this[, w[, h[, scroll[, extras]]]])
// basic usage: <a href="popup.html" target="_blank" onclick="return(popuplink(this));">new pop</a>
// advanced usage: <a href="popup_nojs.html" target="_blank" onclick="return(popuplink('popup_yesjs.html', this, 200, 100, false));">new pop</a>
// site-wide defaults:
popup_w = 400;
popup_h = 300;
popup_scroll = true;
popup_extras = 'location=0,statusbar=0,menubar=0';
function popuplink() {
	var undef, i=0, args=popuplink.arguments;
	var url = (typeof(args[i])=='string') ? args[i++] : args[i].getAttribute('href');
	var target = args[i++].getAttribute('target') || '_blank';
	var w = args[i++];
	var h = args[i++];
	var s = (args[i]===undef) ? popup_scroll : args[i++];
	var features = 'width=' + (w || popup_w)
				 + ',height=' + (h || popup_h)
				 + ',scrollbars=' + (s ? 'yes,' : 'no,')
				 + (args[i] || popup_extras);
	var win = window.open(url, target, features);
	win.focus();
	return false;
}

//Event.observe(window, "load", doPopups);

// *** end: popup links ***



// Tooltip triggers must be given the class 'tooltip-trigger' unless overridden through options
// Tooltip triggers must have the ID 'trigger-<id>' where <id> is the id of the tooltip to show, e.g. 'tooltip-mia'
// Tooltips themselves must have the ID 'tooltip-<id>'


var ToolTip = new Class({

    initialize: function(options) {
        this.trigger = options.trigger || '.tooltip-trigger'; // the CSS selector (class) of the html elements which triggers the tooltip
        this.registerEventHandlers();
    },

    registerEventHandlers: function() {


        $$(this.trigger).each(function(trigger) {
            var id = 'tooltip-' + trigger.id.split('-')[1]; // e.g. 'tooltip-mia'
            var tooltip = $(id);

            trigger.addEvent('click', function(ev) {
                if (typeof openToolTip != "undefined") {
                    this.hideTooltip(openToolTip);
                }

                Event(ev).stop();

                this.showTooltip(tooltip, trigger);
            } .bind(this));


        } .bind(this));
    },


    // showTooltip
    // id | string | the id of the tooltip to show
    // trigger | HTMLObject | the element that triggers the tooltip to show (used for positioning)

    showTooltip: function(tooltip, trigger) {
        if (typeof openToolTip != "undefined") {
            this.hideTooltip(openToolTip);
        }
        tooltip.set('styles', {
            visibility: "visible"
        });

        tooltip.removeClass("offscreen");
        openToolTip = tooltip;
    },

    hideTooltip: function(tooltip) {
        tooltip.addClass("offscreen");
    }

});


// alternate hide
function hideTip(id) {
    $(id).addClass("offscreen");
}