// JavaScript Document
// <![CDATA[

function pushController(params) {

    // private vars
    var name = params;

    var pageInit = false; // flag to determine whether page has been viewed or not
    var pushesVisibleBool; // flag to denote whether pushes are currently visible	
    var browsercanFade; // flag sets push fade out or not. stop black background in IE	
    var canshowPushes; // flag to denote whether pushes can be shown - dictated by screen width / resolution
    var showPushFlag; // flag to display pushes or not depending on browser screen size // deprecated
    var pushesShowing; // flag to register whether pushes are showing or not	// deprecated
    				   
    //public funcs
    this.initPushes = init;
    this.resolutionCheck = resolutionCheck;

    this.getName = returnName;
    this.pushesVisible = pushesVisible;
    this.fadePushes = fadePushes;
    this.embedFlashPushes = embedFlashPushes;
    this.setPushPositions = setPushPositions;
    this.hidePushes = hidePushes;
    this.animatePushes = animatePushes;
    this.fadeInPushes = fadeInPushes;

    function init() {

        // showPushFlag = resolutionCheck();
        canshowPushes = resolutionCheck();

        if (canshowPushes) {
            embedFlashPushes();
            setPushPositions();
        };
    }

    function embedFlashPushes() {

        // embed flash
        var flashvars = {};
        var attributes = {};
        var params = {};
        var base_url = "";
        params.wmode = "transparent";

        //alert(push1.title);
        if (push1) {

            fl1So = new SWFObject("/swfs/pushes/push.swf", "fl1_fo", "100%", "100%", "9", "#ffffff");
            fl1So.addParam("wmode", "transparent");
            fl1So.addParam("base", base_url);
            fl1So.addVariable("pushTitle", push1.title);
            fl1So.addVariable("pushImage", push1.image);
            fl1So.addVariable("pushLnk", push1.lnk);
            fl1So.addVariable("pushTxt", push1.txt);
            fl1So.write("fl1");
        }

        if (push2) {
            fl2So = new SWFObject("/swfs/pushes/push.swf", "fl2_fo", "100%", "100%", "9", "#ffffff");
            fl2So.addParam("wmode", "transparent");
            fl2So.addParam("base", base_url);
            fl2So.addVariable("pushTitle", push2.title);
            fl2So.addVariable("pushImage", push2.image);
            fl2So.addVariable("pushLnk", push2.lnk);
            fl2So.addVariable("pushTxt", push2.txt);
            fl2So.write("fl2");
        }
        if (push3) {
            fl3So = new SWFObject("/swfs/pushes/push.swf", "fl3_fo", "100%", "100%", "9", "#ffffff");
            fl3So.addParam("wmode", "transparent");
            fl3So.addParam("base", base_url);
            fl3So.addVariable("pushTitle", push3.title);
            fl3So.addVariable("pushImage", push3.image);
            fl3So.addVariable("pushLnk", push3.lnk);
            fl3So.addVariable("pushTxt", push3.txt);
            fl3So.write("fl3");
        }
        if (push4) {
            fl4So = new SWFObject("/swfs/pushes/push.swf", "fl4_fo", "100%", "100%", "9", "#ffffff");
            fl4So.addParam("wmode", "transparent");
            fl4So.addParam("base", base_url);
            fl4So.addVariable("pushTitle", push4.title);
            fl4So.addVariable("pushImage", push4.image);
            fl4So.addVariable("pushLnk", push4.lnk);
            fl4So.addVariable("pushTxt", push4.txt);
            fl4So.write("fl4");
        }

        // pushes embedded
        pushesVisibleBool = true;

    }

    function setPushPositions() {

        leftBoxesX = mainPanelDiv.leftGutterMidPoint - ($(".pushpanel").width() / 2);
        rightBoxesX = mainPanelDiv.rightGutterMidPoint - ($(".pushpanel").width() / 2);

        if (pageInit == false) {

            $("#p1").css({
                'left': leftBoxesX
            });
            $("#p2").css({
                'left': leftBoxesX
            });
            $("#p3").css({
                'left': rightBoxesX
            });
            $("#p4").css({
                'left': rightBoxesX
            });
            pageInit = true;
        }

    }

    function hidePushes() {
        pPanels.fadeOut(0);
        pushControl.pushesShowing = false;
    }

    function resolutionCheck() {
        if ($(window).width() <= minScreenWidth) {
            this.showPushFlag = false;
            return false;
        } else {
            this.showPushFlag = true;
            return true;
        }
    }

    function fadePushes(tSpeed) {
        if (tSpeed == undefined) {
            tSpeed = fadeSpeed;
        }
        var t = resolutionCheck();
        if (pushesVisibleBool == true) {
            $(".pushpanel").fadeOut(tSpeed, function () {
                pushesVisibleBool = false
            });
            return;
        } else if (pushesVisibleBool == false && t == true) {
            $(".pushpanel").fadeIn(tSpeed, function () {
                pushesVisibleBool = true
            });
            return;
        }
    }

    //fades in pushes with animation


    function fadeInPushes(tSpeed) {
        $(".pushpanel").fadeIn(tSpeed, function () {
            pushesVisibleBool = true
        });
    }

    function pushesVisible() {
        if (pushesVisibleBool == true) {
            return true;
        } else if (pushesVisibleBool == false) {
            return false;
        }
    }

    function returnName() {
        return name;
    }

    function animatePushes() {
        updateContentPanel();
        pushControl.setPushPositions();

        var t = resolutionCheck();

        // if the screen is resized larger from less than screenwidth - need to fade up pushes and then animate
        if (t && pushesVisibleBool == false) {
            fadeInPushes();
        }

        if (t) {

            $("#p1").animate({
                'left': leftBoxesX
            }, fadeSpeed);

            $("#p2").animate({
                'left': leftBoxesX
            }, fadeSpeed);

            $("#p3").animate({
                'left': rightBoxesX
                //top:rightBoxY				
            }, fadeSpeed);

            $("#p4").animate({
                'left': rightBoxesX
                //top:rightBoxY+200				
            }, fadeSpeed);

        } else {

            fadePushes();
        }

    }

}



// ]]> 
