﻿/*
**********************************************
**** BEGIN Style Switching
**********************************************
*/


styleNum = document.cookie.charAt(6); //

function cssSwitch(styleCampus) {
    if (styleCampus == 'woodway') {
        document.cookie = 'style=0';
    } else if (styleCampus == 'north') {
        document.cookie = 'style=1';
    } else if (styleCampus == 'west') {
        document.cookie = 'style=2';
    } else if (styleCampus == 'cypress') {
        document.cookie = 'style=3';
    } else if (styleCampus == 'pearland') {
        document.cookie = 'style=4';
    } else {
        document.cookie = 'style=0';
    }
    window.location.reload();
}

function styleEmbed() {
    var styleCampus;

    if (styleNum != '') {
        //alert('we have something');
        if (styleNum == 0) {
            styleCampus = "woodway";
        } else if (styleNum == 1) {
            styleCampus = "north";
        } else if (styleNum == 2) {
            styleCampus = "west";
        } else if (styleNum == 3) {
            styleCampus = "cypress";
        } else if (styleNum == 4) {
            styleCampus = "pearland";
        }
    } else {
        styleCampus = "woodway";
    }

    document.writeln('<link rel="stylesheet" type="text/css" href="/styles/second-' + styleCampus + '.css">');
}


/*
**********************************************
**** BEGIN Ministry Index Panel Slider
**********************************************
*/


var toggleFlag = true;

function showIndex() {
    if (toggleFlag == true) {
        var myFx = new Fx.Tween('ministryIndex');
        myFx.start('top', '-222 px', '0');

        toggleFlag = false;
    } else {
        var myFx = new Fx.Tween('ministryIndex');
        myFx.start('top', '0', '-222 px');
        toggleFlag = true;
    }
}

var indexClickFlag = true;

//toggles index arrow up and down depending on state of index panel
function arrowClickSwitch() {
    if (indexClickFlag) {
        document.getElementById("v_toggle").style.background = "url(/images/_img/global/sm-whitearrow-up.gif) no-repeat right center";
        indexClickFlag = false;
    } else {
        document.getElementById("v_toggle").style.background = "url(/images/_img/global/sm-whitearrow-down.gif) no-repeat right center";
        indexClickFlag = true;
    }
}

//checks state of panel and uses correct 'over' graphic for arrow
function arrowOverSwitch() {
    if (indexClickFlag) {
        document.getElementById("v_toggle").style.background = "url(/images/_img/global/sm-blackarrow-down.gif) no-repeat right center";
    } else {
        document.getElementById("v_toggle").style.background = "url(/images/_img/global/sm-blackarrow-up.gif) no-repeat right center";
    }
}

//checks state of panel and uses correct 'out' graphic for arrow
function arrowOutSwitch() {
    if (indexClickFlag) {
        document.getElementById("v_toggle").style.background = "url(/images/_img/global/sm-whitearrow-down.gif) no-repeat right center";
    } else {
        document.getElementById("v_toggle").style.background = "url(/images/_img/global/sm-whitearrow-up.gif) no-repeat right center";
    }
}



/*
**********************************************
**** BEGIN Image Switcher DEPRECATED
**** this code will not work in instances where there's
**** more than 1 ID with the same name
**********************************************
*/
var IMG_PATH = "/images/_img/";
var IMG_GB = "global/";
var IMG_NR = "north/";
var IMG_WS = "west/";
var IMG_CP = "cypress/";
var IMG_PL = "pearland/";

/* this function will create button states assuming id and over and out states have the same root name */
/* the array contains all site buttons. These will only be used if an element is present on the current page */
function addButtonStates(dirAndButtonArr) {

    //build event listeners using builButtonStates() based on array
    for (n = 0; n < dirAndButtonArr.length; n++) {
        buildButtonStates(dirAndButtonArr[n].dir, dirAndButtonArr[n].img);
    }
}

function buildButtonStates(buttonDIR, buttonID) {
    if (document.getElementById(buttonID)) {//if element exists on the page add event listener
        $(buttonID).addEvent('mouseover', function() { imageSwap(buttonDIR, buttonID, 'over'); });
        $(buttonID).addEvent('mouseout', function() { imageSwap(buttonDIR, buttonID, 'out'); });
    } else {
        //alert(buttonID + ' doesnt exist'); //this line is for testing only
    }
}

function imageSwap(buttonDIR, buttonID, state) {
    // this first section figures out what image type the original image
    // is and assumes replaced images will be of the same type
    var theImage = document.getElementById(buttonID).src;
    var arrImageString = theImage.split(".");
    var imageType = arrImageString[arrImageString.length - 1];
    //alert(imageType);

    // in the section below buttonID and image name must coincide
    // image names should be [buttonID] + -f1. or -f2. + imageType
    if (state == 'over') {
        document.getElementById(buttonID).src = IMG_PATH + buttonDIR + "/" + buttonID + "-f2." + imageType; //buttonID and image name must match
        //alert(document.getElementById(buttonID).src);
    } else if (state == 'out') {
        document.getElementById(buttonID).src = IMG_PATH + buttonDIR + "/" + buttonID + "-f1." + imageType; //buttonID and image name must match
    }
}

/*
**********************************************
**** BEGIN Image Switcher NEW!
**** With stronger stain fighting power
**********************************************
*/

function iSwaper() {
    $$('img.iSwap', 'input.iSwap').each(function(el) {

        var theSrcF1 = el.src;
        var theSrcF2 = theSrcF1.replace('-f1', '-f2');

        el.addEvent('mouseover', function() { el.src = theSrcF2 });
        el.addEvent('mouseout', function() { el.src = theSrcF1 });
    });
}


/*
**********************************************
**** BEGIN Location Slidedown DEPRECATED
**********************************************
*/


//toggle location arrows
var locClickFlag = true;

function locClickSwitch() {
    if (locClickFlag) {
        document.getElementById("changeLocationBtn").style.background = "url(/images/_img/global/sm-whitearrow-up.gif) no-repeat right center";
        locClickFlag = false;
    } else {
        document.getElementById("changeLocationBtn").style.background = "url(/images/_img/global/sm-whitearrow-down.gif) no-repeat right center";
        locClickFlag = true;
    }
}

//checks state of locations panel and use correct 'over' graphic for arrow
function locOverSwitch() {
    if (locClickFlag) {
        document.getElementById("changeLocationBtn").style.background = "url(/images/_img/global/sm-whitearrow-down.gif) no-repeat right center";
    } else {
        document.getElementById("changeLocationBtn").style.background = "url(/images/_img/global/sm-whitearrow-up.gif) no-repeat right center";
    }
}

//checks state of locations panel and uses correct 'out' graphic for arrow
function locOutSwitch() {
    if (locClickFlag) {
        document.getElementById("changeLocationBtn").style.background = "url(/images/_img/global/sm-blackarrow-down.gif) no-repeat right center";
    } else {
        document.getElementById("changeLocationBtn").style.background = "url(/images/_img/global/sm-blackarrow-up.gif) no-repeat right center";
    }
}


function addLocToggleEvent() {
    var campusMenuVar = new Fx.Slide('campusMenu');

    //set initial state to in
    document.getElementById("campusMenu").style.display = "block";
    campusMenuVar.hide();

    $('changeLocationBtn').addEvent('click', function(e) {
        e.stop();
        campusMenuVar.toggle();
        //locClickSwitch();
    });

}

/*
**********************************************
**** BEGIN Media Center new window
**********************************************
*/
var mediaWindow;
function openMediaWindow(theURL, winName, features) { //v2.0

    if (!mediaWindow || mediaWindow.closed) {
        mediaWindow = window.open(theURL, winName, features);
    } else {
        mediaWindow.focus();
        mediaWindow = window.open(theURL, winName, features);
    }

}

/*
**********************************************
**** Utilities/Misc
**********************************************
*/

function getRealPos(el, sProp) {
    var iPos = 0;
    while (el) {
        iPos += el["offset" + sProp];
        el = el.offsetParent;
    }

    return iPos;
}

function blockClick(whichLocation) {
    alert('hello!');
}

function blockOver(whichBlock) {
    //alert(this);
    whichBlock.style.cursor = 'pointer';
}