/**
 * User: jeremy
 * Date: Jan 21, 2011
 * Time: 11:34:07 AM
 */
function AppController() {
    var self = this;
    this.popupCurtain = null;
    this.popupContent = null;
    jQuery(document).ready(function() {
        self.onLoad();
    });
}
AppController.prototype = new BaseController();
AppController.prototype.onLoad = function() {
    var self = this;
    this.popupCurtain = jQuery("#overlay");
    this.popupContent = jQuery("#overlayContent");
    this.addListener('redirectEvent', function (e, r) {
        self.onRedirectEvent(r);
    })

    jQuery(".loginLink").click(function() {
        jQuery("#signinButton").click();
    })
    jQuery(".popupTrigger").click(function() {
        jQuery(this).siblings('.popupContent').show();
    })
    jQuery(".closeIcon").click(function () {
        var elem = jQuery(this);
        elem.parent().hide()
    })
    jQuery('.videoPopup').click(function () {
        self.showPopup('/ajax/video/', {url:jQuery(this).attr('href')});
        return false;
    })
}
AppController.prototype.showPopup = function (url, data) {
    var self = this;
    this.closePopup();
    this.popupCurtain.show();
    this.popupContent.load(url, data, function() {
        self.onPopupLoaded(this)
    });
}
AppController.prototype.closePopup = function () {
    this.popupCurtain.hide()
    this.popupContent.hide().html('');
}
AppController.prototype.onPopupLoaded = function (popup) {
    var self = this;
    popup = jQuery(popup);

    popup.find('.closePopup').click(function () {
        self.closePopup();
    })

    this.popupContent.show();
}

AppController.prototype.onRedirectEvent = function (result) {
    if (result.data && result.data.redirect) {
        window.location = decodeURI(result.data.redirect);
    } else {
        window.location = '/'
    }
}
var appController = new AppController();
