/**
 * @author garyrockett
 */

var page = {};

page.setupPopUps = function () {
    $('.popUpWindowedLink').each(function () {
        $(this).attr('href', $(this).attr('href') + '?windowed=true').colorbox({
            maxWidth: "90%",
            maxHeight: "90%",
            initialWidth: 100,
            initialHeight: 100,
            close: '<a href="#" class="closePopup">close</a> or Esc Key'
        });
    });
    $('a.popUp').each(function() {
        var href = $(this).attr('href') + '?windowed=true' ;
        $(this).attr('href',href);
    });
    $("a.popUp.fullFrame").colorbox({
        onComplete:function(){ $('#cboxLoadedContent').addClass('fullFrame');},
        maxWidth: "90%",
        maxHeight: "90%",
        initialWidth: 100,
        initialHeight: 100,
        close: '<a href="#" class="closePopup">close</a> or Esc Key'
    });
    $("a.popUp").colorbox({
        maxWidth: "90%",
        maxHeight: "90%",
        initialWidth: 100,
        initialHeight: 100,
        close: '<a href="#" class="closePopup">close</a> or Esc Key'
    });
};

page.setupExpanders = function () {
    $('.noJs').removeClass('noJs');
    $('div.expander span').show();
    if(document.referrer.indexOf("plus.net") !=-1) {
        $('div.expander > p').hide();
        $('a.expander-button').text('Show Detail');
    } else {
        $('div.expander h2').addClass('minus');
    };
    $('div.expander h2').click( function () {
        $(this).toggleClass('minus').parent('div').children('p').toggle();
        var link = $(this).find('a.expander-button');
        link.text((link.text() == 'Show Detail') ? 'Hide Detail' : 'Show Detail');
        return false;
    });
};

$(document).ready( function () {
    if ($('div.expander').length > 0) {
        page.setupExpanders();  
    }
	if (typeof $.colorbox === 'function') {
        page.setupPopUps();
        $('#cboxClose').live('click', function(){
            return false;
        });
    }
});
