﻿Sys.Browser.WebKit = {}; // Safari 3 is considered WebKit
if (navigator.userAgent.indexOf('WebKit/') > -1) {
    Sys.Browser.agent = Sys.Browser.WebKit;
    Sys.Browser.version = parseFloat(navigator.userAgent.match(/WebKit\/(\d+(\.\d+)?)/)[1]);
    Sys.Browser.name = 'WebKit';
}
/**
 * Liquid Canvas jQuery Plugin 
 * 
 * Version 0.3
 *
 * Steffen Rusitschka  http://www.ruzee.com  MIT licensed
 */
(function($) {
    var canvasElements = [];
    var pollCounter = 0;
    var plugins = {};

    function Area(canvas) {
        var stack = [];

        $.extend(this, {
            width: canvas.width,
            height: canvas.height,
            ctx: canvas.getContext("2d"),
            save: function() {
                this.ctx.save();
                stack.push({ width: this.width, height: this.height });
            },
            restore: function() {
                this.ctx.restore();
                $.extend(this, stack.pop());
            }
        });
    }

    var Plugin = (function() {
        var shrink = function(area, steps) {
            area.ctx.translate(steps, steps);
            area.width -= 2 * steps;
            area.height -= 2 * steps;
        };
        return {
            action: { paint: function() { } },  // provide a NOP "plugin"
            shrink: shrink,
            defaultShrink: shrink,
            setAction: function(action) { this.action = action; }
        };
    })();

    function newPlugin(hash, opts) {
        return $.extend({}, Plugin, hash, { opts: opts, savedOpts: opts });
    }

    function pluginFromPlugins(plugins) {
        return newPlugin({
            paint: function(area) {
                area.save();
                this.action.opts = $.extend(true, this.action.savedOpts);
                $.each(plugins, function() { this.paint(area); });
                area.restore();
            },

            setAction: function(action) {
                this.action = action; // should call super if it existed ...
                $.each(plugins, function() { this.action = action; });
            }
        });
    }
    var pluginFromApplications = pluginFromPlugins; // it just does the same ...

    function pluginFromName(name, opts) {
        var plugin = plugins[name];
        if (!plugin) throw "Unknown plugin: " + name;
        opts = $.extend({}, plugin.defaultOpts || {}, opts);
        return newPlugin(plugin, opts);
    }

    function parse(s) {
        s += " ";
        var index = 0;

        function err(m) { msg = m + " at " + index + ": ..." + s.substring(index) + "\nin " + s; alert(msg); throw msg; }
        function cur() { return s.charAt(index); }
        function next() { if (index > s.length) throw ("Unexpected end"); return s.charAt(index + 1) }
        function eat() { return s.charAt(index++); }
        function skipWhite() { while (/\s/.exec(cur())) eat(); }
        function check(c) {
            skipWhite();
            for (var i = 0; i < c.length; ++i) {
                if (cur() != c.charAt(i)) err("Expected '" + c.charAt(i) + "' found '" + cur() + "'");
                eat();
            }
        }

        // var parseApplications; // forward reference

        function parseWord() {
            skipWhite();
            for (var word = []; /\w/.exec(cur()); word.push(eat()));
            return word.join("");
        }

        function parseNumber() {
            skipWhite();
            for (var n = []; /\d/.exec(cur()); n.push(eat()));
            return parseInt(n.join(""));
        }

        function parseString() {
            skipWhite();
            var s = [], start = cur();
            if (/[^\'\"]/.exec(start)) { err("String expected") }
            eat();
            while (cur() != start) { if (cur() == "\\") s.eat(); s.push(eat()); }
            check(start);
            return s.join("");
        }

        // Yeah, strange thing - this does the CSS value like parsing
        function parseValue() {
            skipWhite();
            for (var s = []; /[^;}]/.exec(cur()); s.push(eat()));
            return s.join("");
        }

        function parseLiteral() {
            skipWhite();
            if (/\d/.exec(cur())) return parseNumber();
            if (/['"]/.exec(cur())) return parseString();
            return parseValue();
        }

        function parseOpts() {
            check("{");
            skipWhite();
            var opts = {};
            while (cur() != "}") {
                var key = parseWord();
                check(":");
                opts[key] = parseLiteral();
                skipWhite();
                if (cur() == "}") break;
                check(";");
            }
            check("}");
            return opts;
        }

        function parsePlugin() {
            var name = parseWord();
            skipWhite();
            opts = cur() == "{" ? parseOpts() : {};
            return pluginFromName(name, opts);
        }

        function parsePlugins() {
            check("[");
            skipWhite();
            var plugins = [];
            while (cur() != "]") {
                plugins.push(parsePlugin());
                skipWhite();
            }
            check("]");
            return pluginFromPlugins(plugins);
        }

        function parseActors() {
            skipWhite();
            return cur() == "[" ? parsePlugins() : parsePlugin();
        }

        function parseAction() {
            var action;
            skipWhite();
            if (cur() == "(") {
                eat();
                action = parseApplications();
                check(")");
            } else {
                action = parsePlugin();
            }
            return action;
        }

        function parseApplication() {
            var actors = parseActors();
            check("=>");
            var action = parseAction();
            actors.setAction(action);
            return actors;
        }

        function parseApplications() {
            var applications = [];
            while (true) {
                applications.push(parseApplication());
                skipWhite();
                if (cur() != ",") break;
                check(",");
            }
            return pluginFromApplications(applications);
        }

        return parseApplications();
    }

    function checkResize(container, force) {
        var $container = $(container);
        var data = $container.data('liquid-canvas');
        if (!data) return;
        var canvas = data.canvas;
        var $canvas = $(canvas);
        var w = $container.outerWidth();
        var h = $container.outerHeight();

        if (force ||
        canvas.width != w || canvas.height != h ||
        canvas.offsetTop != container.offsetTop || canvas.offsetLeft != container.offsetLeft) {
            pollCounter = 100;
            $canvas.css({ left: container.offsetLeft + "px", top: container.offsetTop + "px" });
            canvas.width = w;
            canvas.height = h;
            var area = new Area(canvas);
            area.save();
            data.paint(area);
            area.restore();
        }
    }

    function checkAllResize(force) {
        $.each(canvasElements, function() { checkResize(this, force); });
    }

    function poll() {
        checkAllResize();
        pollCounter--;
        if (pollCounter < 0) {
            pollCounter = 0;
            setTimeout(poll, 1000);
        } else {
            setTimeout(poll, 1000 / 60);
        }
    }

    jQuery.fn.extend({
        liquidCanvas: function(func) {
            this.each(function() {
                var canvas;
                if (window.G_vmlCanvasManager) {
                    $(this).before('<div width="0" height="0" style="position:absolute; top:0px; left:0px;"></div>');
                    canvas = G_vmlCanvasManager.initElement($(this).prev("div").get(0));
                } else {
                    $(this).before('<canvas width="0" height="0" style="position:absolute; top:0px; left:0px;"></canvas>');
                    canvas = $(this).prev("canvas").get(0);
                }

                var paint;
                if ($.isFunction(func)) {
                    paint = func;
                } else {
                    var plugin = parse(func)
                    paint = function(area) { plugin.paint(area); };
                }

                $(this).data("liquid-canvas", {
                    "canvas": canvas,
                    "paint": paint
                });
                $(this).css({ background: "transparent" });
                if ($(this).css("position") != "absolute") $(this).css({ position: "relative" });

                canvasElements.push(this);
                checkResize(this, true);
            });
        },
        liquidCanvasRemove: function() {
            // debugger;
            this.each(function() {
                if (window.G_vmlCanvasManager) {
                    $(this).prev("div").remove();
                } else {
                    $(this).prev("canvas").remove();
                }
                canvasElements.pop(this);
            });
            
        }
    });

    jQuery.extend({
        registerLiquidCanvasPlugin: function(plugin) {
            plugins[plugin.name] = $.extend({}, Plugin, plugin);
        }
    });

    $(document).ready(checkAllResize);
    poll();
})(jQuery);

(function($) {

    $.registerLiquidCanvasPlugin({
        name: "rect",
        paint: function(area) {
            area.ctx.beginPath();
            area.ctx.rect(0, 0, area.width, area.height);
            area.ctx.closePath();
            if (this.action) this.action.paint(area);  // for chaining
        }
    });

    $.registerLiquidCanvasPlugin({
        name: "roundedRect",
        defaultOpts: { radius: 20 },
        paint: function(area) {
            var ctx = area.ctx;
            var opts = this.opts;
            ctx.beginPath();
            ctx.moveTo(0, opts.radius);
            ctx.lineTo(0, area.height - opts.radius);
            ctx.quadraticCurveTo(0, area.height, opts.radius, area.height);
            ctx.lineTo(area.width - opts.radius, area.height);
            ctx.quadraticCurveTo(area.width, area.height, area.width, area.height - opts.radius);
            ctx.lineTo(area.width, opts.radius);
            ctx.quadraticCurveTo(area.width, 0, area.width - opts.radius, 0);
            ctx.lineTo(opts.radius, 0);
            ctx.quadraticCurveTo(0, 0, 0, opts.radius);
            ctx.closePath();
            if (this.action) this.action.paint(area);  // for chaining
        },
        shrink: function(area, steps) {
            this.defaultShrink(area, steps);
            this.opts.radius -= steps;
        }
    });




    $.registerLiquidCanvasPlugin({
        name: "partialRoundedRect",
        defaultOpts: { topLeftRadius: 5, topRightRadius: 10, bottomRightRadius: 20, bottomLeftRadius: 30 },
        paint: function(area) {
            var ctx = area.ctx;
            var opts = this.opts;

            ctx.beginPath();
            // x,y
            ctx.moveTo(0, opts.topLeftRadius);
            ctx.lineTo(0, area.height - opts.bottomLeftRadius);

            ctx.quadraticCurveTo(0, area.height, opts.bottomLeftRadius, area.height);
            ctx.lineTo(area.width - opts.bottomRightRadius, area.height);

            ctx.quadraticCurveTo(area.width, area.height, area.width, area.height - opts.bottomRightRadius);
            ctx.lineTo(area.width, opts.topRightRadius);

            ctx.quadraticCurveTo(area.width, 0, area.width - opts.topRightRadius, 0);
            ctx.lineTo(opts.topLeftRadius, 0);

            ctx.quadraticCurveTo(0, 0, 0, opts.topLeftRadius);
            ctx.closePath();
            if (this.action) this.action.paint(area);  // for chaining
        },
        shrink: function(area, steps) {
            this.defaultShrink(area, steps);
            this.opts.radius -= steps;
        }
    });





    // This is a Liquid Canvas Plugin
    $.registerLiquidCanvasPlugin({
        name: "fill",
        defaultOpts: { color: "#aaa" },
        paint: function(area) {
            area.ctx.fillStyle = this.opts.color;
            this.action.paint(area);
            area.ctx.fill();
        }
    });

    $.registerLiquidCanvasPlugin({  // hmmmmmmm, no rotation? no width??? ah patterns!
        name: "image",
        defaultOpts: { url: "http://www.ruzee.com/files/liquid-canvas-image.png" },
        paint: function(area) {
            var image = new Image();
            image.src = this.opts.url;
            image.onload = function() {
                area.ctx.drawImage(this, 0, 0);
            };
        }
    });

    // This is a Liquid Canvas Plugin
    $.registerLiquidCanvasPlugin({
        name: "gradient",
        defaultOpts: { type: "linear", from: "#fff", to: "#666" },
        paint: function(area) {
            var grad;
            if (this.opts.type == "linear")
                grad = area.ctx.createLinearGradient(0, 0, 0, area.height);
            if (this.opts.type == "radial") {
                // grad = area.ctx.createRadialGradient(45, 45, 10, 250, 250, 330);
                var r1 = area.height > area.width ? (area.height / 2) : (area.width / 2);
                grad = area.ctx.createRadialGradient((area.width / 2), (area.height / 2), 10, (area.width / 2), (area.height / 2), r1);
            }

            grad.addColorStop(0, this.opts.from);
            grad.addColorStop(1, this.opts.to);
            area.ctx.fillStyle = grad;
            this.action.paint(area);
            area.ctx.fill();
        }
    });
    // End of Liquid Canvas Plugin

    $.registerLiquidCanvasPlugin({
        name: "shadow",
        defaultOpts: { width: 3, color: '#000', shift: 2 },
        paint: function(area) {
            var sw = this.opts.width;

            area.ctx.fillStyle = this.opts.color;
            area.ctx.globalAlpha = 1.0 / sw;
            for (var s = 0; s < sw; ++s) {
                this.action.paint(area);
                area.ctx.fill();
                this.action.shrink(area, 1);
            }
            area.ctx.globalAlpha = 1;
            area.ctx.translate(0, -this.opts.shift);
        }
    });

    $.registerLiquidCanvasPlugin({
        name: "border",
        defaultOpts: { color: '#8f4', width: 3 },
        paint: function(area) {
            var bw = this.opts.width;
            area.ctx.strokeStyle = this.opts.color;
            area.ctx.lineWidth = bw;
            this.action.shrink(area, bw / 2);
            this.action.paint(area);
            area.ctx.stroke();
            this.action.shrink(area, bw / 2);
        }
    });
    // <!-- <![CDATA[
    // register a user defined plugin
    $.registerLiquidCanvasPlugin({
        name: "mandala",
        paint: function(area) {
            var opts = this.opts;
            var ctx = area.ctx;
            var min = area.width > area.height ? area.height : area.width;
            var trans = min / 2;
            var rad = trans / 3;
            for (var i = 0; i < 10; ++i) {
                area.save();
                ctx.translate(area.width / 2, area.height / 2);
                ctx.rotate(i * 2 * Math.PI / 10);
                ctx.translate(trans - rad, 0);
                area.width = 30;
                area.height = 30;
                this.action.paint(area);
                area.restore();
            }
        }
    });

})(jQuery);


$(window).load(function() {
    // This will change the height of divs of class .equalHeightBox to the maximum height of the group. 
    var maxH = 0;
    $(".equalHeightContainer .equalHeightBox").each(function() {
        maxH = $(this).height() > maxH ? maxH = $(this).height() : maxH;
    });
    $(".equalHeightContainer .equalHeightBox").height(maxH);


    // Necessary to insure that Liquid Canvas draws boxes of equal height when there is a row of three infoboxes
    // Liquid Canvas
    $("#mainContainer").liquidCanvas("[shadow{width:5; color:#525252;} fill{color:#fff}] => roundedRect{radius:15}");
    $("#HeaderGradient").liquidCanvas("gradient{from:rgba(0, 0, 0, 0.1); to:rgba(255, 255, 255, 0.0);} => roundedRect{radius:8}");
    $("#FooterGradient").liquidCanvas("gradient{from:rgba(255, 255, 255, 0.0); to:rgba(0, 0, 0, 0.1);} => roundedRect{radius:8}");
    // $("#LeftNav").liquidCanvas("[shadow{width:3; color:#999;} gradient{from:#FFF; to: #DEDEDE;}  border{color:#fff; width:4}] => roundedRect{radius:6}");    
    $(".ShadowBoxTop").liquidCanvas("gradient{from:rgba(255, 255, 255, 0.0); to:rgba(0, 0, 0, 0.05);} => rect");
    $(".ShadowBoxBottom").liquidCanvas("gradient{from:rgba(0, 0, 0, 0.15); to:rgba(255, 255, 255, 0.0);} => rect");
    $(".CommonGradientBox").liquidCanvas("gradient{from:rgba(255, 255, 255, 0.0); to:rgba(0, 0, 0, 0.6)} => rect}");
    $(".GenericContainerSmallNoShadow").liquidCanvas("[border{color:#6db737; width:1} fill{color:#f2f2f2;}] => roundedRect{radius:4}");
    $(".GradientBoxContainerThin").liquidCanvas("[shadow{width:3; color:#999;} fill{color:#FFF;}] => roundedRect{radius:8}");
    $(".GradientBoxContainer").liquidCanvas("[shadow{width:3; color:#999;} fill{color:#FFF;}] => roundedRect{radius:8}");
    $(".GradientBoxContainerThin .GradientBox").liquidCanvas("[shadow{width:3; color:#999;} gradient{from:#FFF; to: #DEDEDE;} border{color:#fff; width:3}] => roundedRect{radius:8}");
    $(".GradientBoxContainer .GradientBox").liquidCanvas("[shadow{width:3; color:#999;} gradient{from:#FFF; to: #DEDEDE;} border{color:#fff; width:7}] => roundedRect{radius:8}");
    $(".SolidBox").liquidCanvas("[fill{color:#DEDEDE;}] => roundedRect{radius:8}");
    $(".ClientInfoContainer").liquidCanvas("[shadow{width:3; color:#999;} fill{color:#FFF;}] => roundedRect{radius:8}");
    $(".ClientInfoBox").liquidCanvas("[shadow{width:3; color:#999;} fill{color:#dedede;} border{color:#fff; width:3}] => roundedRect{radius:8}");
    $(".ClientImagesContainer").liquidCanvas("[fill{color:#fff}] => roundedRect{radius:8}");
    $(".ClientImagesBox").liquidCanvas("[fill{color:#fff}] => roundedRect{radius:8}");
    $(".ImageBoxContainer").liquidCanvas("[shadow{width:3; color:#999;} fill{color:#FFF;}] => roundedRect{radius:8}");
    $(".ImageBox").liquidCanvas("[border{color:#fff; width:2}] => roundedRect{radius:10}");
    $(".InfoBoxBar").liquidCanvas("[fill{color:#FFFFFF} gradient{from:rgba(255, 255, 255, 0.0); to:rgba(255, 255, 255, 0.8)}] => partialRoundedRect{topLeftRadius:0; topRightRadius:5; bottomRightRadius:5; bottomLeftRadius:0}");
    $("a.buttonLink").liquidCanvas("[shadow{width:3; color:#999;} gradient{from:#ffb51b; to:#ff7400;} border{color:#000; width:1}] => roundedRect{radius:10}");
    $(".InfoBox").liquidCanvas("[fill{color:#fff}] => roundedRect{radius:8}");
    $(".NoShadow").liquidCanvas("[fill{color:#ffffff;} border{color:#ccc; width:1}] => roundedRect{radius:6}");
    $(".TransparentBorder").liquidCanvas("[fill{color:#ffffff;} border{color:#ffffff; width:1}] => roundedRect{radius:6}");
    $(".GenericColorContainer1Shadow").liquidCanvas("[shadow{width:3; color:#999;} fill{color:#cbdfbc;}] => roundedRect{radius:8}");
    $(".GenericContainerShadow").liquidCanvas("[shadow{width:3; color:#999;} fill{color:#FFF;}] => roundedRect{radius:8}");
    $(".GenericContainerNoShadow").liquidCanvas("[border{color:#6db737; width:3} fill{color:#f2f2f2;}] => roundedRect{radius:8}");
    $(".GenericContainer2NoShadow").liquidCanvas("[fill{color:#ebebeb;} border{color:#ccc; width:1}] => roundedRect{radius:6}");
    $(".GenericContainer2Shadow").liquidCanvas("[shadow{width:3; color:#999;} fill{color:#ebebeb;} border{color:#ccc; width:1}] => roundedRect{radius:6}");
    $(".GenericContainer3Shadow").liquidCanvas("[shadow{width:3; color:#bbbaba;} fill{color:#a6a6a6;}] => roundedRect{radius:8}");
    $(".GenericContainer3NoShadow").liquidCanvas("[border{color:#6db737; width:3} fill{color:#a6a6a6;}] => roundedRect{radius:8}");
    $(".MainNavItemSelected").liquidCanvas("[border{color:#fff; width:2} fill{color:#e2e2e2;}] => roundedRect{radius:6}");
}
			);
// ]]> -->			
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();