/// <reference path="!!stub-proto.js" />

var $Body;
var $Head;

var Dpea = {
    version: "3.5b",
    SetCookie: function(cookieName, value, isSession) {
        
        if (!isSession) {
            var date = new Date(2010,12,31);
            document.cookie = cookieName + "=" + escape(value) + ";path=/;expires=" + date.toGMTString();
        } else {
            document.cookie = cookieName + "=" + escape(value) + ";path=/";
        }
    },
    GetCookie: function(cookieName) {
        var aCookie = document.cookie.split(";");
        for (var i=0; i<aCookie.length;i++) {
            var aCrumb = aCookie[i].split("=");
            if (aCrumb[0].replace(" ","") == cookieName)
                return unescape(aCrumb[1]);
        }
        return null; 
    }
};

Dpea.Basic = {
    initialise: function() {
        // IE 6 fix - runs out of order
        if ($Body == undefined || $Body == null) {
            $Body = $(document.body).addClassName("loaded");
            $Head = $(document.body.previousSibling);
            Dpea.Zoom.initialise();
        }
    }
};

Dpea.Zoom = {
    curZoom: 100,
    _scales: $A([80,100,125,145]),            
    initialise: function() {
        var first = $("textResizer");
        var _template = new Template("<li id='#{id}'><a href='\#ZoomTo#{scale}Percent' title='Text size #{label}' onclick='return Dpea.Zoom.ZoomTo(#{scale});'>A<span class='textOnly'> (#{label})</span></a> </li>");

        first.insert( "<li>Text size:</li>" );
        [ {scale:80, label:"small", id:"z1"}, {scale:100, label:"normal", id:"z2"},
            {scale:125, label:"large", id:"z3" }, {scale:145, label:"largest", id:"z4"} ].each(function(li) {
                first.insert(  _template.evaluate(li) );
            });
        if (Dpea.GetCookie("currentZoom") != null) {
            this.ZoomTo(Dpea.GetCookie("currentZoom"));
        }
    },
    
    ZoomTo: function(scale) {
        // alert(scale);
        //$Body.setStyle( {'font-size': scale  +"%"});
        document.getElementsByTagName("body")[0].style.fontSize = scale + "%";
        $R(1,4).each(function(n) {
            $("z"+n).firstChild.className="";
        });
        Dpea.Zoom.curZoom = scale;
        
        if (scale == 80) $("z1").firstChild.className = "on";
        if (scale == 100) $("z2").firstChild.className = "on";
        if (scale == 125) $("z3").firstChild.className = "on";
        if (scale == 145) $("z4").firstChild.className = "on";
        
        Dpea.SetCookie("currentZoom", scale, false);

        return false;
    }
}; 

Event.observe(window,"load",function() {Dpea.Basic.initialise();});
