﻿//-----------------------------------------------------------------------
// Copyright (C) Winthusiasm (tm). All rights reserved.
//-----------------------------------------------------------------------
// MasterPage.js

function AttachShadow(e, size, borderSize, width, className, ieClassName)
{
    if (e.rightShadow) return;
    
    var pxSize = size + "px";
    var pxWidth = width ? (width - size).toString() + "px" : "100%";
    var isIE = Sys.Browser.agent == Sys.Browser.InternetExplorer;
    var browserVersion = Sys.Browser.version;
    var isIE6 = isIE && browserVersion < 7;
    var classNames = null;
    
    if (className) 
        classNames = className;
        
    if (ieClassName && isIE) 
        classNames = className ? (className + " " + ieClassName) : ieClassName;

    function CreateShadow(bottom)
    {
        var shadow = document.createElement("div");
        shadow.innerHTML = "&nbsp;";
        shadow.style.fontSize = "1px";
        shadow.style.position = "absolute";
        shadow.style.height = bottom ? pxSize : "100%";
        shadow.style.width = bottom ? pxWidth : pxSize;

        if (bottom)
        {
            shadow.style.bottom = "-" + (size + borderSize) + "px";
            shadow.style.left = (size + borderSize) + "px";
        }
        else
        {
            shadow.style.top = (size + borderSize) + "px";
            shadow.style.right = "-" + (size + borderSize) + "px";
        }
        
        if (classNames)
            shadow.className = classNames;
        else
            shadow.style.backgroundColor = "gray";
        
        return shadow;
    }

    var bottomShadow = CreateShadow(true);
    var rightShadow = CreateShadow(false);

    e.appendChild(bottomShadow);
    e.appendChild(rightShadow);
    
    e.bottomShadow = bottomShadow;
    e.rightShadow = rightShadow;
    
    if (isIE)
        e.onresize = function()
                     { 
                        this.bottomShadow.style.width = (this.offsetWidth - size - (borderSize * 2)).toString() + "px"; 
                        this.rightShadow.style.height = (this.offsetHeight - (borderSize * 2)).toString() + "px"; 

                        if (isIE6)
                        {
                            this.bottomShadow.style.top = (this.offsetHeight + borderSize).toString() + "px";
                            this.bottomShadow.style.bottom = "";
                        }
                     };
}
    
function AttachMenuShadows(id, tagName, parentTagName, size, borderSize, width, className, ieClassName)
{
    var base = $get(id);
    var elements = base.getElementsByTagName(tagName);
    
    for (var i = 0; i < elements.length; i++)
    {
        var element = elements[i];
        if (element.parentNode.tagName.toLowerCase() != parentTagName) continue;
        
        AttachShadow(element, size, borderSize, width, className, ieClassName);
    }
}

function RoundCorners(element, bgColor, pixelImageUrl)
{
    function RoundCorner(element, left, top)
    {
        function CreateImage()
        {
            var img = document.createElement("img");
            img.style.backgroundColor = bgColor;
            img.style.position = "absolute";
            img.src = pixelImageUrl;
            
            return img;
        }

        function CloneImage(img, l, t, r, b)
        {
            var cloneImg = img.cloneNode(false);

            if (l)
                cloneImg.style.left = l + "px";
            
            if (t)
                cloneImg.style.top = t + "px";
            
            if (r)
                cloneImg.style.right = r + "px";
            
            if (b)
                cloneImg.style.bottom = b + "px";
            
            return cloneImg;
        }

        var img = CreateImage();
        
        if (left && top)
        {
            img.style.left = "0px";
            img.style.top = "0px";
            
            element.appendChild(img);
            element.appendChild(CloneImage(img, 0, 1));
            element.appendChild(CloneImage(img, 0, 2));
            element.appendChild(CloneImage(img, 1, 0));
            element.appendChild(CloneImage(img, 2, 0));
        }
        else if (left && !top)
        {
            img.style.left = "0px";
            img.style.bottom = "0px";
            
            element.appendChild(img);
            element.appendChild(CloneImage(img, 0, null, null, 1));
            element.appendChild(CloneImage(img, 0, null, null, 2));
            element.appendChild(CloneImage(img, 1, null, null, 0));
            element.appendChild(CloneImage(img, 2, null, null, 0));
        }
        else if (top && !left)
        {
            img.style.right = "0px";
            img.style.top = "0px";
            
            element.appendChild(img);
            element.appendChild(CloneImage(img, null, 1, 0, null));
            element.appendChild(CloneImage(img, null, 2, 0, null));
            element.appendChild(CloneImage(img, null, 0, 1, null));
            element.appendChild(CloneImage(img, null, 0, 2, null));
        }
        else if (!top && !left)
        {
            img.style.right = "0px";
            img.style.bottom = "0px";
            
            element.appendChild(img);
            element.appendChild(CloneImage(img, null, null, 1, 0));
            element.appendChild(CloneImage(img, null, null, 2, 0));
            element.appendChild(CloneImage(img, null, null, 0, 1));
            element.appendChild(CloneImage(img, null, null, 0, 2));
        }
    }

    RoundCorner(element, true, true);    
    RoundCorner(element, false, true);    
    RoundCorner(element, true, false);    
    RoundCorner(element, false, false);    
}

function InitializeWebkit()
{
    if (Sys.Browser.WebKit) return;

    Sys.Browser.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';
    }
}

InitializeWebkit();
