﻿

  function is_array(input){
    return typeof(input)=='object'&&(input instanceof Array);
  }

function ProcessNode(arNode){
    
    if(!is_array(arNode))
        arNode = [arNode];
    
    
    var htmlNode = '<ul>';
    
        for(var i = 0; i < arNode.length; i++){
            var url = '/Catalog-' + arNode[i].Name.replace(/[^a-zA-Z0-9]/g, '') + '_'+arNode[i].CategoryId+'.aspx';
            
			htmlNode += '<li><div><a href="'+url+'">'+arNode[i].Name+'</a></div>';
        
            if(arNode[i].Menu != undefined){
                htmlNode += ProcessNode(arNode[i].Menu);
                htmlNode += '<img src="/rarrow.gif" alt="" />';
            };
        
            htmlNode += '</li>';
            
        }
    htmlNode += '</ul>';
    
    return htmlNode;
}

$(function(){

    var htmlMenu = ProcessNode(Categories.Menus.Menu);
    $('#catcont').html(htmlMenu);
    
    $('#catcont li').click(function(){
		document.location = $(this).children('div').children('a').attr('href');
    });
	
	$('#catcont ul li:last-child').css('border', 'none');
	
	
	$('#catcont ul ul').each(function(index, el){
		if($(el).children('li').length > 3)
			$(el).css('margin-top', '-30px');

		if($(el).children('li').length > 6)
			$(el).css('margin-top', '-60px');

		if($(el).children('li').length > 12)
			$(el).css('margin-top', '-120px');
			
	});
    
    $('#catcont ul li').bind('mouseover', function(){
        $(this).css('background-color', '#0066A6');
        $(this).children('div').children('a').css('color', '#ffffff');
        $(this).children('ul').show();
    
    }).bind('mouseout', function(){
        $(this).children('div').children('a').css('color', '#0066A6');
        $(this).css('background-color', '#ffffff');    
        $(this).children('ul').hide();
    
    });
    
   

});


