    var selectedCat = 0;
    
    // Apple detection object
    var Apple = {};
    Apple.UA = navigator.userAgent;
    Apple.Device = false;
    Apple.Types = ["iPhone", "iPod", "iPad"];
    for (var d = 0; d < Apple.Types.length; d++) {
        var t = Apple.Types[d];
        Apple[t] = !!Apple.UA.match(new RegExp(t, "i"));
        Apple.Device = Apple.Device || Apple[t];
    }
    

    
    $("document").ready(function() {
        $(".catNav").click(function(){
            catID = ".cat"+$(this).attr("catID");
			//test = "#nav"+$(this).attr("catID");
            if (selectedCat != catID) {	
				
                highlight($(this).attr("catID"));
                selectedCat = catID;
            } else {
                highlight(0);
                selectedCat = 0;
            }
        });
        
         //$("#AK").css({"position":"fixed"}); //ivan
         //$("#navigation").css({"position":"fixed"}); //ivan
		 //$(catID).css({"color":"#bf1e2e"});
		// document.getElementByID("nav3")style.visibility = 'hidden';

    });
    
    $(window).resize(function() {
        redraw();
    });
    
    function redraw() {
        w = $(window).width();
        h = $(window).height() - 175;
        if (h<200) h = 200;
        tmpX = 30;
        tmpY = 0;
        $('#links div').each(function(intIndex, element){
            tmp = tmpY + $(this).height();
            if (tmp>h) {tmpY=0; tmpX+=240;}
            $(this).css({top:tmpY+'px', left:tmpX+'px'});
            tmpY += $(this).height();
            $(this).show();
		});
		if (Apple.Device)  {
		    $('#links').width(tmpX+240);
		    setTimeout(function() { window.scrollTo(0, 1) }, 100);
		}
    }
    
        
    function highlight(ID) {
	
        $('div').each(function(intIndex, element){
            removeAllClass($(this).find("a"));
            if(ID==0) {
                $(this).find("a").addClass("cat"+$(this).attr("catID"));
            } else if($(this).attr("catID")==ID) {
                $(this).find("a").addClass("highlight"+ID);
            } else {
                $(this).find("a").addClass("downlight"+$(this).attr("catID"));
            }
		});
    }
    
    function removeAllClass(e) {
                    e.removeClass("cat2");
            e.removeClass("highlight2");
            e.removeClass("downlight2");
                    e.removeClass("cat3");
            e.removeClass("highlight3");
            e.removeClass("downlight3");
                    e.removeClass("cat4");
            e.removeClass("highlight4");
            e.removeClass("downlight4");
                    e.removeClass("cat5");
            e.removeClass("highlight5");
            e.removeClass("downlight5");
            }
