// to show catagories in the menu top
var iCurMenuItemType = 0;
var iLinkType = 0;
var aMenuItemType = new Array();
var aLinkType = new Array();
var curCatMenu = '';
var curCatMenuId = 0;
var goCategoryBottom = 0;
var goCategoryTop = 0;
var goBasketBottom = 0;
var goBasketTop = 0;
var HideLeftPanel = 0;
var mainmenuVer = 0; // if it need to be changed, put value on skin




function menuitemType(Id, Text) {
    this.Id = Id;
    this.Text = Text;
}

function menulinkType(Ref, Target) {
    this.Ref = Ref;
    this.Target = Target;
}


function addMenuItemType(coid, id, text) {
    aMenuItemType[coid] = new menuitemType(id, text);

}

function setTextType(obj, text) {
    if (obj.innerHTML != null) {
        obj.innerHTML = text;
    }
}

function addLinkType(id, Ref, Target) {
    aLinkType[id] = new menulinkType(Ref, Target);
}


function MenuType(iItem, container) {
    ShowMenuItemNo = iItem; //container
    curMenuItemIndex = 0;
    var strt = '';
    var ilength = aMenuItemType.length;
    for (var ii = 1; ii < ilength; ii++) {
        strt = strt + '<ul width="100%" id="catdiv' + ii + '">' + MenuHTMLType(iItem, null) + '</ul>';
        iItem = iItem + 1;
    }
    container.innerHTML = strt;
}

function MenuTypeNew(iItem, container) {
    ShowMenuItemNo = iItem; //container
    curMenuItemIndex = 0;
    var strt = '';
    var ilength = aMenuItemType.length;
    for (var ii = 1; ii < ilength; ii++) {
        strt = strt + '<ul width="100%" id="catdiv' + ii + '">' + MenuHTMLTypeNew(iItem, null) + '</ul>';
        iItem = iItem + 1;
    }
    //alert(strt); 
    container.innerHTML = strt;
}


function MenuHTMLType(iItem, container) {
    var str = '';
    idx = iItem;
    str += MenuItemHTMLType(iItem) + '<div width="100%" ID="cdiv' + iItem + '" STYLE="display:none">';
    str += '</div>';
    return str;
}


function MenuHTMLTypeNew(iItem, container) {
    var str = '';
    idx = iItem;
    str += MenuItemHTMLTypeNew(iItem) + '<div width="100%" id="catHolder' + iItem + '" ';
    str += ' class="CatMenuHide" ';
    str += 'loading="0" >';
    //    processing
    str += '<div id="processing' + iItem + 'cat" style ="position:absolute; top:20%;">';
    str += '</div>';
    //categoryup
    //var category1scroller=new scroller('category1',200);  
    // some main wrap around
    str += '<div id="categoryMain' + iItem + 'wrap" style ="position:relative;">';


    //categoryscrlayer


    str += '<div id="category' + iItem + 'scrlayer" onmousewheel="return scrollerget(\'category' + iItem + '\').scroll(event.wheelDelta/2)">';


    str += '<div  id="category' + iItem + 'up"   style="display:none;" onmousedown="return scrollerget(\'category' + iItem + '\').scrollup();"' +
	 ' onmouseout="return scrollerget(\'category' + iItem + '\').stopscroll();" ' +
   ' onmouseup="return scrollerget(\'category' + iItem + '\').stopscroll();">';
    str += '</div>';


    //categorycontent
    str += '<div width="100%" id="category' + iItem + 'content"  onresize="checkcatcontentsize(' + iItem + ');" style ="z-index:500;">';
    str += '</div>';
    //categorydown
    str += '<div  id="category' + iItem + 'down"   style="display:none;" onmousedown="return scrollerget(\'category' + iItem + '\')' +
	 '.scrolldown();" onmouseout="return scrollerget(\'category' + iItem + '\').stopscroll();" ' +
   ' onmouseup="return scrollerget(\'category' + iItem + '\').stopscroll();">';
    str += '</div>';
    str += '</div>'; // for categoryscrolayer

    // some  wrap1 around
    //str += '<div id="category'+  iItem +'wrap1" style ="position:relative;">'; 

    //str +=  '</div>'; // for wrap

    //str +=  '<div  id="categscrhold' + iItem + 'hight" height="80%"> &nbsp;</div>'; 

    // some wrap2 here
    //str += '<div id="category'+  iItem +'wrap2"  style ="position:relative;">';

    // str +=  '</div>'; // for wrap

    str += '</div>'; // for main wrap
    str += '</div>';    //'text'+ iItem+ '</div>';
    str += '<div width="100%" ID="cdiv' + iItem + '" STYLE="display:none">';
    str += '</div>';
    str += '</li>';

    //    var fileref=document.createElement('script');
    //  fileref.setAttribute("type","text/javascript");
    //  fileref.nodeValue='alert("category' + iItem +   'scroller ");  var category' + iItem +   'scroller=new scroller("category' + iItem +   '",200);';

    //	
    //	// document.write('<scr' + 'ipt language="javas' + 'cript" >alert("category' + iItem +   'scroller ");  var category' + iItem +   'scroller=new scroller("category' + iItem +   '",200); ' + '</scr' + 'ipt>');
    //	document.getElementsByTagName("head")[0].appendChild(fileref);
    return str;
}

function MenuItemHTMLType(iItem) {

    idx = iItem;
    var title = aMenuItemType[idx].Text;
    var menuitemid = aMenuItemType[idx].Id;
    text = aMenuItemType[idx].Text;
    iLevel = 1;
    iLinkId = aMenuItemType[idx].LinkId;
    iLinkIndex = iLinkId;

    sCSSClass = 'menuLevel' + 0;

    sHRef = '<A id="cn' + iItem + '" name="cn' + iItem + '" class="CategoryTop" href="javascript: TypeClick(' + iItem + ')" ';

    sHRef += ' onMouseOver="return sSts(this);"';
    sHRef += ' onMouseDown="return sSts(this);"';
    sHRef += ' onMouseUp="return cSts();"';
    sHRef += ' onMouseOut="return cSts();"';
    sHRef += ' title="Click to view ' + title + '">';


    sHRef += text;

    sHRef += '</a>';

    sMenu = '<li ';
    sMenu += ' STYLE="display:block"'
    sMenu += ' class="' + sCSSClass + '" >';



    sMenu += '<span>' + sHRef;
    if (aMenuItemType[iItem].IsNode == 1) {
        sMenu += '<ul id="cndiv' + iItem + '" style="display:none;"></ul>';
    }

    sMenu += '</span></li>';
    //alert(sMenu);

    return sMenu;
}


function MenuItemHTMLTypeNew(iItem) {

    idx = iItem;
    var title = aMenuItemType[idx].Text;
    var length = aMenuItemType.length - 1;
    var menuitemid = aMenuItemType[idx].Id;
    var catType = aMenuItemType[idx].Id;
    text = aMenuItemType[idx].Text;
    iLevel = 1;
    iLinkId = aMenuItemType[idx].LinkId;
    iLinkIndex = iLinkId;

    sCSSClass = 'menuLevel' + 0;

    //sHRef = '<A id="cn' + iItem + '" name="cn' + iItem + '" class="CategoryTop" href="javascript: TypeClick(' + iItem + ')" ' ;
    sHRef = '<A id="cn' + iItem + '" name="cn' + iItem + '" class="CategoryTop" href="javascript: top.CatMenuClick(' + iItem + ', ' + length + ', ' + catType + ');" ';

    sHRef += ' onMouseOver="return sSts(this);"';
    sHRef += ' onMouseDown="return sSts(this);"';
    sHRef += ' onMouseUp="return cSts();"';
    sHRef += ' onMouseOut="return cSts();"';
    sHRef += ' title="Click to view ' + title + '">';

    sHRef += '<div id="divb' + iItem + '" class="CategoryButtonTop">';
    sHRef += text;
    sHRef += '</div>';
    sHRef += '</a>';

    sMenu = '<li ';
    sMenu += ' STYLE="display:block"'
    sMenu += ' class="' + sCSSClass + '" >';



    sMenu += '<span>' + sHRef;
    if (aMenuItemType[iItem].IsNode == 1) {
        sMenu += '<ul id="cndiv' + iItem + '" style="display:none;"></ul>';
    }
    sMenu += '</span>';
    //sMenu += '</span></li>';
    //alert(sMenu);

    return sMenu;
}

function TypeClick(Type) {
    Type = aMenuItemType[Type].Id;
    neotekscript('/catalog/menu/menuajax.aspx?Type=' + Type);
}

function TypeClickNew(ItemCat, CatType) {
    var elem = 'catHolder' + ItemCat;
    if (document.getElementById(elem).getAttribute('loading') < 1) {
        showcatprocessing(ItemCat);
        //upload new content

        if (document.getElementById('concertina') != null) {
            if (typeof (top.menuArray[ItemCat]) == 'undefined') {
                showcatprocessing(ItemCat);
                neotekscript('/catalog/menu/menuajax.aspx?Type=' + CatType + '&containerId=' + ItemCat);
                //alert ( document.getElementById('categorycontent').innerHTML);				   
                document.getElementById(elem).loading = 1;
                uploadNewCat = 1; // needs to bild new menu
                //hideprocessing();
            }
        }
        else {
            neotekscript('/catalog/menu/menuajax.aspx?Type=' + CatType + '&containerId=' + ItemCat);
            //alert ( document.getElementById('categorycontent').innerHTML);				   
            document.getElementById(elem).loading = 1;
            uploadNewCat = 1; // needs to bild new menu
            //hideprocessing();
        }


    }
}
function showcatprocessing(Type) {
    if (ProcessingTimeout != null)
        window.clearTimeout(ProcessingTimeout);
    try {
        document.getElementById('processing' + Type + 'cat').style['display'] = "block";
    } catch (e) {
    }
    ProcessingTimeout = setTimeout(hidecatprocessing, 5000)
}
function hidecatprocessing(Type) {
    window.clearTimeout(ProcessingTimeout);
    ProcessingTimeout = null;
    try {
        if (document.getElementById('concertina') != null) {
            var o = document.getElementById('processing' + Type + 'cat');
            if (o) { o.style.display = "none"; }

            var elem2 = 'category1scrlayer';
            var allHeights = pixel(225 + (19 * scrollerArray.length));
            resizeElement('category');
            var hh = scrollerHeight(elem2, allHeights);
        }
        else {
            document.getElementById('processing' + Type + 'cat').style['display'] = "none";
        }

    } catch (e) {
    }
}
function CatMenuClick(ItemCat, nn, CatType) {
    var elem = '';
    //alert(ItemCat+' '+ nn+' '+CatType);
    goCategoryBottom = 0;
    goCategoryTop = 0;
    // hide all other  holders 
    for (var ix = 1; ix < nn + 1; ix++) {
        elem = 'catHolder' + ix;
        document.getElementById(elem).className = 'CatMenuHide';
    }
    // show only click one
    elem = 'catHolder' + ItemCat;
    document.getElementById(elem).className = 'CatMenuShow';

    TypeClickNew(ItemCat, CatType);
    var elem2 = 'category' + ItemCat + 'scrlayer';
    curCatMenu = 'category' + ItemCat;
    curCatMenuId = ItemCat;
    //var hh = scrollerArray[Type].scrollerHeight();  
    var allHeights = pixel(document.getElementById('cn1').offsetHeight) * scrollerArray.length;
    resizeElement('category');
    var hh = scrollerHeight(elem2, allHeights);

    //document.getElementById(elem2).style['height']=hh; 

}


function scrollerHeight(name, offsetHeight) {
    var vheight = 500;
    if (document.documentElement != null) {
        vheight = pixel(document.documentElement.clientHeight);
    } else {
        vheight = pixel(window.innerHeight);
    }
    vheight = vheight - pixel(document.getElementById('toolbar').offsetHeight);
    vheight = vheight - pixel(document.getElementById('categorytop').offsetHeight);
    vheight = vheight - pixel(document.getElementById('categorybottom').offsetHeight);
    vheight = vheight - offsetHeight + 'px';
    document.getElementById(name).style['height'] = vheight;
    return vheight;
}



function checkcatcontentsize(numcat) {

    var divcon = document.getElementById('category' + numcat + 'content');
    var contentHeight = pixel(divcon.offsetHeight);
    var divscr = document.getElementById('category' + numcat + 'scrlayer');
    var scrlayerHeight = pixel(divscr.offsetHeight);
    // alert ('goCategoryBottom ' + goCategoryBottom + ' goCategoryTop '+  goCategoryTop ); 
    if (contentHeight > scrlayerHeight) {
        document.getElementById(top.curCatMenu + 'down').style['display'] = 'block';
        goCategoryBottom += 1;
    }
    else {
        document.getElementById(top.curCatMenu + 'down').style['display'] = 'none'; goCategoryBottom = 0;
    }
    return null;
}

function ShowHideLeftPanel(wcat, wInfo, catHide) {
    // sit on skin for RYCO (GUD)			 
    var w2 = pixel(document.getElementById('category').style['width']);
    //javascript:alert(top.InfoFrame.location.href);


    var x = top.InfoFrame.location.href;
    var len = x.length - 24;
    var y = x.substring(0, len);
    var ylen = y.length;
    var z = x.substring(ylen);
    if ((z == 'EditContent.aspx?Id=2010') || (z == 'EditContent.aspx?Id=2020') || (z == 'EditContent.aspx?Id=2030') || (z == 'EditContent.aspx?Id=2040') || (z == 'EditContent.aspx?Id=2050')
		 || (z == 'EditContent.aspx?Id=2060') || (z == 'EditContent.aspx?Id=1010') || (z == 'EditContent.aspx?Id=1020') || (z == 'EditContent.aspx?Id=1030') || (z == 'EditContent.aspx?Id=1035')
		 || (z == 'EditContent.aspx?Id=1040') || (z == 'EditContent.aspx?Id=1050') || (z == 'EditContent.aspx?Id=1060') || (z == 'EditContent.aspx?Id=1070') || (z == 'EditContent.aspx?Id=3010')
		 || (z == 'EditContent.aspx?Id=2020') || (z == 'EditContent.aspx?Id=3030') || (z == 'EditContent.aspx?Id=3040') || (z == 'EditContent.aspx?Id=4010') || (z == 'EditContent.aspx?Id=4020')
		 || (z == 'EditContent.aspx?Id=4030') || (z == '/EditContent.aspx?Id=171')) catHide = 1; // for last one we need '/' --have less charecters
    if ((z == 'ContentPage.aspx?Id=2010') || (z == 'ContentPage.aspx?Id=2020') || (z == 'ContentPage.aspx?Id=2030') || (z == 'ContentPage.aspx?Id=2040') || (z == 'ContentPage.aspx?Id=2050')
		 || (z == 'ContentPage.aspx?Id=2060') || (z == 'ContentPage.aspx?Id=1010') || (z == 'ContentPage.aspx?Id=1020') || (z == 'ContentPage.aspx?Id=1030') || (z == 'ContentPage.aspx?Id=1035')
		 || (z == 'ContentPage.aspx?Id=1040') || (z == 'ContentPage.aspx?Id=1050') || (z == 'ContentPage.aspx?Id=1060') || (z == 'ContentPage.aspx?Id=1070') || (z == 'ContentPage.aspx?Id=3010')
		 || (z == 'ContentPage.aspx?Id=2020') || (z == 'ContentPage.aspx?Id=3030') || (z == 'ContentPage.aspx?Id=3040') || (z == 'ContentPage.aspx?Id=4010') || (z == 'ContentPage.aspx?Id=4020')
		 || (z == 'ContentPage.aspx?Id=4030')) catHide = 1;
    if (catHide == 1) {
        wInfo = wInfo + (wcat);
        document.getElementById('category').style['width'] = '0px';
    } else {
        document.getElementById('category').style['width'] = wcat + 'px';
    }
    document.getElementById('InfoFrame').style['width'] = wInfo + 'px';


}




