//================================================
// mtnav.js
// serial#:20020204003
//================================================
// it expands and collapses the mt admin 
// navigation.
//================================================
// TODO:
// - for nav4, only set height of main layer as 
//   large as is necessary.
// - netscape hand (if possible)
// - do not allow selection of text. i hate that.
// - clean up and comment.
//================================================

var MTNAV_COMPAT = 0;

if ((document.layers || document.getElementById || document.all) && navigator.userAgent.indexOf("Opera") < 0) {
        var MTNAV_COMPAT = 1;

        var SECTION_BACK                = "images/s.jpg";
        var SECTION_BACK_OVER           = "images/s-bg.jpg";
        var SECTION_BACK_ACTIVE         = "images/sek.gif";
        var ITEM_BACK                   = "images/sek.gif";
        var ITEM_BACK_OVER              = "images/sek-bg.gif";

       var SECTION_HEIGHT              = 20;
        var ITEM_HEIGHT                 = 19;
        var MENU_WIDTH                  = 160;

        var SECTION_PADDING_LEFT        = 4;
        var SECTION_PADDING_TOP         = 3;

        var ITEM_PADDING_LEFT           = 10;
        var ITEM_PADDING_TOP            = 3;

        var SLIDE_LENGTH                = 400;
        var SLIDE_ZIP                   = .5;

    document.writeln('<style type="text/css">');
    document.writeln('#mtnav { visibility:hidden; }');
    document.writeln('#mtnav div { position:absolute; overflow:hidden; width:' + MENU_WIDTH + 'px; }');
    document.writeln('</style>');
    document.writeln('<link rel="stylesheet" type="text/css" href="advanced.css">');

    var g_oMtNav, g_aSections = new Array();
    var g_images = [SECTION_BACK, SECTION_BACK_OVER, SECTION_BACK_ACTIVE, ITEM_BACK, ITEM_BACK_OVER];
    var g_activeSection = null;
    var g_sliding = false;
    var g_isMac = navigator.userAgent.match(/(mac|68k|68000|ppc|powerpc)/i) ? true : false;
    var g_useBack = document.layers || g_isMac;

    for (var i = 0; i < g_images.length; i++) {
        var img = new Image();
        img.src = g_images[i];
        g_images[i] = img;
    }

    function initMTNav() {
        g_oMtNav = gE("mtnav");
        g_aSections = gK(g_oMtNav);

        for (var i = 0; i < g_aSections.length; i++) {
            initSection(g_aSections[i], i);
        }

        sW(g_oMtNav, MENU_WIDTH);
        sH(g_oMtNav, 600);
        sE(g_oMtNav);
    }

    function initSection(oSection, iSectionNum) {
        sX(oSection, 0);
        sY(oSection, iSectionNum * SECTION_HEIGHT);
        sH(oSection, SECTION_HEIGHT);
        sC(oSection, 0, MENU_WIDTH, SECTION_HEIGHT, 0);

        var k = gK(oSection);

        initSectionHead(k[0]);

        for (var i = 1; i < k.length; i++) {
            initItem(k[i], i-1);
        }

        oSection.k = k;
        oSection.n = iSectionNum;
    }

    function initSectionHead(oSectionHead) {
        sW(oSectionHead, MENU_WIDTH);
        sH(oSectionHead, SECTION_HEIGHT);
        sC(oSectionHead, 0, MENU_WIDTH, SECTION_HEIGHT, 0);
        
        if (g_useBack) sB(oSectionHead, SECTION_BACK);
        else {
                oSectionHead.innerHTML += "<img src='" + SECTION_BACK + "' style='position:absolute; left:0; top:0; z-index:1;'>";
                oSectionHead.getElementsByTagName("DIV")[0].style.zIndex = 2;
        }

        var k = gK(oSectionHead);

        sX(k[0], SECTION_PADDING_LEFT);
        sY(k[0], SECTION_PADDING_TOP);

        if (l) oSectionHead.captureEvents(Event.MOUSEDOWN);

        oSectionHead.onmouseover = sectionHeadMousedOver;
        oSectionHead.onmouseout  = sectionHeadMousedOut;
        oSectionHead.onmousedown = sectionHeadMousedDown;
    }

    function sectionHeadMousedOver() {
        if (gP(this) != g_activeSection) {
                if (g_useBack) sB(this, g_images[1].src);
                else this.getElementsByTagName("IMG")[0].src = g_images[1].src;
				
        }
    }

    function sectionHeadMousedOut() {
        if (gP(this) != g_activeSection) {
                if (g_useBack) sB(this, g_images[0].src);
                else this.getElementsByTagName("IMG")[0].src = g_images[0].src;
        }
    }

    function sectionHeadMousedDown() {
        toggle(gP(this));

		// ozge ekledi. 
        if (this.getElementsByTagName) {
            sectionLink = this.getElementsByTagName("A")[0];
			if (sectionLink!=null){
			  clickLink(sectionLink);
			}
        }
		// ozge ekledi. 

    }

    function toggle(oSection) {
        if (!g_sliding) {
            // reset
            g_openingSection = null;
            g_closingSection = null;

            // if there's a section open, close it.
            if (g_activeSection != null) {
                g_closingSection = g_activeSection;
                if (g_useBack) sB(g_closingSection, g_images[0].src);
                else g_closingSection.getElementsByTagName("IMG")[0].src = g_images[0].src;
				
            }

            // if this section wasn't that same one, then open it.
            if (g_activeSection != oSection) {
                g_openingSection = oSection;
				if (g_useBack) sB(g_openingSection, g_images[1].src);
                else g_openingSection.getElementsByTagName("IMG")[0].src = g_images[1].src;
            }

            // fix up the layout.
            startSlide();

            // note changes.
            g_activeSection = oSection != g_activeSection ? oSection : null ;
        }
    }
	
	 function toggleLoad() {
	 
	    g_oActive = gE("active");
       	toggle(g_oActive)
		
       
    }



    function startSlide() {
        g_sliding = true;
        g_slideStartTime = new Date().getTime();

        if (g_openingSection != null) {
            g_openingSection.xo = Number(gC(g_openingSection)[2]);
            g_openingSection.xf = (g_openingSection.k.length - 1) * ITEM_HEIGHT + SECTION_HEIGHT;
            g_openingSection.dx = g_openingSection.xf - g_openingSection.xo;
            g_openingSection.a = g_openingSection.dx / Math.pow(SLIDE_LENGTH, SLIDE_ZIP);
        }
        if (g_closingSection != null) {
            g_closingSection.xo = Number(gC(g_closingSection)[2]);
            g_closingSection.xf = SECTION_HEIGHT;
            g_closingSection.dx = g_closingSection.xf - g_closingSection.xo;
            g_closingSection.a = g_closingSection.dx / Math.pow(SLIDE_LENGTH, SLIDE_ZIP);
        }
        g_slideTimerID = window.setInterval("slide()", 10);
				paintBanner();

    }
    
    function slide() {
        var elapsed = new Date().getTime() - g_slideStartTime;

        if (elapsed >= SLIDE_LENGTH) {
            endSlide();
        }
        else {
            if (g_openingSection != null) {
                var h = g_openingSection.a * Math.pow(elapsed, SLIDE_ZIP) + g_openingSection.xo;
                sH(g_openingSection, h);
                sC(g_openingSection, 0, MENU_WIDTH, h, 0);
            }
            if (g_closingSection != null) {
                var h = g_closingSection.a * Math.pow(elapsed, SLIDE_ZIP) + g_closingSection.xo;
                sH(g_closingSection, h);
                sC(g_closingSection, 0, MENU_WIDTH, h, 0);
            }
            paint();
        }    
    }

    function endSlide() {
        window.clearInterval(g_slideTimerID);
        if (g_openingSection != null) {
            sH(g_openingSection, g_openingSection.xf);
            sC(g_openingSection, 0, MENU_WIDTH, g_openingSection.xf, 0);
        }
        if (g_closingSection != null) {
            sH(g_closingSection, g_closingSection.xf);
            sC(g_closingSection, 0, MENU_WIDTH, g_closingSection.xf, 0);
        }
        paint();
        g_sliding = false;
    }

    // well it doesn't actually do that, it re-lays things out based on
    // the current heights of the section divs. 
    // but I like having a function called "paint". It makes me feel cool. 
    // like a game programmer. yea...
    function paint() {
        var t = 0;

        for (var i = 0; i < g_aSections.length; i++) {
            sY(g_aSections[i], t);
            t += Number(gC(g_aSections[i])[2]);
        }
    }

    function initItem(oItem, iItemNum) {
        sX(oItem, 0);
        sY(oItem, iItemNum * ITEM_HEIGHT + SECTION_HEIGHT);
        sW(oItem, MENU_WIDTH);
        sH(oItem, ITEM_HEIGHT);

        if (g_useBack) sB(oItem, ITEM_BACK);
        else {
		if (oItem.id!="") {
				oItem.className = "hover";
				oItem.innerHTML += "<img src='" + ITEM_BACK_OVER + "' style='position:absolute; left:0; top:0; z-index:1;'>";
		}
		else{
                oItem.innerHTML += "<img src='" + ITEM_BACK + "' style='position:absolute; left:0; top:0; z-index:1;'>";
		}
                oItem.getElementsByTagName("DIV")[0].style.zIndex = 2;
				
        }

        var k = gK(oItem);
        sX(k[0], ITEM_PADDING_LEFT);
        sY(k[0], ITEM_PADDING_TOP);

        if (l) oItem.captureEvents(Event.CLICK);

        oItem.onmouseover = itemMousedOver;
        oItem.onmouseout  = itemMousedOut;
        oItem.onclick     = itemClicked;
    }

    function itemMousedOver() {
	if (this.id=="") {
		this.className = "hover";
	    if (g_useBack) sB(this, g_images[4].src);
	        else this.getElementsByTagName("IMG")[0].src = g_images[4].src;
	}
    }

    function itemMousedOut() {
	if (this.id=="") {
        this.className = "";
        if (g_useBack) sB(this, g_images[3].src);
        else this.getElementsByTagName("IMG")[0].src = g_images[3].src;
	}
    }

    function itemClicked() {
        var l;
        
        if (document.layers) {
            l = this.layers[0].document.links[0];
        }
        else if (this.getElementsByTagName) {
            l = this.getElementsByTagName("A")[0];
        }
        else {
            l = this.all.tags("A")[0].click();
        }

		
        clickLink(l);
    }

    function clickLink(l) {
        var t = l.target;
        
        if (t == "" || t == null) {
            var w = window;
        }
        else if (t == "_self" || t == "_parent" || t == "_top") {
            var w = window[t.substring(1, t.length)];
        }
        else if (window.parent.frames[t]) {
            var w = window.parent.frames[t];
        }
        else {
            var w = window.open();
        }

        w.location.href = l.href;
    }

    function dbg(o) {
        var s = "";
        var i = 0;
        for (p in o) {
            s += p + ":"+ o[p] + "\n";
            if (++i % 15 == 0) {
                alert(s);
                s = "";
            }
        }
    }

}

  function paintBanner() {
	 // Banner kayiyyoor
	targetBnnr=document.getElementById('bnnr');
	topix=topProductMenu+(g_aSections.length*20)+10
	if ((g_openingSection != null) && (g_closingSection != null)) {
		targetBnnrHeight=g_openingSection.xf-g_closingSection.xf + 20; 
		topix=topProductMenu+(targetBnnrHeight-20)+(g_aSections.length*20)+10;
	} else {
		if (g_openingSection != null)	{ targetBnnrHeight=g_openingSection.xf;  topix=topProductMenu+(targetBnnrHeight-20)+(g_aSections.length*20)+10; }
		if (g_closingSection != null)  { targetBnnrHeight=g_closingSection.xf; topix=topProductMenu+(targetBnnrHeight-20)+(g_aSections.length*20)+10; }
	}
	 
	 targetBnnr.style.top =topix+'px'
}

