﻿/// <reference path="jquery-1.3.2.js" />

/*
modals
requires jquery.simplemodal-1.2.2.js
*/

$(document).ready(function() {
    if (InLiveMode()) { HabModal.InitLinks(); }
    //if ($('.bp-Modal').length >= 1) { HabModalContent.Init(); }
});


var HabModal = {
    InitLinks: function() {
        // add click handlers to all links with rel containing "modal"
        $('a[rel*=modal]').click(function(e) {
            e = $(this);
            HabModal.LaunchModalFromURL(e.attr('href'), e.attr('rel'), e.attr('title'));
            return false;
        });
    },

    LaunchModalFromURL: function(url, rel, title) {
        /*if (rel.split(' ').length > 0) {
        rel = rel.split(' ')[1];
        }*/

        if (url.indexOf('?') > 0)
            url += '&';
        else
            url += '?';

        url += 'pageMode=Modal';

        //s = '<div id="' + rel + '">';
        //if (title != '')
        s = '<h2 class="sIFRDisabled">' + title + '</h2>';
        s += '<iframe id="modalIframe" name="modalIframe" scrolling="no" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="445px" src="' + url + '"></iframe>';
        //s += '</div>';

        $.modal(s, {containerCssClass: rel});
    }
}

var HabModalContent = {
    Init: function() {
        $('a:not([rel*=modal])').click(function() {
            if (!$(this).hasRel('external')) {
                parent.location.href = this.href;
            }
            return false;
        });
    }
}