﻿

var sPath = window.location.pathname;
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
sPage = sPage.toLowerCase()

//pre-loads all of the menu images

var defaultimageover = new Image(350, 100)
defaultimageover.src = "/App_Themes/CPLGSHK/Images/menuhome.png";
var sourcingimageover = new Image(350, 100)
sourcingimageover.src = "/App_Themes/CPLGSHK/Images/menusourcing.png";
var designimageover = new Image(350, 100)
designimageover.src = "/App_Themes/CPLGSHK/Images/menudesign.png";
var qualityimageover = new Image(350, 100)
qualityimageover.src = "/App_Themes/CPLGSHK/Images/menuquality.png";
var collectionsimageover = new Image(350, 100)
collectionsimageover.src = "/App_Themes/CPLGSHK/Images/menucollect.png";
var wheretoimageover = new Image(350, 100)
wheretoimageover.src = "/App_Themes/CPLGSHK/Images/menuwhereto.png";
var brochureimageover = new Image(350, 100)
brochureimageover.src = "/App_Themes/CPLGSHK/Images/menubrochure.png";

// set the 'out' image source depending on the current page name

var currentimageout = new Image(350, 100);
if (sPage == "default.aspx") {
    currentimageout.src = defaultimageover.src;
}
else if (sPage == "sourcinganddesign.aspx") {
currentimageout.src = sourcingimageover.src;
}
else if (sPage == "design.aspx") {
currentimageout.src = designimageover.src;
}
else if (sPage == "qualityassurance.aspx") {
currentimageout.src = qualityimageover.src;
}
else if (sPage == "homecollections.aspx") {
currentimageout.src = collectionsimageover.src;
}
else if (sPage == "whereto.aspx") {
currentimageout.src = wheretoimageover.src;
}
else if (sPage == "brochurerequest.aspx") {
currentimageout.src = brochureimageover.src;
}
else if (sPage == "admin.aspx") {
currentimageout.src = defaultimageover.src;
}
else if (sPage == "") {
currentimageout.src = defaultimageover.src;
}


// set the image map image depending on what shape the mouse is currently over
function DisplayImage(image) {
    var obj = document.getElementById("ctl00_imageMenu")
    obj.src = image.src;
    return true;
}


//var _controls_loaded = new Array();
//function AttachMouseEventsToAreaTags(img) {
//    if (_controls_loaded[img.id] == null) {
//        var image_map = document.getElementById(img.getAttribute("usemap").substring(1));

//        for (var i = 0; i < image_map.areas.length; i++) {
//            addEvent(image_map.areas[i], "mouseover", MouseOverArea);
//            addEvent(image_map.areas[i], "mouseout", MouseOutArea);
//        }

//        _controls_loaded[img.id] = true;
//    }
//}

//function MouseOverArea(e) {
////    var image_map = document.getElementById(e.fromElement.useMap.substring(1));
////    image_map.ImageUrl = "~/App_Themes/CPLGSHK/Images/testmenu.png"
////    var area_tag = (e.srcElement || e.target);
////    ShowUserRatingImage(area_tag.parentNode.id.substring(8), parseInt(area_tag.href.substring(area_tag.href.length - 3), 10) + 1);
//    ShowImage(e)
//}

//function MouseOutArea(e) {
////    var area_tag = (e.srcElement || e.target);
//    //    RestoreRatingImageToOriginal(area_tag.parentNode.id.substring(8));
//    
//    RestoreImage(e)
//}


//function ShowImage(area) {
//    // var area_tag = (area.srcElement || area.target);
//    //document.imMenu.src = "~/App_Themes/CPLGSHK/Images/testmenu.png";
//    var o = getElementByContentId("imMenu");
//    alert("showimage");
//}

//function RestoreImage(area) {
//    alert("restoreimage")
//}



//function addEvent(obj, type, fn) {
//    if (obj.addEventListener) {
//        obj.addEventListener(type, fn, false);
//        EventCache.add(obj, type, fn);
//    }
//    else if (obj.attachEvent) {
//        obj["e" + type + fn] = fn;
//        obj[type + fn] = function() { obj["e" + type + fn](window.event); }
//        obj.attachEvent("on" + type, obj[type + fn]);
//        EventCache.add(obj, type, fn);
//    }
//    else {
//        obj["on" + type] = obj["e" + type + fn];
//    }
//}

//var EventCache = function() {
//    var listEvents = [];
//    return {
//        listEvents: listEvents,
//        add: function(node, sEventName, fHandler) {
//            listEvents.push(arguments);
//        },
//        flush: function() {
//            var i, item;
//            for (i = listEvents.length - 1; i >= 0; i = i - 1) {
//                item = listEvents[i];
//                if (item[0].removeEventListener) {
//                    item[0].removeEventListener(item[1], item[2], item[3]);
//                };
//                if (item[1].substring(0, 2) != "on") {
//                    item[1] = "on" + item[1];
//                };
//                if (item[0].detachEvent) {
//                    item[0].detachEvent(item[1], item[2]);
//                };
//                item[0][item[1]] = null;
//            };
//        }
//    };
//} ();
//addEvent(window, 'unload', EventCache.flush);


function getElementByContentId(contentId) {
    var o;
    try {
        o = eval(contentId);
    }
    catch (e) {
    }
    if (o == null) {
        o = document.getElementById(contentId);
    }
    if (o == null) {
        var id = eval("ctl00_" + contentId);
        try {
            o = eval(id);
        }
        catch (e) {
        }
    }
    if (o == null) {
        o = document.getElementById(id)
    }
    if (o == null) {
        o = findControl(id)
    }
    return o;
}

function findControl(id) {
    for (i = 0; i < document.all.length; i++) {
        if (document.all(i).id == id) {
            return document.all(i)
        }
    }
    return null
}


function printcontrolids() {
 for (i = 0; i < document.all.length; i++) 
        {
             alert(document.all(i).id);
        }
    return null
}
