﻿var sccgovCalendarCellSpacing = "2";

function sccgovImageCycle(id, effect, cycletime, nextid, previd, pagerid) {
    $('#' + id).cycle({
        fx: effect,
        timeout: parseInt(cycletime),
        pause: 1,
        next: '#' + nextid,
        prev: '#' + previd,
        pager: '#' + pagerid
    });
}

/*
* jQuery Backstretch
* Version 1.1.2
* http://srobbin.com/jquery-plugins/jquery-backstretch/
*
* Add a dynamically-resized background image to the page
*
* Copyright (c) 2010 Scott Robbin (srobbin.com)
* Dual licensed under the MIT and GPL licenses.
*/
(function (a) { a.backstretch = function (k, i, l) { function m(c) { try { f = { left: 0, top: 0 }; d = e.width(); b = d / j; if (b >= e.height()) { g = (b - e.height()) / 2; h.centeredY && a.extend(f, { top: "-" + g + "px" }) } else { b = e.height(); d = b * j; g = (d - e.width()) / 2; h.centeredX && a.extend(f, { left: "-" + g + "px" }) } a("#backstretch img").width(d).height(b).css(f) } catch (n) { } typeof c == "function" && c() } var h = { centeredX: true, centeredY: true, speed: 0 }, e = "onorientationchange" in window ? a(document) : a(window), j, d, b, g, f; i && typeof i == "object" && a.extend(h, i); a(document).ready(function () { if (k) { var c = a("<div />").attr("id", "backstretch").css({ left: 0, top: 0, position: "fixed", overflow: "hidden", zIndex: -9999 }), n = a("<img />").css({ position: "relative", display: "none" }).bind("load", function (o) { var p = a(this); j = a(o.target).width() / a(o.target).height(); m(function () { p.fadeIn(h.speed, function () { typeof l == "function" && l() }) }) }).appendTo(c); a("body").prepend(c); n.attr("src", k); a(window).resize(m) } }); return this } })(jQuery);

var _GET = {};
for (var m, v = location.href.split(/[?&]/), k = v.length - 1; k > 0; k--)
    _GET[(m = v[k].split(/[=#]/))[0].toLowerCase()] = m.length > 1 ? decodeURI(m[1]) : "";
if (_GET['classtitle'] != null) {
    var classTitle = _GET['classtitle'];
}
else {
    var classTitle = "";
}

function vhpLanguageDropDown() {
    if ($("#vhp_master_header_languagesdropdown_body").css("display") == "none") {
        $("#vhp_master_header_languagesdropdown_header").css("background-image", "url('" + siteCollectionRootURL + "/Style Library/SCCGOV/" + sccgovTemplateName + "/Images/" + sccgovTemplateColor + "/vhp_languages_button_header_selected.png')");
        $("#vhp_master_header_languagesdropdown_body").css("display", "block");
        $("#vhp_master_header_languagesdropdown_footer").css("display", "block");
    }
    else {
        $("#vhp_master_header_languagesdropdown_header").css("background-image", "url('" + siteCollectionRootURL + "/Style Library/SCCGOV/" + sccgovTemplateName + "/Images/" + sccgovTemplateColor + "/vhp_languages_button_header.png')");
        $("#vhp_master_header_languagesdropdown_body").css("display", "none");
        $("#vhp_master_header_languagesdropdown_footer").css("display", "none");        
    }
}

function sccgovOpenEventsCalendarLocationDirections(url, location) {
    var length = sccgovEventsCalendarLocations.locations.location.length - 1;
    for (i = 0; i <= length; i++) {
        if (sccgovEventsCalendarLocations.locations.location[i].name == location) {
            window.open(url + "?name=" + sccgovEventsCalendarLocations.locations.location[i].name + "&address=" + sccgovEventsCalendarLocations.locations.location[i].address1 + "&city=" + sccgovEventsCalendarLocations.locations.location[i].city + "&state=" + sccgovEventsCalendarLocations.locations.location[i].state + "&zip=" + sccgovEventsCalendarLocations.locations.location[i].zip);
        }
    }
}

function showDate(date) {
    var d = new Date(date);
    var monthName = monthname[d.getMonth()];
    var dayName = weekday[d.getDay()];
    var dayNumber = d.getDate();
    var year = d.getFullYear();
    var sccgovCalendarPopUpTitle = dayName + ", " + monthName + " " + dayNumber + ", " + year;
    var length = sccgovCalendarEvents.calendar.day.length - 1;
    var header = "<div class=\"sccgov_events_container\"><table cellpadding=\"8\" cellspacing=\"0\"><thead><tr><th width=\"160\">Time</th><th width=\"180\">Class/Event</th><th width=\"160\">Location</th></tr></thead><tbody>";
    var footer = "</tbody></table><div id=\"sccgov_calendar_popup_bottom\"></div>";
    var bottom = "</div>";
    var output = "";

    for (i = 0; i <= length; i++) {
        if (sccgovCalendarEvents.calendar.day[i].date == date) {
            var length2 = sccgovCalendarEvents.calendar.day[i].event.length - 1;
            for (j = 0; j <= length2; j++) {
                output += "<tr><td valign=\"top\">" + sccgovCalendarEvents.calendar.day[i].event[j].start.replace(" ", "") + " - " + sccgovCalendarEvents.calendar.day[i].event[j].end.replace(" ", "") + "</td><td valign=\"top\"><a href=\"" + sccgovCalendarEvents.calendar.day[i].event[j].url + "\">" + sccgovCalendarEvents.calendar.day[i].event[j].title + "</a></td><td valign=\"top\"><a href=\"javascript:sccgovOpenEventsCalendarLocationDirections('http://" + document.domain + "/en-us/Services/Pages/Directions.aspx" + "','" + sccgovCalendarEvents.calendar.day[i].event[j].locname + "');\">" + sccgovCalendarEvents.calendar.day[i].event[j].locname + "</a></td></tr>";
            }
        }
    }

    if (output == "") {
        sccgovModalPopup("Valley Health Plan", "<div class=\"sccgov_events_container\">", "<p>There are no classes or events scheduled for " + sccgovCalendarPopUpTitle + ".</p>", "<div id=\"sccgov_calendar_popup_bottom\"></div>", bottom, "calendar");
    }
    else {
        sccgovModalPopup(sccgovCalendarPopUpTitle, header, output, footer, bottom, "calendar");
        setExternalLinks();
    }
}

function openExternalSite(desturl)
{
    sccgovModalPopup("You Are Leaving Valley Health Plan", "<div class=\"sccgov_events_container\">", "<p>Our web pages have many links to other organizations, such as other government agencies, non-profit community based organizations, and for-profit entities. While we offer these links for your convenience in accessing the services you require, please be aware that the policies that apply to our portal may not be the same as the terms of use for other web sites. In addition, the County of Santa Clara cannot attest to the accuracy of the information provided by linked sites. The inclusion of a hypertext link to an external website is not intended as an endorsement of any product or service offered or referenced the linked websites, the organizations sponsoring linked websites, or any views that might be expressed or referenced in websites linked to from the County of Santa Clara's Official Web Portal.</p><p><a href=\"" + desturl + "\" target=\"_blank\">Continue to external website</a></p>", "<div id=\"sccgov_calendar_popup_bottom\"></div>", "</div>","","double");
}

function vhpShowRibbon() {
    document.getElementById("s4-ribbonrow").style.display = "block";
}

function vhpContainer() {
    $('#vhp_top').css('visibility', 'visible');
    $('#vhp_container').css('visibility', 'visible');
    $('#vhp_bottom').css('visibility', 'visible');
}

$(document).ready(function () {
    sccgovSetExternalLinks();
});
