/*
 * Copyright (c) 2009, Techtribe B.V.
 * Url: http://www.techtribe.nl
 * Author: Remon de Boer
 *
 * SCHUBERG.view.View
 */

var View = function (remote) {
    this.remote = remote;
    this.init();
}

View.prototype = {

    body: null,
    commonEvents: null,
    photographView: null,
    headerView: null,
    sidebarView: null,
    creditsView: null,
    contentView: null,
    subMenuView: null,
    lightboxView: null,

    init: function () {
        try {
            document.execCommand("BackgroundImageCache", false, true);
        } catch (ignore) {
        }
        this.commonEvents = SCHUBERG.events.CommonEvents.getInstance();
        this.setElements();
        this.setListeners();
        this.photographView = new SCHUBERG.view.PhotographView();
        this.headerView = new SCHUBERG.view.HeaderView();
        this.sidebarView = new SCHUBERG.view.SidebarView(this.headerView);
        this.contentView = new SCHUBERG.view.ContentView(this.sidebarView);
        if (!this.remote) {
            this.subMenuView = new SCHUBERG.view.SubMenuView(this.contentView);
            this.creditsView = new SCHUBERG.view.CreditsView(this.sidebarView, this.subMenuView);
        } else {
            this.leftMenuView = new SCHUBERG.view.LeftMenuView();
        }
        this.lightboxView = new SCHUBERG.view.LightboxView(this.contentView, this.creditsView, this.headerView);
    },

    setElements: function() {
        this.body = document.body;
    },

    setListeners: function() {
        var callback1 = TECHTRIBE.Delegate.create(this, this.startApplication);
        this.commonEvents.startApplicationEvent.subscribe(callback1);
    },

    startApplication: function() {
        YAHOO.util.Dom.setStyle(this.body, "display", "block");
        TECHTRIBE.TransparantFix.init();
    },

    initLogger: function() {
        var configs = {width: "400px", height: "500px", fontSize: "100%"};
        var container = "logger";
        var logger = new YAHOO.widget.LogReader(container, configs);
        var logWriter = new YAHOO.widget.LogWriter();
    }
};
SCHUBERG.view.View = View;


/*
 *** SCHUBERG.view.PhotographView ***
 */
var PhotographView = function() {
    this.init();
}

PhotographView.prototype = {

    //CONSTANTS
    ASPECT_RATIO_WIDTH: 16,
    ASPECT_RATIO_HEIGHT: 9,
    MEDIUM_SCREEN_WIDTH: 1600,
    MEDIUM_SCREEN_HEIGHT: 900,
    MASK_SPACER_RIGHT: 100,

    //INSTANCES
    model: null,
    commonEvents: null,

    //VARIABLES
    highResPhoto: null,

    //CONTAINER ELEMENTS
    bgMask1Container: null,
    bgMask2Container: null,
    bgContainer: null,

    //IMAGE ELEMENTS
    bgMaskImg1: null,
    bgMaskImgTemp1: null,
    bgMaskImg2: null,
    bgMaskImgTemp2: null,
    bgImg: null,
    bgImgTemp: null,

    init: function() {
        this.model = SCHUBERG.model.Model.getInstance();
        this.commonEvents = SCHUBERG.events.CommonEvents.getInstance();
        this.setElements();
        this.setListeners();
        this.loadHighRes();
    },

    setElements: function() {
        this.bgMask1Container = YAHOO.util.Dom.get("bgMask1Container");
        this.bgMask2Container = YAHOO.util.Dom.get("bgMask2Container");
        this.bgContainer = YAHOO.util.Dom.get("bgContainer");
        this.bgMaskImg1 = this.bgMask1Container && this.bgMask1Container.getElementsByTagName("IMG")[0];
        this.bgMaskImg2 = this.bgMask2Container && this.bgMask2Container.getElementsByTagName("IMG")[0];
        this.bgImg = this.bgContainer && this.bgContainer.getElementsByTagName("IMG")[0];
    },

    setListeners: function() {
        var callback1 = TECHTRIBE.Delegate.create(this, this.update);
        this.commonEvents.viewUpdateEvent.subscribe(callback1);
    },

    loadHighRes: function() {
        var photoURL;
        if ((screen.width <= this.MEDIUM_SCREEN_WIDTH) && (screen.height <= this.MEDIUM_SCREEN_HEIGHT)) {
            photoURL = this.model.photosObj.medium;
        } else {
            photoURL = this.model.photosObj.high;
        }
        highResPhoto = new Image();
        highResPhoto.onload = TECHTRIBE.Delegate.create(this, this.highResLoaded);
        highResPhoto.src = photoURL;
    },

    highResLoaded: function() {
        this.bgMaskImgTemp1 = this.bgMaskImg1;
        this.bgMaskImgTemp2 = this.bgMaskImg2;
        this.bgImgTemp = this.bgImg;
        this.bgMaskImg1 = document.createElement("img");
        YAHOO.util.Dom.setStyle(this.bgMaskImg1, "opacity", "0");
        this.bgMaskImg1.setAttribute('src', highResPhoto.src);
        this.bgMask1Container.appendChild(this.bgMaskImg1);
        this.bgMaskImg2 = document.createElement("img");
        YAHOO.util.Dom.setStyle(this.bgMaskImg2, "opacity", "0");
        this.bgMaskImg2.setAttribute('src', highResPhoto.src);
        this.bgMask2Container.appendChild(this.bgMaskImg2);
        this.bgImg = document.createElement("img");
        YAHOO.util.Dom.setStyle(this.bgImg, "opacity", "0");
        this.bgImg.setAttribute('src', highResPhoto.src);
        this.bgContainer.appendChild(this.bgImg);
        this.update();
        this.animatePhotoIn();
    },

    animatePhotoIn: function () {
        var animation1 = new YAHOO.util.Anim(this.bgMaskImg1, {opacity: {from: 0, to: 1}}, 1.2);
        animation1.animate();
        var animation2 = new YAHOO.util.Anim(this.bgMaskImg2, {opacity: {from: 0, to: 1}}, 1.2);
        animation2.animate();
        var animation3 = new YAHOO.util.Anim(this.bgImg, {opacity: {from: 0, to: 1}}, 1.2);
        animation3.onComplete.subscribe(TECHTRIBE.Delegate.create(this, this.animatePhotoInCompleted));
        animation3.animate();
    },

    animatePhotoInCompleted: function () {
        this.bgMask1Container.removeChild(this.bgMaskImgTemp1);
        this.bgMaskImgTemp1 = null;
        this.bgMask2Container.removeChild(this.bgMaskImgTemp2);
        this.bgMaskImgTemp2 = null;
        this.bgContainer.removeChild(this.bgImgTemp);
        this.bgImgTemp = null;
    },

    update: function () {
        if (this.model.stageWidth > 25) {
            var subMenuContainer = document.getElementById('subMenuContainer'),
                bgMask2Height = this.model.FOOTER_BAR_HEIGHT,
                bgMask2Top;
            if (subMenuContainer) {
                bgMask2Height += subMenuContainer.offsetHeight + 1;
                bgMask2Top = (this.model.stageHeight - (this.model.FOOTER_BAR_HEIGHT + 36));
            } else {
                bgMask2Top = (this.model.stageHeight - this.model.FOOTER_BAR_HEIGHT);
            }
            var photoSizeArr = this.calculatePhotoSize();
            var photoTop = -((photoSizeArr[1] - this.model.stageHeight) / 2);
            var photoLeft = -((photoSizeArr[0] - this.model.stageWidth) / 2);
            YAHOO.util.Dom.setStyle(this.bgMask1Container, "width", (this.model.stageWidth - this.MASK_SPACER_RIGHT) + "px");
            YAHOO.util.Dom.setStyle(this.bgMask2Container, "width", (this.model.stageWidth - this.MASK_SPACER_RIGHT) + "px");
            YAHOO.util.Dom.setStyle(this.bgMask2Container, "height", bgMask2Height + "px");
            YAHOO.util.Dom.setStyle(this.bgMask2Container, "top", bgMask2Top + "px");
            YAHOO.util.Dom.setStyle(this.bgContainer, "width", this.model.stageWidth + "px");
            YAHOO.util.Dom.setStyle(this.bgContainer, "height", this.model.stageHeight + "px");
            this.bgMaskImg1.width = photoSizeArr[0];
            this.bgMaskImg1.height = photoSizeArr[1];
            YAHOO.util.Dom.setStyle(this.bgMaskImg1, "top", photoTop + "px");
            YAHOO.util.Dom.setStyle(this.bgMaskImg1, "left", photoLeft + "px");
            this.bgMaskImg2.width = photoSizeArr[0];
            this.bgMaskImg2.height = photoSizeArr[1];
            YAHOO.util.Dom.setStyle(this.bgMaskImg2, "top", (photoTop - (this.model.stageHeight - bgMask2Height)) + "px");
            YAHOO.util.Dom.setStyle(this.bgMaskImg2, "left", photoLeft + "px");
            this.bgImg.width = photoSizeArr[0];
            this.bgImg.height = photoSizeArr[1];
            YAHOO.util.Dom.setStyle(this.bgImg, "top", photoTop + "px");
            YAHOO.util.Dom.setStyle(this.bgImg, "left", photoLeft + "px");
        }
    },

    calculatePhotoSize: function () {
        var viewWidth = this.model.stageWidth;
        var viewHeight = this.model.stageHeight;
        if (viewWidth >= ((viewHeight / this.ASPECT_RATIO_HEIGHT) * this.ASPECT_RATIO_WIDTH)) {
            return [viewWidth, ((viewWidth / this.ASPECT_RATIO_WIDTH) * this.ASPECT_RATIO_HEIGHT)];
        } else {
            return [((viewHeight / this.ASPECT_RATIO_HEIGHT) * this.ASPECT_RATIO_WIDTH), viewHeight];
        }
    }
}
SCHUBERG.view.PhotographView = PhotographView;


/*
 *** SCHUBERG.view.HeaderView ***
 */
var HeaderView = function() {
    this.init();
}

HeaderView.prototype = {

    MAX_WIDTH: 960,
    MIN_WIDTH: 840,

    model: null,
    commonEvents: null,

    headerContainer: null,
    header: null,

    width: 0,
    left: 0,

    init: function () {
        this.model = SCHUBERG.model.Model.getInstance();
        this.commonEvents = SCHUBERG.events.CommonEvents.getInstance();
        this.setElements();
        this.setListeners();
        this.setFlash();
    },

    setElements: function () {
        this.headerContainer = YAHOO.util.Dom.get("headerContainer");
        this.header = YAHOO.util.Dom.get("header");
    },

    setListeners: function () {
        var callback1 = TECHTRIBE.Delegate.create(this, this.update);
        this.commonEvents.viewUpdateEvent.subscribe(callback1);
    },

    setFlash: function () {
        swfobject.embedSWF(
            "/wp-content/themes/schubergphilis/swf/Menu.swf",
            "header",
            "100%",
            "100%",
            "9.0.0",
            false,
            // flash vars
        {
            "menuColorPattern" : "1"
        },
            // params
        {
            "allowScriptAccess" : "always",
            "wmode" : "transparent"
        },
            // attributes
            false
            );
    },

    getMenuObj: function () {
        return this.model.menuObj;
    },

    update: function () {
        this.width = this.MIN_WIDTH + ((this.MAX_WIDTH - this.MIN_WIDTH) * this.model.resizeFactor);
        this.left = (this.model.stageWidth - this.width) / 2;
        YAHOO.util.Dom.setStyle(this.headerContainer, "width", this.width + "px");
        YAHOO.util.Dom.setStyle(this.headerContainer, "left", this.left + "px");
    }
}
SCHUBERG.view.HeaderView = HeaderView;


/*
 *** SCHUBERG.view.SidebarView ***
 */
var SidebarView = function (headerView) {
    this.headerView = headerView;
    this.init();
}

SidebarView.prototype = {

    SIDEBAR_WIDTH: 150,

    model: null,
    commonEvents: null,
    headerView: null,

    creditsContainer: null,
    sidebarContainer: null,
    sidebar: null,

    left: 0,

    init: function () {
        this.model = SCHUBERG.model.Model.getInstance();
        this.commonEvents = SCHUBERG.events.CommonEvents.getInstance();
        this.setElements();
        this.setListeners();
        if (this.modules[0]) {
            YAHOO.util.Dom.addClass(this.modules[0], 'highlight');
        }
    },

    setElements: function () {
        this.creditsContainer = YAHOO.util.Dom.get("creditsContainer");
        this.sidebarContainer = YAHOO.util.Dom.get("sidebarContainer");
        this.sidebar = YAHOO.util.Dom.get("sidebar");
        this.modules = YAHOO.util.Dom.getElementsByClassName('module', 'div', this.sidebar);
        if (SBP_ROTATE) {
            var rotate = YAHOO.util.Dom.getElementsByClassName('rotate', 'a', this.sidebar),
                rlen = rotate.length;
            if (rlen > 1) {
                var plen = rlen,
                    item,
                    current,
                    first,
                    next;
                while (rlen--) {
                    item = rotate[rlen];
                    item.parentNode.className += ' rotate';
                    if (rlen > 0) {
                        item.parentNode.style.display = 'none';
                    } else {
                        first = current = 0;
                    }
                }
                var t = window.setInterval(
                    function () {
                        next = (current < (plen - 1)) ? (current + 1) : 0;
                        rotate[current].parentNode.style.display = 'none';
                        var fadeIn = new YAHOO.util.Anim(rotate[next], {opacity: {to: 1}}, .5, YAHOO.util.Easing.easeNone);
                        fadeIn.onComplete.subscribe(
                            function () {
                                var fadeOut = new YAHOO.util.Anim(rotate[next], {opacity: {to: 0.5}}, .5, YAHOO.util.Easing.easeNone);
                                fadeOut.animate();
                            }
                            );
                        fadeIn.animate();
                        rotate[next].parentNode.style.display = '';
                        current = next;
                    },
                    SBP_ROTATE
                    );
                var mlen = this.modules.length,
                    tmp = [],
                    n = 0,
                    m;
                for (var i = 0; i < mlen; i++) {
                    m = this.modules[i];
                    if ((m == first) || !YAHOO.util.Dom.hasClass(m, 'rotate')) {
                        tmp[n++] = m;
                    }
                }
                this.modules = tmp;
            }
        }
    },

    setListeners: function () {
        var callback1 = TECHTRIBE.Delegate.create(this, this.update);
        this.commonEvents.viewUpdateEvent.subscribe(callback1);
    },

    update: function () {
        this.left = (this.headerView.left + this.headerView.width) - this.SIDEBAR_WIDTH;
        var height = this.model.stageHeight - (95 + 80);
        YAHOO.util.Dom.setStyle(this.sidebarContainer, "left", this.left + "px");
        YAHOO.util.Dom.setStyle(this.sidebarContainer, "height", height + "px");
        var maxHeight = this.sidebarContainer.offsetHeight - this.creditsContainer.offsetHeight;
        if (maxHeight > 0) {
            var len = this.modules.length;
            var c = len;
            while (c--) {
                this.modules[c].style.display = '';
            }
            maxHeight -= 20;
            while (len--) {
                if (this.sidebar.offsetHeight > maxHeight) {
                    this.modules[len].style.display = 'none';
                }
            }
            ;
        }
    }
}
SCHUBERG.view.SidebarView = SidebarView;


/*
 *** SCHUBERG.view.ContentView ***
 */
var ContentView = function (sidebarView) {
    this.sidebarView = sidebarView;
    this.init();
}

ContentView.prototype = {

    MAX_WIDTH: 501,
    MIN_WIDTH: 435,
    SIDEBAR_SPACE: 1,

    model: null,
    commonEvents: null,
    sidebarView: null,

    scrollContainer: null,
    contentContainer: null,
    content: null,
    whiteLine: null,
    ghostBG: null,

    width: 0,
    left: 0,

    init: function () {
        this.model = SCHUBERG.model.Model.getInstance();
        this.commonEvents = SCHUBERG.events.CommonEvents.getInstance();
        this.setElements();
        this.createWhiteLine();
        this.createGhostBG();
        this.setListeners();
        this.subMenuContainer = document.getElementById('subMenuContainer');
        //this.scrollContainer.Focus();
    },

    setElements: function () {
        this.scrollContainer = YAHOO.util.Dom.get("scrollContainer");
        this.contentContainer = YAHOO.util.Dom.get("contentContainer");
        this.content = YAHOO.util.Dom.get("content");
    },

    setListeners: function () {
        var callback1 = TECHTRIBE.Delegate.create(this, this.update);
        this.commonEvents.viewUpdateEvent.subscribe(callback1);
    },

    createWhiteLine: function () {
        this.whiteLine = document.createElement("div");
        this.whiteLine.id = 'whiteLine';
        YAHOO.util.Dom.setStyle(this.whiteLine, "position", "absolute");
        YAHOO.util.Dom.setStyle(this.whiteLine, "top", "130px");
        YAHOO.util.Dom.setStyle(this.whiteLine, "zIndex", "500");
        YAHOO.util.Dom.setStyle(this.whiteLine, "background", "#FFFFFF");
        YAHOO.util.Dom.setStyle(this.whiteLine, "width", "510px");
        YAHOO.util.Dom.setStyle(this.whiteLine, "height", "1px");
        YAHOO.util.Dom.setStyle(this.whiteLine, "line-height", "1px");
        YAHOO.util.Dom.setStyle(this.whiteLine, "fontSize", "1px");
        YAHOO.util.Dom.setStyle(this.whiteLine, "overflow", "hidden");
        document.body.appendChild(this.whiteLine);
    },


    createGhostBG: function () {
        this.ghostBG = document.createElement("div");
        this.ghostBG.className = 'noprint';
        YAHOO.util.Dom.setStyle(this.ghostBG, "position", "absolute");
        YAHOO.util.Dom.setStyle(this.ghostBG, "top", "130px");
        YAHOO.util.Dom.setStyle(this.ghostBG, "left", "0px");
        YAHOO.util.Dom.setStyle(this.ghostBG, "zIndex", "100");
        YAHOO.util.Dom.setStyle(this.ghostBG, "background", "#FFFFFF");
        YAHOO.util.Dom.setStyle(this.ghostBG, "opacity", "0");
        YAHOO.util.Dom.setStyle(this.ghostBG, "width", "1px");
        YAHOO.util.Dom.setStyle(this.ghostBG, "height", "1px");
        this.scrollContainer.appendChild(this.ghostBG);
    },

    update: function () {
        this.left = this.sidebarView.left - (this.width + this.SIDEBAR_SPACE);
        this.width = this.MIN_WIDTH + ((this.MAX_WIDTH - this.MIN_WIDTH) * this.model.resizeFactor);
        YAHOO.util.Dom.setStyle(this.contentContainer, "width", this.width + "px");
        YAHOO.util.Dom.setStyle(this.contentContainer, "left", this.left + "px");
        YAHOO.util.Dom.setStyle(this.whiteLine, "width", this.width + "px");
        YAHOO.util.Dom.setStyle(this.whiteLine, "left", this.left + "px");
        YAHOO.util.Dom.setStyle(this.ghostBG, "width", (this.model.stageWidth - 25) + "px");
        YAHOO.util.Dom.setStyle(this.ghostBG, "height", (this.content.offsetHeight - 25) + "px");
        var height = this.model.stageHeight - (95 + 80);
        if (this.subMenuContainer) {
            height -= this.subMenuContainer.offsetHeight;
        }
        this.content.style.minHeight = (height + 1) + 'px';
    }
}
SCHUBERG.view.ContentView = ContentView;


/*
 *** SCHUBERG.view.SubMenuView ***
 */
var SubMenuView = function (contentView) {
    this.contentView = contentView;
    this.init();
}

SubMenuView.prototype = {

    model: null,
    commonEvents: null,
    contentView: null,

    subMenuContainer: null,
    subMenu: null,

    top: 0,

    init: function () {
        this.model = SCHUBERG.model.Model.getInstance();
        this.commonEvents = SCHUBERG.events.CommonEvents.getInstance();
        this.setElements();
        this.setListeners();
    },

    setElements: function () {
        this.subMenuContainer = YAHOO.util.Dom.get("subMenuContainer");
        this.subMenu = YAHOO.util.Dom.get("subMenu");
    },

    setListeners: function () {
        var callback1 = TECHTRIBE.Delegate.create(this, this.update);
        this.commonEvents.viewUpdateEvent.subscribe(callback1);
    },

    update: function () {
        YAHOO.util.Dom.setStyle(this.subMenuContainer, "width", this.contentView.width + "px");
        YAHOO.util.Dom.setStyle(this.subMenuContainer, "left", this.contentView.left + "px");
        if (this.contentView.content.offsetHeight > (this.model.stageHeight - (this.model.HEADER_BAR_HEIGHT + this.model.FOOTER_BAR_HEIGHT))) {
            //this.top = (this.model.stageHeight-(this.model.FOOTER_BAR_HEIGHT-1));
        } else {
            //this.top = (this.contentView.content.offsetHeight+(this.model.HEADER_BAR_HEIGHT+1));
        }
        YAHOO.util.Dom.setStyle(this.subMenuContainer, "bottom", this.model.FOOTER_BAR_HEIGHT + "px");
    }
}
SCHUBERG.view.SubMenuView = SubMenuView;


/*
 *** SCHUBERG.view.CreditsView ***
 */
var CreditsView = function (sidebarView, subMenuView) {
    this.sidebarView = sidebarView;
    this.subMenuView = subMenuView;
    this.init();
}

CreditsView.prototype = {
    model: null,
    commonEvents: null,
    sidebarView: null,
    subMenuView: null,

    creditsContainer: null,
    credits: null,

    top: 0,

    init: function () {
        this.model = SCHUBERG.model.Model.getInstance();
        this.commonEvents = SCHUBERG.events.CommonEvents.getInstance();
        this.setElements();
        this.setListeners();
    },

    setElements: function () {
        this.creditsContainer = YAHOO.util.Dom.get("creditsContainer");
        this.credits = YAHOO.util.Dom.get("credits");
    },

    setListeners: function () {
        var callback1 = TECHTRIBE.Delegate.create(this, this.update);
        this.commonEvents.viewUpdateEvent.subscribe(callback1);
    },

    update: function () {
        var top1 = ((this.subMenuView.top + this.model.SUB_MENU_HEIGHT) - this.credits.offsetHeight);
        var top2 = (this.model.HEADER_BAR_HEIGHT + this.sidebarView.sidebar.offsetHeight + 10);
        if (top1 < top2) {
            this.top = top2;
        } else {
            this.top = top1;
        }
        YAHOO.util.Dom.setStyle(this.creditsContainer, "left", (this.sidebarView.left + 15) + "px");
        //YAHOO.util.Dom.setStyle(this.creditsContainer, "top", this.top + "px");
    }
}
SCHUBERG.view.CreditsView = CreditsView;


/*
 *** SCHUBERG.view.LightboxView ***
 */
var LightboxView = function (contentView, creditsView, headerView) {
    this.contentView = contentView;
    this.creditsView = creditsView;
    this.headerView = headerView;
    this.init();
};

LightboxView.prototype = {

    CLOSE_BUTTON_HEIGHT: 18,
    model: null,
    commonEvents: null,
    contentView: null,
    creditsView: null,
    headerView: null,
    connectionManager: null,

    lightbox: null,
    lightboxContent:null,
    lightboxBG: null,
    highResPhoto: null,
    galleryImg: null,
    zoomImg : null,
    zoomImgWidth : null,
    zoomImgHeight : null,
    logoSmallImg: null,
    closeButton: null,
    uriRef : null,

    top: 0,
    lightboxActive: false,
    galleryActive: false,
    zoomActive: false,
    flipBookActive: false,

    flipBookContainer: null,
    headerContainer: null,
    whiteLine: null,
    contentContainer: null,
    sidebarContainer: null,
    careersMenuContainer: null,
    subMenuContainer: null,

    video : null,

    init: function () {
        this.model = SCHUBERG.model.Model.getInstance();
        this.commonEvents = SCHUBERG.events.CommonEvents.getInstance();
        this.connectionManager = new SCHUBERG.controller.ConnectionManager();
        this.headerContainer = document.getElementById('header');
        this.whiteLine = document.getElementById('whiteLine');
        this.contentContainer = document.getElementById('scrollContainer');
        this.sidebarContainer = document.getElementById('sidebarContainer').parentNode;
        this.careersMenuContainer = document.getElementById('careers-sidebar');
        this.subMenuContainer = document.getElementById('subMenuContainer');
        this.createElements();
        this.setTriggers();
        this.setListeners();
        YAHOO.util.Dom.setStyle(this.logoSmallImg, "zIndex", "1");
        YAHOO.util.Dom.setStyle(this.closeButton, "zIndex", "1");
    },

    setTriggers: function () {
        var triggerLightboxes = YAHOO.util.Dom.getElementsByClassName("triggerLightbox", "A"),
            len = triggerLightboxes.length;
        for (var i = 0; i < len; i++)
        {
            var triggerLightBox = triggerLightboxes[i];
            if (YAHOO.util.Dom.hasClass(triggerLightBox, "triggerVideo")) {
                this.videoSize = triggerLightBox.rel;
                triggerLightBox.onclick = TECHTRIBE.Delegate.create(this, this.openLightbox, triggerLightBox.href, true);
            } else {
                triggerLightBox.onclick = TECHTRIBE.Delegate.create(this, this.openLightbox, triggerLightBox.href, false);
            }
        }
        var galleryTable = YAHOO.util.Dom.getElementsByClassName("galleryTable", "TABLE");
        if (galleryTable.length > 0) {
            galleryTable = galleryTable[0];
            var triggerGalleryPics = galleryTable.getElementsByTagName("A");
            for (i = 0,len = triggerGalleryPics.length; i < len; i++)
            {
                var triggerGalleryPic = triggerGalleryPics[i];
                if (triggerGalleryPic.className != "ignore") {
                    triggerGalleryPic.onclick = TECHTRIBE.Delegate.create(this, this.openGalleryBox, triggerGalleryPic.href);
                }
            }
        }
        var zoom = YAHOO.util.Dom.getElementsByClassName("zoom", "A"),
            zlen = zoom.length;
        for (i = 0; i < zlen; i++) {
            zoom[i].onclick = TECHTRIBE.Delegate.create(this, this.openZoomImage, zoom[i]);
        }
        // flipbook
        var a = document.getElementsByTagName('A'),
            l = a.length,
            link,
            needle = 'flipbook.swf',
            needleLength = needle.length;
        while (l--) {
            link = a[l];
            if (link.href.lastIndexOf(needle) == (link.href.length - needleLength)) {
                link.onclick = TECHTRIBE.Delegate.create(this, this.openFlipBook, link.href);
            }
        }
    },

    createElements: function () {
        this.lightbox = document.createElement("div");
        this.lightbox.id = "lightbox";
        YAHOO.util.Dom.setStyle(this.lightbox, "position", "absolute");
        YAHOO.util.Dom.setStyle(this.lightbox, "top", "130px");
        YAHOO.util.Dom.setStyle(this.lightbox, "zIndex", "1");
        YAHOO.util.Dom.setStyle(this.lightbox, "display", "none");
        YAHOO.util.Dom.setStyle(this.lightbox, "background", "#FFFFFF");
        YAHOO.util.Dom.setStyle(this.lightbox, "width", "1px");
        YAHOO.util.Dom.setStyle(this.lightbox, "height", "1px");
        YAHOO.util.Dom.setStyle(this.lightbox, "overflow", "hidden");
        YAHOO.util.Dom.setStyle(this.lightbox, "opacity", "0");
        document.body.appendChild(this.lightbox);
        this.lightbox.innerHTML = "<div onclick='SCHUBERG.mainView.lightboxView.closeLightbox();' style='float: right; cursor: pointer;'><img src='/wp-content/themes/schubergphilis/img/closeButton.png' width='55' height='18'/></div><div class='clear' style='height: 0px;'></div>";
        this.lightboxContent = document.createElement("div");
        this.lightboxContent.id = "lightboxContent";
        YAHOO.util.Dom.setStyle(this.lightboxContent, "overflow", "auto");
        YAHOO.util.Dom.setStyle(this.lightboxContent, "overflowX", "hidden");
        YAHOO.util.Dom.setStyle(this.lightboxContent, "width", "100%");
        YAHOO.util.Dom.setStyle(this.lightboxContent, "height", "1px");
        YAHOO.util.Dom.setStyle(this.lightboxContent, "color", "#000000");
        this.lightbox.appendChild(this.lightboxContent);
        this.lightboxInnerContent = document.createElement("div");
        this.lightboxInnerContent.id = "lightboxInnerContent";
        this.lightboxContent.appendChild(this.lightboxInnerContent);
        this.lightboxBG = document.createElement("div");
        YAHOO.util.Dom.setStyle(this.lightboxBG, "position", "absolute");
        YAHOO.util.Dom.setStyle(this.lightboxBG, "top", "0px");
        YAHOO.util.Dom.setStyle(this.lightboxBG, "zIndex", "1");
        YAHOO.util.Dom.setStyle(this.lightboxBG, "opacity", ".5");
        YAHOO.util.Dom.setStyle(this.lightboxBG, "display", "none");
        YAHOO.util.Dom.setStyle(this.lightboxBG, "background", "#000000");
        YAHOO.util.Dom.setStyle(this.lightboxBG, "width", "1px");
        YAHOO.util.Dom.setStyle(this.lightboxBG, "height", "1px");
        YAHOO.util.Dom.setStyle(this.lightboxBG, "opacity", "0");
        this.lightboxBG.onclick = TECHTRIBE.Delegate.create(this, this.closeLightbox);
        document.body.appendChild(this.lightboxBG);

        this.logoSmallImg = document.createElement("img");
        this.logoSmallImg.setAttribute('src', "/wp-content/themes/schubergphilis/img/logoSmall.png");
        this.logoSmallImg.setAttribute('width', "250");
        this.logoSmallImg.setAttribute('height', "17");
        document.body.appendChild(this.logoSmallImg);
        this.logoSmallImg.style.position = "absolute";

        this.closeButton = document.createElement("img");
        this.closeButton.setAttribute('src', "/wp-content/themes/schubergphilis/img/closeButtonWit.png");
        document.body.appendChild(this.closeButton);
        this.closeButton.onclick = TECHTRIBE.Delegate.create(this, this.closeGalleryBox);
        this.closeButton.style.position = "absolute";
        this.closeButton.style.cursor = "pointer";

    },

    setListeners: function () {
        var callback1 = TECHTRIBE.Delegate.create(this, this.update);
        this.commonEvents.viewUpdateEvent.subscribe(callback1);
    },

    openLightbox: function (url, isVideo) {
        isVideo && (this.video = true);
        if (this.lightboxActive) {
            if (url == this.uriRef) {
                this.closeLightbox();
            } else {
                this.uriRef = url;
                this.connectionManager.asyncRequestGet(url + "?view=xhr", TECHTRIBE.Delegate.create(this, this.setContent));
            }
            return false;
        }
        if (isVideo) {
            this.lightboxInnerContent.innerHTML = "<div id='flashVideo'></div><div style='height: 18px;'>&nbsp;</div>";
            this.setFlash(url);
            YAHOO.util.Dom.setStyle(this.lightbox, "display", "block");
            YAHOO.util.Dom.setStyle(this.lightbox, "zIndex", "600");
            YAHOO.util.Dom.setStyle(this.lightboxBG, "display", "block");
            YAHOO.util.Dom.setStyle(this.lightboxBG, "zIndex", "500");
            this.update();
            this.fadeIn();
        } else {
            YAHOO.util.Dom.setStyle(this.creditsView.creditsContainer, "zIndex", "1000");
            this.connectionManager.asyncRequestGet(url + "?view=xhr", TECHTRIBE.Delegate.create(this, this.setContent));
        }
        this.uriRef = url;
        this.lightboxActive = true;
        this.update();
        return false;
    },

    openGalleryBox: function (url) {
        this.galleryActive = true;
        this.highResPhoto = new Image();
        this.highResPhoto.onload = TECHTRIBE.Delegate.create(this, this.highResLoaded);
        this.highResPhoto.src = url;
        this.closeButton.onclick = TECHTRIBE.Delegate.create(this, this.closeGalleryBox);
        return false;
    },

    openZoomImage: function (a) {
        var img = a.getElementsByTagName('IMG')[0],
            clone = img.cloneNode(true);
        document.body.appendChild(clone);
        this.zoomImgWidth = clone.width;
        this.zoomImgHeight = clone.height;
        YAHOO.util.Dom.setStyle(clone, "opacity", "0");
        clone.onclick = TECHTRIBE.Delegate.create(this, this.closeZoomImage, clone);
        this.zoomImg = clone;
        this.zoomActive = true;
        this.closeButton.setAttribute('src', "/wp-content/themes/schubergphilis/img/closeButton.png");
        this.closeButton.onclick = TECHTRIBE.Delegate.create(this, this.closeZoomImage);
        this.update();
        this.fadeInZoomImage();
        return false;
    },

    closeZoomImage: function (clone) {
        this.zoomActive = false;
        this.fadeOutZoomImage();
    },

    highResLoaded: function () {
        this.galleryImg.setAttribute('src', this.highResPhoto.src);
        this.galleryImg.style.position = "absolute";
        YAHOO.util.Dom.setStyle(this.galleryImg, "opacity", "0");
        this.galleryImg.style.zIndex = "2000";
        this.galleryImg.onclick = TECHTRIBE.Delegate.create(this, this.closeGalleryBox, this.galleryImg);
        document.body.appendChild(this.galleryImg);
        this.update();
        this.fadeInGallery();
    },

    closeGalleryBox: function (child) {
        this.galleryActive = false;
        this.fadeOutGallery();
    },

    openFlipBook: function (url) {
        var style;
        this.flipBookActive = true;
        this.flipBookContainer = document.createElement('DIV');
        style = this.flipBookContainer.style;
        style.position = 'absolute';
        style.zIndex = '501';
        style.width = this.model.stageWidth + 'px';
        style.height = this.model.stageHeight + 'px';
        this.flipBookDummy = document.createElement('DIV');
        this.flipBookDummy.id = 'flipBook';
        this.flipBookContainer.appendChild(this.flipBookDummy);
        document.body.appendChild(this.flipBookContainer);
        this.closeButton.onclick = TECHTRIBE.Delegate.create(this, this.closeFlipBook);
        this.update();
        this.setFlipBook(url);
        this.fadeInFlipBook();
        return false;
    },

    closeFlipBook: function () {
        this.flipBookActive = false;
        this.fadeOutFlipBook();
    },

    setFlash: function (url) {
        swfobject.embedSWF(
            url,
            "flashVideo",
            "100%",
            "100%",
            "9.0.0",
            false,
            // flash vars
        {
            "autoplay" : "true",
            "colourSet" : "orange",
            "brandText" : "Schuberg Philis",
            "brandLink" : "www.schubergphilis.com",
            "border" : "none"
        },
            // params
        {
            "allowScriptAccess" : "always",
            "allowFullScreen" : "true",
            "wmode" : "transparent"
        },
            // attributes
            false
            );
    },

    setFlipBook: function (url) {
        swfobject.embedSWF(
            url,
            "flipBook",
            "100%",
            "100%",
            "9.0.0",
            false,
            false,
            // params
        {
            "allowScriptAccess" : "sameDomain",
            "allowFullScreen" : "true",
            "quality"  : "high",
            "wmode" : "transparent",
            "scale" : "noscale",
            "align" : "TL",
            "salign" : "TL"
        },
            // attributes
            false
            );
    },

    setContent: function (res) {
        this.lightboxInnerContent.innerHTML = "<div>" + res.responseText + "</div>";
        YAHOO.util.Dom.setStyle(this.lightbox, "display", "block");
        YAHOO.util.Dom.setStyle(this.lightbox, "zIndex", "600");
        YAHOO.util.Dom.setStyle(this.lightboxBG, "display", "block");
        YAHOO.util.Dom.setStyle(this.lightboxBG, "zIndex", "500");
        this.update();
        this.fadeIn();
    },

    fadeIn: function () {
        if (this.lightbox.animation != null) {
            if (this.lightbox.animation.isAnimated) {
                var opacity = YAHOO.util.Dom.getStyle(this.lightbox, "opacity");
                this.lightbox.animation.stop(false);
                YAHOO.util.Dom.setStyle(this.lightbox, "opacity", opacity);
            }
        }
        this.lightbox.animation = new YAHOO.util.Anim(this.lightbox, {opacity: {to: 1}}, .7, YAHOO.util.Easing.easeNone);
        this.lightbox.animation.animate();
        if (this.lightboxBG.animation != null) {
            if (this.lightboxBG.animation.isAnimated) {
                var opacity = YAHOO.util.Dom.getStyle(this.lightboxBG, "opacity");
                this.lightboxBG.animation.stop(false);
                YAHOO.util.Dom.setStyle(this.lightboxBG, "opacity", opacity);
            }
        }
        this.lightboxBG.animation = new YAHOO.util.Anim(this.lightboxBG, {opacity: {to: 0.75}}, 0.7, YAHOO.util.Easing.easeNone);
        this.lightboxBG.animation.animate();
    },


    fadeInGallery: function () {
        YAHOO.util.Dom.setStyle(this.lightboxBG, "display", "block");
        YAHOO.util.Dom.setStyle(this.lightboxBG, "zIndex", "500");
        if (this.galleryImg.animation != null) {
            if (this.galleryImg.animation.isAnimated) {
                var opacity = YAHOO.util.Dom.getStyle(this.galleryImg, "opacity");
                this.galleryImg.animation.stop(false);
                YAHOO.util.Dom.setStyle(this.galleryImg, "opacity", opacity);
            }
        }
        this.galleryImg.animation = new YAHOO.util.Anim(this.galleryImg, {opacity: {to: 1}}, .7, YAHOO.util.Easing.easeNone);
        this.galleryImg.animation.animate();
        if (this.lightboxBG.animation != null) {
            if (this.lightboxBG.animation.isAnimated) {
                var opacity = YAHOO.util.Dom.getStyle(this.lightboxBG, "opacity");
                this.lightboxBG.animation.stop(false);
                YAHOO.util.Dom.setStyle(this.lightboxBG, "opacity", opacity);
            }
        }
        this.lightboxBG.animation = new YAHOO.util.Anim(this.lightboxBG, {opacity: {to: 0.75}}, 0.7, YAHOO.util.Easing.easeNone);
        this.lightboxBG.animation.animate();
        YAHOO.util.Dom.setStyle(this.logoSmallImg, "zIndex", "5000");
        YAHOO.util.Dom.setStyle(this.closeButton, "zIndex", "5000");
    },

    fadeInZoomImage: function () {
        YAHOO.util.Dom.setStyle(this.lightboxBG, "display", "block");
        YAHOO.util.Dom.setStyle(this.lightboxBG, "zIndex", "500");
        if (this.zoomImg.animation != null) {
            if (this.zoomImg.animation.isAnimated) {
                var opacity = YAHOO.util.Dom.getStyle(this.zoomImg, "opacity");
                this.zoomImg.animation.stop(false);
                YAHOO.util.Dom.setStyle(this.zoomImg, "opacity", opacity);
            }
        }
        this.zoomImg.animation = new YAHOO.util.Anim(this.zoomImg, {opacity: {to: 1}}, .7, YAHOO.util.Easing.easeNone);
        this.zoomImg.animation.animate();
        if (this.lightboxBG.animation != null) {
            if (this.lightboxBG.animation.isAnimated) {
                var opacity = YAHOO.util.Dom.getStyle(this.lightboxBG, "opacity");
                this.lightboxBG.animation.stop(false);
                YAHOO.util.Dom.setStyle(this.lightboxBG, "opacity", opacity);
            }
        }
        this.lightboxBG.animation = new YAHOO.util.Anim(this.lightboxBG, {opacity: {to: 0.75}}, 0.7, YAHOO.util.Easing.easeNone);
        this.lightboxBG.animation.animate();
        YAHOO.util.Dom.setStyle(this.closeButton, "zIndex", "5000");
    },

    fadeInFlipBook: function () {
        this.lightboxBG.style.display = "block";
        this.lightboxBG.style.zIndex = "500";
        if (this.lightboxBG.animation != null) {
            if (this.lightboxBG.animation.isAnimated) {
                opacity = YAHOO.util.Dom.getStyle(this.lightboxBG, "opacity");
                this.lightboxBG.animation.stop(false);
                YAHOO.util.Dom.setStyle(this.lightboxBG, "opacity", opacity);
            }
        }
        this.lightboxBG.animation = new YAHOO.util.Anim(this.lightboxBG, {opacity: {to: 0.75}}, 0.7, YAHOO.util.Easing.easeNone);
        var that = this;
        this.lightboxBG.animation.onComplete.subscribe(
            function () {
                that.headerContainer && (that.headerContainer.style.visibility = 'hidden');
                that.whiteLine && (that.whiteLine.style.visibility = 'hidden');
                that.contentContainer && (that.contentContainer.style.visibility = 'hidden');
                that.sidebarContainer && (that.sidebarContainer.style.visibility = 'hidden');
                that.careersMenuContainer && (that.careersMenuContainer.style.visibility = 'hidden');
                that.subMenuContainer && (that.subMenuContainer.style.visibility = 'hidden');
            }
            );
        this.lightboxBG.animation.animate();
        var style = this.closeButton.style;
        style.top = '5px';
        style.right = '25px';
        style.zIndex = '502';
    },

    fadeOut: function () {
        if (this.lightbox.animation != null) {
            if (this.lightbox.animation.isAnimated) {
                var opacity = YAHOO.util.Dom.getStyle(this.lightbox, "opacity");
                this.lightbox.animation.stop(false);
                YAHOO.util.Dom.setStyle(this.lightbox, "opacity", opacity);
            }
        }
        this.lightbox.animation = new YAHOO.util.Anim(this.lightbox, {opacity: {to: 0}}, 0.3, YAHOO.util.Easing.easeNone);
        var that = this;
        this.lightbox.animation.onComplete.subscribe(
            function () {
                that.video = null;
                var close = that.lightbox.getElementsByTagName('IMG')[0];
                close && close.setAttribute('src', "/wp-content/themes/schubergphilis/img/closeButton.png");
                YAHOO.util.Dom.setStyle(that.lightbox, "background", "#fff");
                YAHOO.util.Dom.setStyle(that.lightboxContent, "width", "100%");
                YAHOO.util.Dom.setStyle(that.creditsView.creditsContainer, "zIndex", "");
            }
            );
        this.lightbox.animation.animate();
        if (this.lightboxBG.animation != null) {
            if (this.lightboxBG.animation.isAnimated) {
                var opacity = YAHOO.util.Dom.getStyle(this.lightboxBG, "opacity");
                this.lightboxBG.animation.stop(false);
                YAHOO.util.Dom.setStyle(this.lightboxBG, "opacity", opacity);
            }
        }
        this.lightboxBG.animation = new YAHOO.util.Anim(this.lightboxBG, {opacity: {to: 0}}, 0.3, YAHOO.util.Easing.easeNone);
        this.lightboxBG.animation.onComplete.subscribe(TECHTRIBE.Delegate.create(this, this.fadeOutComplete));
        this.lightboxBG.animation.animate();
    },

    fadeOutComplete: function () {
        YAHOO.util.Dom.setStyle(this.lightbox, "display", "none");
        YAHOO.util.Dom.setStyle(this.lightbox, "zIndex", "1");
        YAHOO.util.Dom.setStyle(this.lightboxBG, "display", "none");
        YAHOO.util.Dom.setStyle(this.lightboxBG, "zIndex", "1");
        this.lightboxInnerContent.innerHTML = "";
    },

    fadeOutGallery: function () {
        if (this.galleryImg) {
            if (this.galleryImg.animation != null) {
                if (this.galleryImg.animation.isAnimated) {
                    var opacity = YAHOO.util.Dom.getStyle(this.galleryImg, "opacity");
                    this.galleryImg.animation.stop(false);
                    YAHOO.util.Dom.setStyle(this.galleryImg, "opacity", opacity);
                }
            }
            this.galleryImg.animation = new YAHOO.util.Anim(this.galleryImg, {opacity: {to: 0}}, 0.3, YAHOO.util.Easing.easeNone);
            this.galleryImg.animation.animate();
        }
        if (this.lightboxBG.animation != null) {
            if (this.lightboxBG.animation.isAnimated) {
                var opacity = YAHOO.util.Dom.getStyle(this.lightboxBG, "opacity");
                this.lightboxBG.animation.stop(false);
                YAHOO.util.Dom.setStyle(this.lightboxBG, "opacity", opacity);
            }
        }

        this.lightboxBG.animation = new YAHOO.util.Anim(this.lightboxBG, {opacity: {to: 0}}, 0.3, YAHOO.util.Easing.easeNone);
        this.lightboxBG.animation.onComplete.subscribe(TECHTRIBE.Delegate.create(this, this.fadeOutGalleryComplete));
        this.lightboxBG.animation.animate();
        YAHOO.util.Dom.setStyle(this.lightbox, "zIndex", "1");
    },

    fadeOutGalleryComplete: function () {
        YAHOO.util.Dom.setStyle(this.lightbox, "display", "none");
        YAHOO.util.Dom.setStyle(this.lightboxBG, "display", "none");
        YAHOO.util.Dom.setStyle(this.lightboxBG, "zIndex", "1");
        YAHOO.util.Dom.setStyle(this.logoSmallImg, "zIndex", "1");
        YAHOO.util.Dom.setStyle(this.closeButton, "zIndex", "1");
        document.body.removeChild(this.galleryImg);
    },

    fadeOutZoomImage: function () {
        if (this.zoomImg) {
            if (this.zoomImg.animation != null) {
                if (this.zoomImg.animation.isAnimated) {
                    var opacity = YAHOO.util.Dom.getStyle(this.zoomImg, "opacity");
                    this.zoomImg.animation.stop(false);
                    YAHOO.util.Dom.setStyle(this.zoomImg, "opacity", opacity);
                }
            }
            this.zoomImg.animation = new YAHOO.util.Anim(this.zoomImg, {opacity: {to: 0}}, 0.3, YAHOO.util.Easing.easeNone);
            this.zoomImg.animation.animate();
        }
        if (this.lightboxBG.animation != null) {
            if (this.lightboxBG.animation.isAnimated) {
                var opacity = YAHOO.util.Dom.getStyle(this.lightboxBG, "opacity");
                this.lightboxBG.animation.stop(false);
                YAHOO.util.Dom.setStyle(this.lightboxBG, "opacity", opacity);
            }
        }

        this.lightboxBG.animation = new YAHOO.util.Anim(this.lightboxBG, {opacity: {to: 0}}, 0.3, YAHOO.util.Easing.easeNone);
        this.lightboxBG.animation.onComplete.subscribe(TECHTRIBE.Delegate.create(this, this.fadeOutZoomComplete));
        this.lightboxBG.animation.animate();
        YAHOO.util.Dom.setStyle(this.lightbox, "zIndex", "1");
    },

    fadeOutZoomComplete: function () {
        YAHOO.util.Dom.setStyle(this.lightbox, "display", "none");
        YAHOO.util.Dom.setStyle(this.lightboxBG, "display", "none");
        YAHOO.util.Dom.setStyle(this.lightboxBG, "zIndex", "1");
        YAHOO.util.Dom.setStyle(this.closeButton, "zIndex", "1");
        document.body.removeChild(this.zoomImg);
    },


    fadeOutFlipBook: function () {
        this.headerContainer && (this.headerContainer.style.visibility = '');
        this.whiteLine && (this.whiteLine.style.visibility = '');
        this.contentContainer && (this.contentContainer.style.visibility = '');
        this.sidebarContainer && (this.sidebarContainer.style.visibility = '');
        this.careersMenuContainer && (this.careersMenuContainer.style.visibility = '');
        this.subMenuContainer && (this.subMenuContainer.style.visibility = '');
        this.update();
        var opacity;
        if (this.lightboxBG.animation != null) {
            if (this.lightboxBG.animation.isAnimated) {
                opacity = YAHOO.util.Dom.getStyle(this.lightboxBG, "opacity");
                this.lightboxBG.animation.stop(false);
                YAHOO.util.Dom.setStyle(this.lightboxBG, "opacity", opacity);
            }
        }
        this.lightboxBG.animation = new YAHOO.util.Anim(this.lightboxBG, {opacity: {to: 0}}, 0.3, YAHOO.util.Easing.easeNone);
        this.lightboxBG.animation.onComplete.subscribe(TECHTRIBE.Delegate.create(this, this.fadeOutFlipBookComplete));
        document.body.removeChild(this.flipBookContainer);
        this.flipBookContainer = null;
        this.lightboxBG.animation.animate();
    },

    fadeOutFlipBookComplete: function () {
        this.lightboxBG.style.display = "none";
        this.lightboxBG.style.zIndex = "1";
        this.closeButton.style.zIndex = "1";
        this.closeButton.style.top = "";
        this.closeButton.style.right = "";
    },

    closeLightbox: function () {
        this.connectionManager.abortConnection();
        this.lightboxActive = false;
        if (this.galleryActive) {
            this.closeGalleryBox();
        }
        if (this.zoomActive) {
            this.closeZoomImage();
        }
        this.fadeOut();
        this.uriRef = null;
        return false;
    },

    update: function () {
        if (this.lightboxActive) {
            YAHOO.util.Dom.setStyle(this.lightbox, "left", this.contentView.left + "px");
            if (this.video) {
                var close = this.lightbox.getElementsByTagName('IMG')[0];
                close && close.setAttribute('src', "/wp-content/themes/schubergphilis/img/closeButtonWit.png");
                var size;
                if (this.videoSize && (this.videoSize.indexOf(',') > 0)) {
                    size = this.videoSize.split(',');
                }
                var x = +size[0] || 768;
                var y = +size[1] || 614;
                var ratio = x / y;
                // content top / bottom spacing
                var chrome = 130 + 80;
                var w = this.model.stageWidth;
                var h = this.model.stageHeight - chrome;
                if (h < y) {
                    x = h * ratio;
                    y = h;
                }
                YAHOO.util.Dom.setStyle(flashBox, "width", x + "px");
                YAHOO.util.Dom.setStyle(flashBox, "height", y + "px");
                YAHOO.util.Dom.setStyle(this.lightboxContent, "width", x + "px");
                YAHOO.util.Dom.setStyle(this.lightboxContent, "height", (y + 18) + "px");
                YAHOO.util.Dom.setStyle(this.lightboxContent, "margin", "0 auto");
                YAHOO.util.Dom.setStyle(this.lightbox, "background", "#000");
                var ref = Math.floor(this.model.stageWidth - (this.contentView.width + this.contentView.left));
                var lbw = x;
                if ((lbw + (ref * 2)) < this.model.stageWidth) {
                    lbw = (this.model.stageWidth - (ref * 2));
                }
                var l = (this.model.stageWidth - lbw) / 2;
                YAHOO.util.Dom.setStyle(this.lightbox, "width", lbw + "px");
                YAHOO.util.Dom.setStyle(this.lightbox, "left", l + "px");
            } else {
                YAHOO.util.Dom.setStyle(this.lightbox, "left", this.contentView.left + "px");
                YAHOO.util.Dom.setStyle(this.lightbox, "width", this.contentView.width + "px");
            }
            var height;
            var maxHeight = this.model.stageHeight - (this.model.HEADER_BAR_HEIGHT + this.model.FOOTER_BAR_HEIGHT);
            if (maxHeight > (this.lightboxInnerContent.offsetHeight + this.CLOSE_BUTTON_HEIGHT)) {
                if ((this.lightboxInnerContent.offsetHeight + this.CLOSE_BUTTON_HEIGHT) < (this.contentView.content.offsetHeight)) {
                    if (this.contentView.content.offsetHeight > maxHeight) {
                        height = maxHeight;
                    } else {
                        height = this.contentView.content.offsetHeight + 36;
                    }
                } else {
                    height = this.lightboxInnerContent.offsetHeight + this.CLOSE_BUTTON_HEIGHT;
                }
            } else {
                height = maxHeight;
            }
            if (this.video) {
                var flashBox = document.getElementById('flashVideo');
                if (flashBox) {
                    YAHOO.util.Dom.setStyle(flashBox, "width", x + "px");
                    YAHOO.util.Dom.setStyle(flashBox, "height", y + "px");
                    YAHOO.util.Dom.setStyle(this.lightboxContent, "width", x + "px");
                    YAHOO.util.Dom.setStyle(this.lightboxContent, "height", (y + 18) + "px");
                    YAHOO.util.Dom.setStyle(this.lightbox, "height", height + "px");
                }
            } else {
                YAHOO.util.Dom.setStyle(this.lightbox, "height", height + "px");
                YAHOO.util.Dom.setStyle(this.lightboxContent, "height", (height - (this.CLOSE_BUTTON_HEIGHT - 2)) + "px");
            }
            YAHOO.util.Dom.setStyle(this.lightboxBG, "width", this.model.stageWidth + "px");
            YAHOO.util.Dom.setStyle(this.lightboxBG, "height", this.model.stageHeight + "px");
        } else if (this.galleryActive) {
            var galleryWidth = this.headerView.width;
            var galleryHeight = (9 * (this.headerView.width / 16));

            YAHOO.util.Dom.setStyle(this.galleryImg, "width", galleryWidth + "px");
            YAHOO.util.Dom.setStyle(this.galleryImg, "height", galleryHeight + "px");
            YAHOO.util.Dom.setStyle(this.galleryImg, "top", 130 + "px");
            YAHOO.util.Dom.setStyle(this.galleryImg, "left", this.headerView.left + "px");
            YAHOO.util.Dom.setStyle(this.lightboxBG, "width", this.model.stageWidth + "px");
            YAHOO.util.Dom.setStyle(this.lightboxBG, "height", this.model.stageHeight + "px");

            YAHOO.util.Dom.setStyle(this.logoSmallImg, "top", 175 + "px");
            YAHOO.util.Dom.setStyle(this.logoSmallImg, "left", this.headerView.left + ((galleryWidth / 3) - 250) + "px");
            YAHOO.util.Dom.setStyle(this.logoSmallImg, "zIndex", "2500");

            YAHOO.util.Dom.setStyle(this.closeButton, "top", 130 + "px");
            YAHOO.util.Dom.setStyle(this.closeButton, "left", ((this.headerView.left + this.headerView.width) - 55) + "px");
            YAHOO.util.Dom.setStyle(this.closeButton, "zIndex", "2500");
        } else if (this.zoomActive) {
            var clone = this.zoomImg,
                maxWidth = (this.model.stageWidth - 40),
                maxHeight = (this.model.stageHeight - (130 + this.model.FOOTER_BAR_HEIGHT)),
                wRatio = maxWidth / this.zoomImgWidth,
                hRatio = maxHeight / this.zoomImgHeight,
                ratio = (wRatio < hRatio) ? wRatio : hRatio;
            clone.width = Math.round(this.zoomImgWidth * ratio);
            clone.height = Math.round(this.zoomImgHeight * ratio);
            clone.style.position = 'absolute';
            clone.style.top = '130px';
            clone.style.zIndex = '2000';
            var cloneOffset = ((this.model.stageWidth - clone.width) / 2);
            clone.style.left = cloneOffset + 'px';
            YAHOO.util.Dom.setStyle(this.lightboxBG, "width", this.model.stageWidth + "px");
            YAHOO.util.Dom.setStyle(this.lightboxBG, "height", this.model.stageHeight + "px");
            YAHOO.util.Dom.setStyle(this.closeButton, "top", 130 + "px");
            YAHOO.util.Dom.setStyle(this.closeButton, "left", ((cloneOffset + clone.width) - 55) + "px");
            YAHOO.util.Dom.setStyle(this.closeButton, "zIndex", "2500");
        } else if (this.flipBookActive) {
            style = this.lightboxBG.style;
            style.width  = this.model.stageWidth + "px";
            style.height = this.model.stageHeight + "px";
            style = this.flipBookContainer.style;
            style.width  = this.model.stageWidth + "px";
            style.height = this.model.stageHeight + "px";
        }
    }
}
SCHUBERG.view.LightboxView = LightboxView;


/*
 *** SCHUBERG.view.LeftMenuView ***
 */
var LeftMenuView = function () {
    this.init();
}

LeftMenuView.prototype = {

    MAX_WIDTH: 960,
    MIN_WIDTH: 840,
    model: null,
    commonEvents: null,
    leftMenuContainer: null,
    left: 0,

    init: function () {
        this.model = SCHUBERG.model.Model.getInstance();
        this.commonEvents = SCHUBERG.events.CommonEvents.getInstance();
        this.setElements();
        this.setListeners();
    },

    setElements: function () {
        this.leftMenuContainer = YAHOO.util.Dom.get("leftMenu");
    },

    setListeners: function () {
        var callback1 = TECHTRIBE.Delegate.create(this, this.update);
        this.commonEvents.viewUpdateEvent.subscribe(callback1);
    },

    update: function() {
        this.width = this.MIN_WIDTH + ((this.MAX_WIDTH - this.MIN_WIDTH) * this.model.resizeFactor);
        this.left = (this.model.stageWidth - this.width) / 2;
        var height = this.model.stageHeight - (130 + 80);
        YAHOO.util.Dom.setStyle(this.leftMenuContainer, "left", (this.left - 10) + "px");
        YAHOO.util.Dom.setStyle(this.leftMenuContainer, "height", height + "px");
    }
}
SCHUBERG.view.LeftMenuView = LeftMenuView;

