
var states = new Object();
var ie = false;
var ie6 = false;
var nojs = false;
var textversion = true;
var debug = false;
var debugField = null;
var cache = new Array();

if (debug) {
    setTimeout(function() { debugField = $('debugger'); }, 100); //AccDev
}


// Mozilla contains() hack
if (window.Node && Node.prototype && !Node.prototype.contains) {
    Node.prototype.contains = function(arg) { return !!(this.compareDocumentPosition(arg) & 16) }
}

document.write('<style type="text\/css">');
document.write('.subMenu { display: none; } ');
document.write('<\/style>');


function $(e) {
    if (cache[e]) return cache[e];
    if (document.getElementById) {
        var el = document.getElementById(e);
        if (el) { cache[e] = el; return el; }
    }
    if (document.all) {
        var el = document.all[e];
        if (el) { cache[e] = el; return el; }
    }
}

if (navigator.appName.indexOf('Microsoft') != -1) {
    ie = true;
    d('internet explorer');
    if (navigator.appVersion.indexOf('MSIE 6.0') != -1) {
        ie6 = true;
        d('internet explorer version 6');
    }
}

function d(s) {
    if (debug) {
        try {
            debugField.innerHTML = s + '<br />' + debugField.innerHTML;
        } catch (e) {
            setTimeout('d ("' + s + '")', 100); //AccDev
        }
    }
}

function fade_to_100(element) {
    if (typeof (element) == 'string') element = $(element);

    var o = parseFloat(get_opacity(element));

    element.style.display = 'block';
    set_opacity(element, (o + 0.05));
    if (get_opacity(element) < 1) {
        setTimeout("fade_to_100 ('" + element.id + "')", 5);
    } else {
        states[element.id] = 2;
    }

}

function fade_to_100_with_interval(element, interval) {
    if (typeof (element) == 'string') element = $(element);
    var o = parseFloat(get_opacity(element));
    element.style.display = 'block';

    set_opacity(element, (o + interval));

    if (get_opacity(element) < 1) {
        setTimeout("fade_to_100_with_interval ('" + element.id + "', " + interval + ")", 5);
    } else {
        states[element.id] = 2;
    }
}

function fade_to_zero(element) {
    if (typeof (element) == 'string') element = $(element);
    var o = parseFloat(get_opacity(element));
    set_opacity(element, (o - 0.05));
    //alert('Hi');
    //alert(get_opacity(element));
    states[element.id] = 3;
    if (get_opacity(element) >= 0) {
        if (ie||ie6) { //AccDev: Added
            setTimeout("fade_to_zero_with_interval ('" + element.id + "')", 5);
        }
        else {
            setTimeout("fade_to_zero ('" + element.id + "')", 5);
        }
    } else {
        states[element.id] = 0;
        element.style.display = 'none';
    }

}

function fade_to_zero_with_interval(element, interval) {
    if (typeof (element) == 'string') element = $(element);
    var o = parseFloat(get_opacity(element));
    set_opacity(element, (o - interval));

    states[element.id] = 3;

    if (get_opacity(element) >= 0) {
        setTimeout("fade_to_zero_with_interval ('" + element.id + "', " + interval + ")", 5);
    } else {
        states[element] = 0;
        element.style.display = 'none';
    }

}

function fade_to_zero_callback(element, interval, callback) {
    if (typeof (element) == 'string') element = $(element);
    d('fade 0 callback => ' + element.id);

    var o = parseFloat(get_opacity(element));
    set_opacity(element, (o - interval));

    states[element.id] = 3;

    if (get_opacity(element) >= 0) {
        setTimeout("fade_to_zero_callback ('" + element.id + "', " + interval + ", " + callback + ")", 1);
    } else {
        states[element.id] = 0;
        callback();
        element.style.display = 'none';
    }

}

function sayhi() {
    alert('hi');
}

function jump_to_100(element) {//alert('Hi-jumpto100');
    if (typeof (element) == 'string') element = $(element);
    d('set 100 => ' + element);
    element.style.display = 'block';
    set_opacity(element, 1);
    states[element.id] = 2;
}



function jump_to_zero(element) {
    if (typeof (element) == 'string') element = $(element);
    d('set 0 => ' + element.id);
    element.style.display = 'none';
    set_opacity(element, 0);
    states[element.id] = 0;
}

var rollout_timeout;
var timeouts = new Object();

function rollover(e) {//alert("element:" + e);

    if (typeof (e) != 'string') e = e.id;
    //alert(typeof (e));
    //alert("states(e)" + states[e]);
    if (ie) {
        if (states[e] == 0 || states[e] == null || states[e] == undefined || states[e] == 3) {//alert('inrollover-if');
            states[e] = 1;
            fade_to_100(e);
        } else if (states[e] == 2) {
            //alert('inrollover-elseif');
            //alert(timeouts[e]);
            clearTimeout(timeouts[e]);
        } 
    }
    else {
        if (states[e] == 0 || states[e] == null) {//alert('inrollover-if');
            states[e] = 1;
            fade_to_100(e);
        } else if (states[e] == 2) {
            //alert('inrollover-elseif');
            //alert(timeouts[e]);
            clearTimeout(timeouts[e]);
        }
    }
}

function is_in_transition() {

    for (state in states) {

        if (states[state] == 1) {
          
            return true;
        }
    }
    return false;
}

function rollout(e) {
    if (is_in_transition()) {
        return;
    }
    if (typeof (e) != 'string') e = e.id;
    if (states[e] == 2 || states[e] == 3) {

        timeouts[e] = setTimeout('fade_to_zero (\'' + e + '\')', 100); //AccDev
    }

    if (states[e] == 1) {
        states[e] = 2;
        setTimeout('rollout (\'' + e + '\')', 100); //AccDev
    }
}

function set_opacity(e, val) {
    if (typeof (e) == 'string') e = $(e);
    val = roundNumber(val);
    if (ie) {
         //alert(e + " " + val);
        e.style.filter = 'alpha(opacity=' + (val * 1000) + ')'; //AccDev
    } else {
        e.style.MozOpacity = (val);
    }

    d('set opacity ' + val + ' => ' + e.id);
}

function get_opacity(e) {
    if (typeof (e) == 'string') e = $(e);
    if (ie) {
        o = e.style.filter.substr(e.style.filter.indexOf("=") + 1, e.style.filter.indexOf(")") - (e.style.filter.indexOf("=") + 1));
        //alert(o);
        if (o == '') {
            set_opacity(e.id, 0);
            return get_opacity(e);
        } else {
            o = parseFloat(o);
            o = (o / 100);
            o = roundNumber(o);

            return o;
        }
    } else {
        o = e.style.MozOpacity;
    }

    return o;
}

function hide_all() {
    jump_to_zero('menu_gender');
    jump_to_zero('menu_one_links');
    jump_to_zero('menu_two_links');
    jump_to_zero('menu_shopOnline_links'); //AccDev
    //jump_to_zero ('menu_skin_links'); 
    jump_to_zero('menu_three_links');
    jump_to_zero('menu_four_links');
}

function roundNumber(n) {
    var rnum = n;
    var rlength = 2; // The number of decimal places to round to
    if (rnum > 8191 && rnum < 10485) {
        rnum = rnum - 5000;
        var newnumber = Math.round(rnum * Math.pow(10, rlength)) / Math.pow(10, rlength);
        newnumber = newnumber + 5000;
    } else {
        var newnumber = Math.round(rnum * Math.pow(10, rlength)) / Math.pow(10, rlength);
    }
    return newnumber;
}


function containsDOM(container, containee) {
    var isParent = false;
    do {
        if ((isParent = container == containee))
            break;
        containee = containee.parentNode;
    }
    while (containee != null);
    return isParent;
}

function checkMouseEnter(element, evt) {
    if (element.contains && evt.fromElement) {
        return !element.contains(evt.fromElement);
    }
    else if (evt.relatedTarget) {
        return !containsDOM(element, evt.relatedTarget);
    }
}

function checkMouseLeave(element, evt) {
    if (element.contains && evt.toElement) {
        return !element.contains(evt.toElement);
    }
    else if (evt.relatedTarget) {
        return !containsDOM(element, evt.relatedTarget);
    }
} 

