﻿/// <reference path="jquery-1.2.6.js" />
/// <reference path="inPractice-utilities.js" />

function ccoRoot(params) {
    this.contentId = $("head").find("meta[name=guid]").attr("content");
    this.interstitials = new ccoInterstitials(this.contentId, params.showInterstitial, params.interstitial);
    supporterSlideshow();
}

function ccoInterstitials(contentId, show, interstitial) {
    if (show) {
        var modal = $('#modalDialog');
        $('#modalDialogHeader').css({ visibility: "hidden" });
        modal.jqm({
            modal: true,
            onShow: function(h) {
                /* callback executed when a trigger click. Show notice */
                h.w.css('opacity', .96).slideDown();
            },
            onHide: function(h) {
                /* callback executed on window hide. Hide notice, overlay. */
                h.w.slideUp("slow", function() { if (h.o) h.o.remove(); });
            }
        });
        modal.html('<iframe id="int' + interstitial + '" class="intFrame" src=\"/Interstitials/' + interstitial + '.aspx?id=' + contentId + '&interstitial='+ interstitial +'\" onLoad=\'calcHeight("int' + interstitial + '");\' />');
        modal.jqmShow();


        this.close = function() {
            modal.jqmHide();
        }
    }
}

function calcHeight(iframeTitle) {
    //find the height of the internal page
    //Firefox returns incorrect scrollheight so use scrollMaxY + innerHeight to calculate height of content
    var the_height = document.getElementById(iframeTitle).contentWindow.scrollMaxY + document.getElementById(iframeTitle).contentWindow.innerHeight;
    //IE doesnt support scrollMaxY so use scrollHeight
     if (isNaN(the_height))
        the_height = document.getElementById(iframeTitle).contentWindow.document.body.scrollHeight + 5;
    //change the height of the iframe, maximum of 400 pixels for interstitial
    if (the_height > 400) the_height = 400;
    document.getElementById(iframeTitle).height = the_height;

}

function trackPage(wsURL) { $.ajax({ type: 'GET', url: wsURL }) }

function supporterSlideshow() {
    var theTimeout;
    if ($(".supporter_slideshow").children().length == 1) {
        //Fix styling when only one supporter image available
        $(".supporter_slideshow").css({ "margin-bottom": "-50px" });
        $(".supporter_slideshow").css({ "margin-left": "0px" });
    }
    else 
    {
      $(".supporter_slideshow").cycle();
    }
    $(".supporter_slideshow").css({ visibility: "visible" });
    $(".trackBoxLink a").hover(function() {
        var target = $("#trackHighlightBoxHolder");
        target.children().hide();
        var id = "#" + $(this).attr("id") + "_guts";
        $(id).show();

        if (theTimeout) { clearTimeout(theTimeout); }
        theTimeout = setTimeout(function() {
            target.children().hide();
            target.children(":first").show();
        }, 6000);
    }, function() { });
}

tipOffset = 0;
