/**************register namespace************/
/********************Author:david*************/
if (window.LE == null) {//the top layer namespace of LiveEarthProject
    window.LE = {};
}

if (window.LE.ImageAnchor == null)// the clss in this namespace add anchor in a static image. 
{
    window.LE.ImageAnchor = {};
}

//global static 
LE.ImageAnchor.USERMAP = "#head";
LE.ImageAnchor.MAPNAME = "head";


// a object for area attribute of tag map
LE.ImageAnchor.Area = function(shape, coords, href, alt) //a anchor class
{
    this.shape = shape;   //the shape of mouse when mouseover
    this.coords = coords; //location
    this.href = href;     //url
    this.alt = alt;       //tip when mouseover
}

/*Map object*/
/*areaPool array*/
LE.ImageAnchor.Map = function(id, name, config) 
{
    function getAreaPool() 
    {
        var areaPool = new Array();

        var perArea = null;
        for (var key in config) 
        {
            var perArea = config[key];
            areaPool.push(new LE.ImageAnchor.Area(perArea.shape, perArea.coords, perArea.href, perArea.alt));
        }
        return areaPool;
    }


    this.id = id;
    this.name = name;
    this.areaPool = getAreaPool();

    this.renderTo = function(parentNodeId)
    {
        var map = document.createElement("map");
        map.setAttribute("id", this.id);
        map.setAttribute("name", this.name);

        var areaTemp;
        var areaReal;

        //create nodeset area 
        for (var i = 0; i < this.areaPool.length; i++) {
            areaTemp = this.areaPool[i];

            areaReal = document.createElement("area");

            for (areaAttr in areaTemp) {
                areaReal.setAttribute(areaAttr, areaTemp[areaAttr]);
            }
            map.appendChild(areaReal);
        }

        var parentNode = document.getElementById(parentNodeId).childNodes[0].childNodes[0].childNodes[0]; ;
        parentNode.appendChild(map);
    }
}

LE.ImageAnchor.addImageAnchor = function(ImageAnchorConfig) {
    try {
        var node = document.getElementById("subhead");

        var imgNode = node.childNodes[0].childNodes[0].childNodes[0].childNodes[0];
        imgNode.setAttribute("useMap", LE.ImageAnchor.USERMAP);

        //check the params
        if (ImageAnchorConfig == undefined || ImageAnchorConfig == null || ImageAnchorConfig == "") 
        {
            return;
        } 

        var map = new LE.ImageAnchor.Map(LE.ImageAnchor.MAPNAME, LE.ImageAnchor.MAPNAME, ImageAnchorConfig);
        map.renderTo("subhead");
    }
    catch (e) {
    }

}

/***************************Adjust the height of Main Editorial Module (Author: Sabrina)************************************************/
if (window.LE.MainEditorialHeight == null) 
{
    window.LE.MainEditorialHeight = {};
}

LE.MainEditorialHeight.AdjustHeight = function()
{
    if(document.getElementById("main_editorial_01"))
    {
        var IE_Browser = document.all && window.external;//Check browser type
        if(IE_Browser)
        {
            document.getElementById("main_editorial_01").style.height=document.getElementById("main_editorial_01").parentNode.offsetHeight + "px";
        }else{
           document.getElementById("main_editorial_01").style.height=document.getElementById("main_editorial_01").parentNode.offsetHeight -280 + "px";
           document.getElementById("main_editorial_02").style.width=document.getElementById("main_editorial_01").parentNode.offsetWidth - document.getElementById("main_editorial_01").offsetWidth -66 + "px";
           document.getElementById("main_editorial_03").style.width=document.getElementById("main_editorial_01").parentNode.offsetWidth - document.getElementById("main_editorial_01").offsetWidth -66 + "px";
        }
    }
}

function init() {




    var oImageAnchorConfig = null;
    try 
    {
        // this json obj is the config of tag map that denif
        var str = "{" + "area1:{shape: 'rect', coords: '175,87,315,102'," + arguments[0] + "," + arguments[1] + "}," + "area2: { shape: 'rect', coords: '495,84,565,102'," + arguments[2] + "," + arguments[3] + "}," + "area3:{shape: 'rect', coords: '585,84,675,100', " + arguments[4] + "," + arguments[5] + "}," + "area4:{shape:'rect',coords: '701,81,779,102', " + arguments[6] + "," + arguments[7] + "}," + "area5:{shape:'rect',coords:'835,55,950,93'," + arguments[8] + "," + arguments[9] + "}" + "}";
        // convert the string to  json obj
        oImageAnchorConfig = eval('(' + str + ')');
    }
    catch (e) { }
    
    window.onload = function() 
    {
        //addImageAnchor
        LE.ImageAnchor.addImageAnchor(oImageAnchorConfig);
        //Adjust Adjust the height of Main Editorial Module
        LE.MainEditorialHeight.AdjustHeight();
    }
}

/****************Global Flash Configuration JS*******************************************************/
function GetParams(ParamName) {
    var Params = { ConfigXML: "http://stc.sand.msn-int.com/br/intl/spec/le/flash/ImagesConfig.xml", LiveEarthGlobalSite: "http://stc.sand.msn-int.com/br/intl/spec/le/flash/LiveEarthGlobalSite.swf", GlobalSiteClassName: "Main" };
    return Params[ParamName];
}

/***************Artist Gallery Configuratio JS**************************************/
function GetPhotoParams_ForFlash(ParamName) {
    var Params = { ConfigXML: "http://stcjp.msn.com/br/intl/spec/le/flash/artistgallery/in/ImagesConfig.xml", showTime: 5000, RevolveNum: 5000 };
    return Params[ParamName];
} 
