﻿/* General application-wide functions and settings */

//site-wide page load functions
jQuery(function($) {
    //convert 'popup' links to open in new window
    $('a.popup').bind('click', makePopup);
});


//event-handler to create a popup from links on the page
//NOTE: uses 'this' as the actual link element, so bind it!
function makePopup(e) {
    e.preventDefault();
    
    var opts = {};
    if (jQuery(this).hasClass('location-0'))
        opts.location = 0;
    
    popup(this.href, opts);
}

//opens a new window using the URL and settings provided
function popup(url, settings) {
    //override defaults if settings provided
    var options = jQuery.extend({
        height: 550,
        width: 700,
        scrollBars: 1,
        toolbar: 1,
        resizable: 1,
        location: 1,
        status: 1
    }, settings || {});

    //create a string of all options (height=550, width=650, toolbar=1...)
    //TODO: more elegant way to build the options string?
    var opts = '';
    jQuery.each(options, function(val) {opts += val + '=' + options[val] + ',';});
    
    window.open(url, 'popup_win', opts);
}
