﻿/***********************
*   UNIVERSAL    *******
***********************/
function GetElement(id) {
    if (document.getElementById) {
        return document.getElementById(id);
    }
    else if (document.all) {
        return document.all[id];
    }
    else {
        return document.layers[id];
    }
}

function TogglePopup(strPopupID) {
    var divPopup = GetElement(strPopupID);
    if (divPopup != null) {
        var strPopupStatus = divPopup.style.display;

        // toggle the popup based on what it was coming into this function
        if (strPopupStatus == "block")
            divPopup.style.display = "none";
        else
            divPopup.style.display = "block";
    }
}


/***********************
*   SUB MENUS    *******
***********************/
$(document).ready(function() {

    // get current active code for image replacement
    var strULID = $("#pnav").children("li.CMSListMenuHighlightedLI").children("ul").attr("id");
    var strCode = $("#page").attr("class");

    // set the initial sub menu to display
    $("ul#" + strULID).css("left", GetSubMenu($("ul#" + strULID).attr("id")));
    $("ul#" + strULID).show();


    // this is for the primary LIs
    $("#pnav").children("li").hover(
        function(event) { /* HOVER ON */

            if (strCode == "idx") {
                // it's the index page, so we only show descriptions
                var strCurrentCode = GetCode($(this).children("ul").attr("id"));
                var strSubNavDescDivID = "div#subnavdesc-" + strCurrentCode;
                $(strSubNavDescDivID).show();
                $(strSubNavDescDivID).css("left", GetSubMenu($(this).children("ul").attr("id")));

                if (strCurrentCode == "tgs" || strCurrentCode == "mts" || strCurrentCode == "qsa") {
                    // let's also change the background image property
                    $("#page." + strCode + " #page-container").css("background-image", "url(/images/sections/bg-page-sub-landing-" + strCurrentCode + ".jpg)");
                }
            }
            else {
                // let's first hide the active menu
                //$("ul#" + strULID).hide();

                // show sub menu for selected navigation
                //$(this).children("ul").show();
                //$(this).children("ul").css("left", GetSubMenu($(this).children("ul").attr("id")));
            }

            // replace pnav image with it's on state and set background to be highlighted
            $(this).children("a").children("img").attr("src", $(this).children("a").children("img").attr("src").replace(strCode + "-off", "on"));
            $(this).children("a").toggleClass("CMSListMenuLinkHighlighted", true);

        },
        function(event) { /* HOVER OFF */

            var strCurrentCode = GetCode($(this).children("ul").attr("id"));

            if (strCode == "idx") {
                // hide sub descriptions
                var strSubNavDescDivID = "div#subnavdesc-" + GetCode($(this).children("ul").attr("id"));
                $(strSubNavDescDivID).hide();

                if (strCurrentCode == "tgs" || strCurrentCode == "mts" || strCurrentCode == "qsa") {
                    // let's also change the background image property back to index
                    $("#page." + strCode + " #page-container").css("background-image", "url(/images/sections/bg-page-idx.jpg)");
                }
            }

            // only switch back to the off state if we aren't in that nav
            if ($(this).attr("class").indexOf("CMSListMenuHighlightedLI") < 0) {
                // hide menu
                //$(this).children("ul").hide();

                $(this).children("a").toggleClass("CMSListMenuLinkHighlighted", false);
                $(this).children("a").children("img").attr("src", $(this).children("a").children("img").attr("src").replace("on", strCode + "-off"));

                //$("ul#" + strULID).show();

            }
        });

    // this is for the active ULs
    $("#pnav li ul").hover(
        function(event) { /* HOVER ON */

            $("ul#" + strULID).hide();

            // show menu
            $(this).show();
            $(this).css("left", GetSubMenu($(this).attr("id")));

            // switch out image
            $(this).parent().children("a").children("img").attr("src", $(this).parent().children("a").children("img").attr("src").replace(strCode + "-off", "on"));

            $(this).children("a").toggleClass("CMSListMenuLinkHighlighted", true);

        },
        function(event) { /* HOVER OFF */

            // only switch back to the off state if we aren't in that nav
            if ($(this).parent().attr("class").indexOf("CMSListMenuHighlightedLI") < 0) {
                // hide menu
                $(this).hide();

                //$(this).parent().children("a").children("img").attr("src", $(this).parent().children("a").children("img").attr("src").replace("on", strCode + "-off"));
                $(this).parent().children("a").toggleClass("CMSListMenuLinkHighlighted", false);

                $("ul#" + strULID).show();
            }
        });
});




function GetSubMenu(strSubMenuID) {

    var bIsIE6 = (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) && (navigator.userAgent.toLowerCase().indexOf('msie 7') == -1)
    switch (strSubMenuID) {
        case "pnav_UL_1":
            return (bIsIE6) ? "-696px" : "0px";
            break;
        case "pnav_UL_2":
            return (bIsIE6) ? "-596px" : "-90px";
            break;
        case "pnav_UL_3":
            return (bIsIE6) ? "-570px" : "-160px";
            break;
        case "pnav_UL_4":
            return (bIsIE6) ? "-360px" : "-50px";
            break;
        case "pnav_UL_5":
            return (bIsIE6) ? "-547px" : "-400px";
            break;
        default:
            return "0";
            break;
    }
}

function GetCode(strSubMenuID) {
    switch (strSubMenuID) {
        case "pnav_UL_1":
            return "tgs";
            break;
        case "pnav_UL_2":
            return "mts";
            break;
        case "pnav_UL_3":
            return "qsa";
            break;
        case "pnav_UL_4":
            return "crt";
            break;
        case "pnav_UL_5":
            return "cpi";
            break;
        default:
            return "idx";
            break;
    }
}

var strOrg1, strOrg2, strOrg3, strOrg4, strOrg5;
function Roll(obj, strOrgSrc, status) {
    if (obj != null) {
    
        // let's find out what section this incoming image needs to highlight.
        if (status == "on") {
            var strCodeID;
            if (obj.src.indexOf("-1-") > -1) {
                strCodeID = "1";
                strOrg1 = strOrgSrc;
            }
            else if (obj.src.indexOf("-2-") > -1) {
                strCodeID = "2";
                strOrg2 = strOrgSrc;
            }
            else if (obj.src.indexOf("-3-") > -1) {
                strCodeID = "3";
                strOrg3 = strOrgSrc;
            }
            else if (obj.src.indexOf("-4-") > -1) {
                strCodeID = "4";
                strOrg4 = strOrgSrc;
            }
            else if (obj.src.indexOf("-5-") > -1) {
                strCodeID = "5";
                strOrg5 = strOrgSrc;
            }

            //alert(strOrgSrc);


            obj.src = "/images/nav/nav-" + strCodeID + "-on.gif";
        }
        else {
            if (obj.src.indexOf("-1-") > -1) {
                obj.src = strOrg1;
            }
            else if (obj.src.indexOf("-2-") > -1) {
                obj.src = strOrg2;
            }
            else if (obj.src.indexOf("-3-") > -1) {
                obj.src = strOrg3;
            }
            else if (obj.src.indexOf("-4-") > -1) {
                obj.src = strOrg4;
            }
            else if (obj.src.indexOf("-5-") > -1) {
                obj.src = strOrg5;
            }

        }
    }
}

/*********************
* LOCATION MAPPING ***
*********************/
function ShowGalleryImage(strMainImageID, strAddressID, strMainImageSource, strClickedElement, strAddressList, strLinkList) {

    //Update the Main Image
    var objMainImage = GetElement(strMainImageID);
    objMainImage.src = strMainImageSource;

    // set the a tag to display the "on" state
    var objClicked = GetElement(strClickedElement);
    objClicked.className = "on";
    
    // set the address to be visible
    var objAddress = GetElement(strAddressID);
    objAddress.style.display = "block";

    // set other addresses to be invisible
    HideAddresses(strAddressList);

    ResetLinks(strLinkList);

}

function ResetLinks(strLinkIDs) {

    var arrAddressesIDs = strLinkIDs.split(",");
    var iIndex = 0;

    for (iIndex = 0; iIndex < arrAddressesIDs.length; iIndex++) {
    
        // loop through given list and make each element invisible
        GetElement(arrAddressesIDs[iIndex]).className = "off";
    }
}

function HideAddresses(strAddressIDs) {

    var arrAddressesIDs = strAddressIDs.split(",");
    var iIndex = 0;

    for (iIndex = 0; iIndex < arrAddressesIDs.length; iIndex++) {

        // loop through given list and make each element invisible
        GetElement(arrAddressesIDs[iIndex]).style.display = "none";
    }
}

/* this function is called by flash (about-history-timeline) */
function hideLargePhoto(action) {
    $(document).ready(function() {
        $("divAboutTimelineImage").hide();
    });
}

function setLargePhoto(strImage) {
    $(document).ready(function() {
        $("divAboutTimelineImage").show();
        $("divAboutTimelineImage").children("img").attr("src", "/flash/timeline/" + strImage);
    });
}

/***********************
*   PROMOTIONS *********
***********************/

// these are the variables needed to control the promo area
var iCurrentXPos = 0;
var iCurrentPromo = 1;

// initialize settings
$.scrollTo.defaults.axis = 'x';

//this one is important, many browsers don't reset scroll on refreshes
//$("promo-listing").scrollTo(0); //reset all scrollable panes to (0,0)
//$.scrollTo(0); //reset the screen to (0,0)

$(document).ready(function() {
    $("#btn-next-promo").click(function(event) {
        event.preventDefault();

        // reset promos if at last one
        if (iCurrentPromo == iTotalPromos) {
            iCurrentPromo = 1;
            iCurrentXPos = 0;

            // move!
            $("#promo-listing-inner").scrollTo(iCurrentXPos + "px", 900);
        }
        else {
            // increment counters
            iCurrentXPos += iPromoWidth;
            iCurrentPromo++;

            // move!
            $("#promo-listing-inner").scrollTo(iCurrentXPos + "px", 800);
        }
    });

    // set the promo areas to be bottom left 
    var iFtrHeight = $("#page-ftr").position();

    var iPromoTop = Math.ceil(iFtrHeight.top) - 304;
    $("div.promo-listing-index").css("top", iPromoTop + "px");

    iPromoTop = Math.ceil(iFtrHeight.top) - 292;
    $("div.promo-listing-salon").css("top", iPromoTop + "px");

    iPromoTop = Math.ceil(iFtrHeight.top) - 292;
    $("div.promo-listing-inc").css("top", iPromoTop + "px");
});

/* Web Booking Repeater Scroller
 *
 *
 *
 *
*/
var iCurrentYPos = 0;            

$(document).ready(function()
{
   $("#btn-arrow-down").click(function(event)
   {
        $.scrollTo.defaults.axis = 'y';
        event.preventDefault();
        
        iCurrentYPos += 390;
        
        $("#web-booking-avail").scrollTo(iCurrentYPos + "px", 900);
        //$(this).hide("slow");
        //$("div.web-booking-available").css("height", "384px");
   });
   $("#btn-arrow-up").click(function(event)
   {
        $.scrollTo.defaults.axis = 'y';
        event.preventDefault();
        
        iCurrentYPos -= 390;
        if (iCurrentYPos < 0)
        {
            iCurrentYPos = 0;
        }
        
        $("#web-booking-avail").scrollTo(iCurrentYPos + "px", 900);
        //$(this).hide("slow");
        //$("div.web-booking-available").css("height", "384px");
   });
});

/***********************
*   PHOTO GALLERY*******
***********************/
var strCurrentPhoto = "";
$(document).ready(function() {
    $("div.photo-gallery-wrapper").hide();

    $("#dub-gal").click(function(event) {
        event.preventDefault();
        $("div.photo-gallery-wrapper").hide();
        $(this).parent().siblings("div.photo-gallery-wrapper").show();
    });

    $("#gah-gal").click(function(event) {
        event.preventDefault();
        $("div.photo-gallery-wrapper").hide();
        $(this).parent().siblings("div.photo-gallery-wrapper").show();
    });

    $("#pol-gal").click(function(event) {
        event.preventDefault();
        $("div.photo-gallery-wrapper").hide();
        $(this).parent().siblings("div.photo-gallery-wrapper").show();
    });

    $("#gv-gal").click(function(event) {
        event.preventDefault();
        $("div.photo-gallery-wrapper").hide();
        $(this).parent().siblings("div.photo-gallery-wrapper").show();
    });

    $("#sn-gal").click(function(event) {
        event.preventDefault();
        $("div.photo-gallery-wrapper").hide();
        $(this).parent().siblings("div.photo-gallery-wrapper").show();
    });

    $("#qsa-gal").click(function(event) {
        event.preventDefault();
        $("div.photo-gallery-wrapper").hide();
        $(this).parent().siblings("div.photo-gallery-wrapper").show();
    });

    $("img.gallery-thumb").mouseover(function(event) { $(this).attr("src", $(this).attr("src").replace("-off").replace("-on")); });
});


/***********************
*   LOCATIONS    *******
***********************/
$(document).ready(function() {
    $("div.location-entry-preview a").click(function(event) {
        event.preventDefault();

        var bIsShowing = $(this).hasClass("on");
        if (bIsShowing) {
            // user clicked on a link that was showing its extended info.  let's hide it now
            $(this).parent().parent().parent().parent().children("div.location-entry-extended").slideUp(500);
            $(this).addClass("off");
            $(this).removeClass("on");
            // set the links display to off
            //$(this).parent().parent().parent().toggleClass("on", false);
        }
        else {
            // hide all extenders
            $("div.location-entry-extended").hide();
            $(this).addClass("on");
            $(this).removeClass("off");

            // get the extended control and show it
            $(this).parent().parent().parent().parent().children("div.location-entry-extended").slideDown(800);
        }

    });
});


/***********************
*   AWARDS/PRESS *******
***********************/
$(document).ready(function() {
    $("a.continue-reading").click(function(event) {
        event.preventDefault();

        $("a.continue-reading").toggleClass("on", false);
        // open up the continue reading
        $(this).toggleClass("on", true);
        $(this).parent().children("div.long-desc").toggle(800);

    });
});

/***********************
*   CREATIVE BIOS ******
***********************/
$(document).ready(function() {
$("a.view-bios").click(function(event) {
        event.preventDefault();

        //$("a.view-bios").toggleClass("on", false);
        // open up the continue reading
        $(this).toggleClass("on", true);
        $(this).parent().parent().parent().children("div.team-members").toggle(800);

    });
});

/***********************
*   GIFT CARDS    ******
***********************/
$(document).ready(function() {
    $("a.GiftCardDown").click(function(event) {
        event.preventDefault();

        // convert value to number and decrease
        var strValue = parseFloat($(".tbGiftCardValue").val());

        // reset value if under 0
        if (strValue <= 0)
            $(".tbGiftCardValue").val(0);
        else {
            // check to see if it's multiple of 5
            if (strValue % 5 == 0)
                $(".tbGiftCardValue").val(strValue - 5);
            else {
                strValue = strValue - (strValue % 5);
                $(".tbGiftCardValue").val(strValue);
            }
        }
    });

    $("a.GiftCardUp").click(function(event) {
        event.preventDefault();

        // convert value to number and decrease
        var strValue = parseFloat($(".tbGiftCardValue").val());

        // reset value if under 0
        if (strValue < 0)
            $(".tbGiftCardValue").val(0);
        else
            $(".tbGiftCardValue").val(strValue + 5);
    });
});

function Count(tbMessage, iMaxLength, strMessageCount) {

    // get incoming max length and convert to number
    var maxlength = new Number(iMaxLength);
    
    // compare size of textbox with max length and update
    if (tbMessage.value.length > iMaxLength) {

        // if the message goes over (copy & paste) we will only show first 60 chars
        tbMessage.value = tbMessage.value.substring(0, iMaxLength);
    }

    // set the label we have to show
    GetElement(strMessageCount).innerHTML = tbMessage.value.length;
}

function RoundToNearestFive(tbValue) {

    // make sure that the value is an increment of 5
    var iValue = parseFloat($(".tbGiftCardValue").val());

    if (tbValue.value < 0)
        tbValue.value = 0;
    else
        tbValue.value = iValue - (iValue % 5);
}


/***********************
*   SEARCH QUERY  ******
***********************/
// sets the search box to default text when unfocused
function SetSearchBoxTextFocus(tbSearch) {
    if (tbSearch.value == "search service or keyword")
        tbSearch.value = "";
}

function SetSearchBoxTextUnFocus(tbSearch) {
    if (tbSearch.value == "")
        tbSearch.value = "search service or keyword";
}

function openJobApplicationWindow() {

    var url = "/job-app.aspx?type=test";    
    window.open(url, "CharlesPenzoneEmploymentApplication", "width=763,scrollbars=1,resizable=0,location=0");
}


/***********************
** Social Media Popup **
***********************/
$(document).ready(function() {

$("#fb-tw-container").hide();

$("#fb-tw-btn").click(function(event)
   {
      event.preventDefault();
       // set the promo areas to be bottom left 

    var iFbBtnHeight = $(this).position();
// this is the top position of the image link you just clicked

    var iPromoTop = Math.ceil(iFbBtnHeight.top) - 154;
    var iPromoLeft = Math.ceil(iFbBtnHeight.left) - 165;
    $("#fb-tw-container").css("top", iPromoTop + "px");
    $("#fb-tw-container").css("left", iPromoLeft + "px");
    $("#fb-tw-container").show();

   });

$("#fb-tw-btn-close").click(function(event)

   {
      event.preventDefault();
    $("#fb-tw-container").hide();

   });
});

