﻿String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, "");
}
//include after debugWorkaround generated
function DisplayBrochure(fpid) {
    window.open('Brochure.aspx?fpid='+fpid,'FloorPlanModel','menubar=no,location=no,toolbar=no,resizable=no,scrollbars=1,status=no,width=840,height=900,left=100,top=10');
}

function OnClientClose(oWnd) {
    oWnd.GetContentFrame().src = "about:blank";
}
function SetHash(pageName) {
    window.location.hash = '#' + pageName;
}
function GetHash() {
    if (window.location.hash.length > 0)
        return window.location.hash.substring(1);
    else
        return "";
}


function getFlashMovie(appName) {
    //This is some deep magic meant to handle cross browser scenarios.
    //Works in Chrome, Firefox and IE7.
    //No idea about 6 or 8.
    return document[appName] || document.getElementById(appName) || window[appName]; 
}

//calculate app root based on image gauranteed to be positioned correctly.
function baseURL() {
    var url = $("#magicalBlankImage img").attr("src");
    url = url.substr(0, url.lastIndexOf("/")+1) + "../";
    return url; //url;
}
function DoFontToFlashReplace(pattern,font,size) {
    function makeFlashVars(text, font, size) {
        if (!(font == "Gill" || font == "Hand")) {
            font = "Gill";
        }
        return "myTextVariable=" + escape(text.trim()) + "&myTextFont=" + font + "&myTextSize=" + size;
    }
    function makeString(swf, FlashVars) {
        //WEIRD.
        if (!IsIE8() && !IsIE6()) {
            return '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://macromedia.com/cabs/swflash.cab#version=6,0,0,0" WIDTH="100%" HEIGHT="100%" > <PARAM NAME="wmode" VALUE="transparent" /><PARAM NAME="movie" VALUE="' + swf + '" /><PARAM NAME="quality" VALUE="medium" /><PARAM NAME="FlashVars" VALUE="' + FlashVars + '" /><EMBED src="' + swf + '" WIDTH="100%" HEIGHT="100%" wmode="transparent" 	FlashVars="' + FlashVars + '" TYPE="application/x-shockwave-flash" ></EMBED></OBJECT>';
        } else {
            return '<EMBED src="' + swf + '" WIDTH="100%" HEIGHT="100%" wmode="transparent" 	FlashVars="' + FlashVars + '" TYPE="application/x-shockwave-flash" ></EMBED>';
        }
    }
    //if (!IsIE6()) {
        var swf = baseURL() + "siteswfs/pinnacleTextBox.swf";
        var size = 20;
        var pixsize = Math.round(size * 4 / 3);
        $(pattern).each(function() {
            //make Flash object string, copy computed styles, and add element
            var FlashText = makeString(swf, makeFlashVars($(this).text(), font, size))
            var obj = $('<div style="height:30px; width:100%;" class="flashTextInstance" ></div>');
            obj.css({ 'marginTop': $(this).css('marginTop') });
            obj.css({ 'marginBottom': $(this).css('marginBottom') });
            obj.css({ 'height': pixsize + "px" });
            $(this).after(obj);
            obj.html(FlashText);
            var refereshTextObj = $('<span class="refeshFlash" style="display:none" ></span>').text(FlashText);
            obj.append(refereshTextObj);
        }).remove();    //and remove after processing.
    //}
}
function DoFlashReload(patternOrObj) {
    $(patternOrObj).find("div.flashTextInstance").each(function() {
        var flashText = $(this).find("span.refeshFlash").text();
        var refereshTextObj = $('<span class="refeshFlash" style="display:none"></span>').text(flashText);
        $(this).empty();
        $(this).html(flashText);
        $(this).append(refereshTextObj);
    });
}
function IsIE6() {
    return navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;
}
function IsIE8() {
    return navigator.userAgent.toLowerCase().indexOf('msie 8') != -1;
}
//Replaces elements with flash. Woot
function DoFont() {
    DoFontToFlashReplace("h1", "Gill", 20);
    DoFontToFlashReplace(".pnlCalendarSumary .title .p1", "Hand", 30);
    DoFontToFlashReplace(".pnlCalendarSumary .title .p2", "Hand", 30);
    DoFontToFlashReplace(".pnlCalendarSumary .eventDateRange", "Hand", 15);
    DoFontToFlashReplace(".pnlCalendarSumary .newsHeader", "Hand", 15);
}

function myalert(mesg) {
    $("<li>" + mesg + "</li>").appendTo("#eventLog");
}
function JSResizeSideBar(MaxHeight, White) {
    getFlashMovie("PinnacleStudentBackground").JSresizeSidebar(MaxHeight, White);
}


function BlogCalendar_OnDateSelected(calendarInstance, args) {
    if (args.get_renderDay().get_isSelected()) {
        var dateArr = args.get_renderDay().get_date();
        var date = dateArr[1] + "/" + dateArr[2] + "/" + dateArr[0];
        var dateURL = dateArr[0] + "/" + dateArr[1] + "/" + dateArr[2];
        //alert("OnDateSelected: " + date + " " + (args.get_renderDay().get_isSelected() ? "selected" : "unselected"));
        $.fn.colorbox({ href: baseURL() + "eventsummary/" + dateURL + "/BlogSummary.aspx", open: true, iframe: true, innerWidth: 425, innerHeight: 673 });
    }
};

function genExceptionMessage(ex) {
    if (typeof ex == "string") {
        return ("An exception occurred in the script. Error string: " + ex);
    } else {
        return ("An exception occurred in the script. Error name: " + ex.name
  + ". Error message: " + ex.message);
    }
}

$(document).ready(
    function() {
        DoFont();
    });

