﻿/// <reference path="jquery-1.5.min.js" />
/// <reference path="jquery-blockUI.js" />

var settings = {
    tl: { radius: 17 },
    tr: { radius: 17 },
    bl: { radius: 17 },
    br: { radius: 17 },
    antiAlias: true
}

var barwidth = 0;

$(function () {
    var footerboxes = $(".footerboxtext");
    var maxfooterheight = 0;
    for (var f = 0; f < footerboxes.length; f++) {
        if ($(footerboxes[f]).height() > maxfooterheight)
            maxfooterheight = $(footerboxes[f]).height();
    }
    $(".footerbox").height(maxfooterheight + 10);
    $(".footerboxes").height(maxfooterheight + 55);
    $(".footer").height(maxfooterheight + 95);

    $(".navigationIcon").hover(
        function () {
            var cl = this.className;
            $(this).addClass(cl.replace("-Off", "-On"));
            $(this).removeClass(cl.replace("-On", "-Off"));
        },
        function () {
            var cl = this.className;
            $(this).addClass(cl.replace("-On", "-Off"));
            $(this).removeClass(cl.replace("-Off", "-On"));
        }
    );

    $(".arrowButton").hover(
            function () {
                $(this).addClass("arrowButton-hover");
            },
            function () {
                $(this).removeClass("arrowButton-hover");
            }
    );

    $(".surveyVoteButton").hover(
            function () {
                $(this).addClass("surveyVoteButton-hover");
            },
            function () {
                $(this).removeClass("surveyVoteButton-hover");
            }
    );

    $(".emailButton").hover(
        function () {
            $(this).addClass("emailButton-hover");
        },
        function () {
            $(this).removeClass("emailButton-hover");
        }
    );

    $(".topButton").hover(
        function () {
            $(this).addClass("topButton-hover");
        },
        function () {
            $(this).removeClass("topButton-hover");
        }
    );

    $('#jsddm > li').bind('mouseover', jsddm_open);
    $('#jsddm > li').bind('mouseout', jsddm_timer);
    $('.submenucontainer').bind('mouseover', showsubmenu);
    //$('.submenucontainer > *').bind('mouseout', submenu_timer);

    expandVerticalBar();

    $(".reset").hover(
            function () {
                $(this).addClass("reset-on");
                $(this).removeClass("reset-off");
            },
            function () {
                $(this).addClass("reset-off");
                $(this).removeClass("reset-on");
            }
    );

    $(".send").hover(
            function () {
                $(this).addClass("send-on");
                $(this).removeClass("send-off");
            },
            function () {
                $(this).addClass("send-off");
                $(this).removeClass("send-on");
            }
    );

    (function ($) {
        $.fn.customFadeIn = function (callback) {
            $(this).stop().animate({ opacity: 1 }, 500, function () {
                if (jQuery.browser.msie)
                    $(this).get(0).style.removeAttribute('filter');
                if (callback != undefined)
                    callback();
            });
        };
        $.fn.customFadeOut = function (callback) {
            $(this).animate({ opacity: 0 }, 500, function () {
                if (jQuery.browser.msie)
                    $(this).get(0).style.removeAttribute('filter');
                if (callback != undefined)
                    callback();
            });
        };
    })(jQuery);

    $(".ImageMapContainer span.ImageMapLink img").hover(function () {
        var imagePath = $(this).attr("src");
        var lastSlash = imagePath.lastIndexOf("/");
        var imageDirectory = imagePath.substring(0, lastSlash + 1);
        var imageFilename = imagePath.substring(lastSlash + 1);
        $(this).attr("off_src", $(this).attr("src"));
        $(this).attr("src", $(this).attr("hover_src"));
    },
    function () {
        $(this).attr("src", $(this).attr("off_src"));
    });

    $(".ImageMapContainer span.LandingMapText").hover(function () {
        var imagePath = $(this).parent().find("img").attr("src");
        var lastSlash = imagePath.lastIndexOf("/");
        var imageDirectory = imagePath.substring(0, lastSlash + 1);
        var imageFilename = imagePath.substring(lastSlash + 1);
        $(this).parent().find("img").attr("src", imageDirectory + "h-" + imageFilename);
    },
    function () {
        $(this).parent().find("img").attr("src", $(this).parent().find("img").attr("src").replace("h-", ""));
    });

    $("table#ImageMapTable tr td img.ImageMapLink").hover(function () {
        var imagePath = $(this).attr("src");
        var lastSlash = imagePath.lastIndexOf("/");
        var imageDirectory = imagePath.substring(0, lastSlash + 1);
        var imageFilename = imagePath.substring(lastSlash + 1);
        $(this).attr("src", imageDirectory + "h-" + imageFilename);
    },
    function () {
        $(this).attr("src", $(this).attr("src").replace("h-", ""));
    });


    setDropdownBehavior("#countriesDropdown");
    setDropdownBehavior("#citiesDropdown");
    setDropdownBehavior("#staffDropdown");
    setTextBoxBehavior("#FirstName", rm["First Name"]);
    setTextBoxBehavior("#LastName", rm["Last Name"]);
    setTextBoxBehavior("#Email", rm["Email"]);
    setTextBoxBehavior("#ConfirmEmail", rm["Confirm Email"]);

    $("input[name='AnswerId']").imageTick({
        tick_image_path: "/Content/Images/radio_selected-15.png",
        no_tick_image_path: "/Content/Images/radio-15.png",
        image_tick_class: "surveyRadios"
    });

    var imageMapBubbleTitle = $(".ImageMapBubbleTitle");
    var imageMapBubbleHeight = $(".ImageMapBubble").height();
    //$(".main").css("height", imageMapBubbleHeight);
    for (var i = 0; i < imageMapBubbleTitle.length; i++) {
        $(imageMapBubbleTitle[i]).css("top", (imageMapBubbleHeight - $(imageMapBubbleTitle[i]).height()) / 2);
    }

});

function setMeter(pct,id) {
    $("#surveyResponses" + id).css("width", barwidth * (pct / 100) + "px");
}  

function hoverize(i,isOn) {  
    if (!isOn) {
        var imagePath = $(i).attr("src");
        var lastSlash = imagePath.lastIndexOf("/");
        var imageDirectory = imagePath.substring(0, lastSlash + 1);
        var imageFilename = imagePath.substring(lastSlash + 1);  
        $(i).attr("src", imageDirectory + "h-" + imageFilename);
    }
    else {
        $(i).attr("src", $(i).attr("src").replace("h-", ""));  
    }
}

function CaptchaClick(id,code) {
    for (var i = 1; i <= 3; i++) {
        var src = $("#Captcha" + i).attr("src");
        $("#Captcha" + i).attr("src", src.toString().replace("h-", ""));
    }

    $("#Captcha").val(code);
    var o = $("#Captcha" + id);    
    hoverize(o,$(o).attr("src").indexOf("h-") > -1);           
}

function printPage() {
    window.print();
}

function emailPage() {
    alert("TBD");
}

function expandVerticalBar() {
    $("html").find(".verticalBar").height($(".main").height() - 15);
}

function setTextBoxBehavior(textboxId, fieldtext) {    
    $(textboxId).blur(function () {
        if ($(textboxId).val() == "") $(textboxId).val(fieldtext);
    });
    $(textboxId).focus(function () {
        if ($(textboxId).val() == fieldtext) $(textboxId).val("");
    });

    $(textboxId).blur();
}


function setDropdownBehavior(dropdownId) {
    $(dropdownId + " dt a").click(function () {
        if ($(dropdownId + " dd ul").css("display") != "block") {
            $(dropdownId + " dd ul").fadeIn("normal");
        }
        else {
            $(dropdownId + " dd ul").fadeOut("normal");
        }
    });
    $(dropdownId + " dd ul li a").click(function () {
        $(dropdownId + " dd ul").hide();
    });
    $(document).bind('click', function (e) {
        var $clicked = $(e.target);
        if ((!$clicked.parents().hasClass("dropdown") && !$clicked.parents().hasClass("dropdownLarge")) && $(dropdownId + " dd ul").css("display") == "block")
            $(dropdownId + " dd ul").fadeOut("normal");
    });
    var divObj = $(dropdownId + " .dropdownUL");
    if (divObj != null) {
        for (var i = 0; i < divObj.length; i++) {
            curvyCorners(settings, divObj[i]);
        }
    }

    var captchaObj = $(".Captcha")[0];
    if (captchaObj != null) {
        curvyCorners(settings, captchaObj);
    }

    var bubbleObj = $(".ImageMapDetailsBubble");
    if (bubbleObj != null) {
        for (var ib = 0; ib < bubbleObj.length; ib++) {
            curvyCorners(settings, bubbleObj[ib]);
        }
    }
}

function menuSelected(page) {
    if (page == "Home")
        $($("#menu li")[0]).addClass("selected");
    else
        $("#menu li a[href$='" + page + "']").parent().addClass("selected");
}

function showsubmenu() {
    $(".submenucontainer").slideDown("normal");
    jsddm_open();
}

function hidesubmenu() {
    $(".submenucontainer").slideUp("normal");
    jsddm_timer();
}

function submenuSelected(id) {
    var submenuArray = $("#submenu li");
    for (var i = 0; i < submenuArray.length; i++) {
        $(submenuArray[i]).removeClass("selected");
    }
    $(submenuArray[id - 1]).addClass("selected");
    return false;
}

function GetData(url, callfront, callback, id) {
    callfront.call(this, id, function () {
        $.ajax({ url: url + '?jsoncallback=' + callback + '', dataType: "script" });
    });
    return false;
}

function GetData2(url, callfront, callback, id) {
    callfront.call(this, id, function () {
        $.ajax(url, {
            dataType: "html", 
            success: function (data, textStatus, jqXHR) {
                callback(data);
            } 
        });
    });
    return false;
}

/* Executive Contact Us */
function ContactUs_ExecutiveCallfront(id, onComplete) {
    $(".ContactUsDetails").fadeOut("normal", onComplete);
}

function ContactUs_ExecutiveCallback(data) {
    $(".ContactUsDetails").html(data);
    $(".ContactUsDetails").fadeIn("normal");
    $(".ContactUsDetails").show();
}

/* Executive Contact Us */

/* Our Team */
function OurTeam(url, callfront, callback, id) {
    GetData2(url, callfront, callback, id);
    GetData2(url.replace("GetStaffByLocation", "GetStaffDropdown"), OurTeamStaffDropdownCallfront, OurTeamStaffDropdownCallback, id);
    return false;
}

function OurTeamCallfront(id, onComplete) {
    $("#citiesDT").html(id);
    var selectedItem = $("#citiesDropdown dd ul li:contains('" + id + "')").clone();
    $("#citiesDropdown dd ul li:contains('" + id + "')").remove();
    $("#citiesDropdown dd ul .autoPadDiv").prepend(selectedItem);
    $("#citiesDropdown dd ul").hide();
    $(".midContent").fadeOut("normal", onComplete);
}

function OurTeamCallback(data) {    
    $(".midContent").html(data);
    $(".midContent").fadeIn("normal");
    $(".midContent").show();
}

function OurTeamStaffDropdownCallfront(id, onComplete) {
    $("#topDropDownLargeRight").fadeOut("normal", onComplete);
}

function OurTeamStaffDropdownCallback(data) {
    $("#topDropDownLargeRight").html(data);    
    $("#topDropDownLargeRight").fadeIn("normal");
    $("#topDropDownLargeRight").show();
    setDropdownBehavior("#staffDropdown");
}
/* Our Team */

/* ContactUs */
function ContactUsCallfront(id, onComplete) {
    $("#citiesDT").html(id);
    var selectedItem = $("#citiesDropdown dd ul li:contains('" + id + "')").clone();
    $("#citiesDropdown dd ul li:contains('" + id + "')").remove();
    $("#citiesDropdown dd ul .autoPadDiv").prepend(selectedItem);
    $("#citiesDropdown dd ul").hide();
    $(".LocationData").slideUp("normal", onComplete);            
}

function ContactUsCountriesCallfront(id, onComplete) {
    $("#countriesDT").html(id);
    var selectedItem = $("#countriesDropdown dd ul li:contains('" + id + "')").clone();
    $("#countriesDropdown dd ul li:contains('" + id + "')").remove();
    $("#countriesDropdown dd ul .autoPadDiv").prepend(selectedItem);
    $("#countriesDropdown dd ul").hide();
    $("#citiesDropdown").fadeOut("normal", onComplete);
}

function ContactUsCountriesCallback(result) {    
    citiesHtml = "<dt><a href=\"javascript:void(0);\" id=\"citiesDT\">"+result.Cities[0].Name+"</a></dt><dd><ul class=\"dropdownUL\">";
    for (var i = 0; i < result.Cities.length; i++) {        
        citiesHtml += "<li><a href='" + GetCitiesAction.replace("0/0", result.Cities[i].LocationId + "/" + result.Cities[i].CountryId) + "' onclick=\"return GetData2('" + GetCitiesAction.replace("0/0", result.Cities[i].LocationId + "/" + result.Cities[i].CountryId) + "',ContactUsCallfront,ContactUsCallback,'" + result.Cities[i].Name + "')\">" + result.Cities[i].Name + "</a></li>";        
    }
    citiesHtml += "</ul></dd>";
    $("#citiesDropdown").html(citiesHtml);
    $("#citiesDropdown").fadeIn("normal", function () {
        setDropdownBehavior("#citiesDropdown");
        // Refresh list with current city at the top of new country list
        return GetData2(GetCitiesAction.replace("0/0", result.Cities[0].LocationId + "/" + result.Cities[0].CountryId), ContactUsCallfront, ContactUsCallback, result.Cities[0].Name);        
    });
}

function ContactUsCallback(result) {
    $(".LocationData").html(result);
    $(".LocationData").slideDown("normal");    
    $(".LocationData").show();  
}
/* ContactUs */

/* Practices */
function MainCallfront(id, onComplete) {
    ShowImageMap(false, function () {
        onComplete();
    });
    GetData2(crumbreload + "/" + id, CrumbCallfront, CrumbCallback, id);
}

function BreadCrumbHideImageMap() {
    GetData2(crumbreload + "/-1", CrumbCallfront, CrumbCallback, -1);
    ShowImageMap(true);    
    return false;
}

function GetPracticesCallback(result) {
    $(".detailContent").html(result);
    $(".detailContent").show();
    $(".detailContent").fadeIn("slow");    
    //$(".detailContent").animate({ marginLeft: parseInt($(".detailContent").css('marginLeft'), 10) == 0 ? $(".detailContent").outerWidth() : 0 }, 'slow');
}

function ShowImageMap(isShown, callback) {
    if (isShown) {
        //$(".detailContent").animate({ marginLeft: parseInt($(".detailContent").css('marginLeft'), 10) == 0 ? $(".detailContent").outerWidth() : 0 }, 'slow', function () {
        $(".detailContent").fadeOut("slow", function() {
            $(".ImageMapContainer").show();
            $(".detailContent").hide();
            //$(".ImageMapContainer").animate({ left: parseInt($(".ImageMapContainer").css('left'), 10) == 0 ? -$(".ImageMapContainer").outerWidth() : 0 }, 'slow', function () {                
            $(".ImageMapContainer").fadeIn("slow", function() {    
                if (callback != null) callback();
            });
        });
    }
    else {
        //$(".ImageMapContainer").animate({ left: parseInt($(".ImageMapContainer").css('left'), 10) == 0 ? -$(".ImageMapContainer").outerWidth() : 0 }, 'slow', function () {
        $(".ImageMapContainer").fadeOut("slow", function() {
            $(".ImageMapContainer").hide();
            if (callback != null) callback();
        });
    }
    return false;
}

/* Practices */

function CrumbCallfront(id, onComplete) {
    onComplete();
}

function CrumbCallback(result) {
    $(".breadcrumb").html(result);
}

function expandList(i) {   
    var p = $("#pageList" + i);
    var pt = $("#pageList" + i + "-Text");
    if ($(p).hasClass("expanded")) {
        $(p).removeClass("expanded");
        $(p).addClass("unexpanded");
        $(pt).slideUp("fast", function () {
            expandVerticalBar();
        });
    }
    else {
        $(p).addClass("expanded");
        $(p).removeClass("unexpanded");
        $(pt).slideDown("fast", function () {
            expandVerticalBar();
        });
    }
}

var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open() {
    jsddm_canceltimer();
    jsddm_close();
    ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');
    $(this).children("a").addClass('jsddm_top_on');
    $(this).children("a").removeClass('jsddm_top_off');
}

function jsddm_close() {
    if (ddmenuitem) {
        ddmenuitem.css('visibility', 'hidden');
        ddmenuitem.parent().children("a").addClass('jsddm_top_off');
        ddmenuitem.parent().children("a").removeClass('jsddm_top_on');
    }
}

function jsddm_timer() {
    closetimer = window.setTimeout(jsddm_close, timeout);
}

function submenu_timer() {
    closetimer = window.setTimeout(submenu_close, timeout);
}

function submenu_close() {
    hidesubmenu();
}

function jsddm_canceltimer() {
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}

function jsddm_sub_hover() {

}

document.onclick = jsddm_close;

function contactUsSubmit() {
    $("#form1").submit();
}

function submitSurvey(url, responsesUrl) {    
    $.ajax({
        type: 'POST',
        url: url,
        data: "AnswerId=" + $("input[name='AnswerId']:checked").val() + "&QuestionId=" + $("#QuestionId").val(),
        callback: showSurveyResponses(responsesUrl)
    });
    return false;
}

function showSurveyResponses(url) {
    $(".surveyBox").load(url);
}
