/**********************************************
                [-jCay.com-]
               [-JavaScript-]
***********************************************/

function id2name(id_name)
{
  if (document.getElementById(id_name))
    return document.getElementById(id_name);
  return 0;  
}

function countIds()
{
  for (var i = 0; i < 100; i++)
  {
    if (!id2name("button_visit_" + i))
      break;
    if (id2name("button_download_" + i))
      id2name("button_download_" + i).innerHTML = creats(0, i);
    if (id2name("button_visit_" + i))
      id2name("button_visit_" + i).innerHTML = creats(1, i);
  }
  return i;  
}

function creats(types, i)
{
  if (types == 1)
    return '<a href="' + jslines[1][i] + '" target="_blank">' + '<img src="./data/images/visit-button.gif" alt="VISIT">' + '</a>';  
  else
    return '<a href="' + jslines[0][i] + '" target="_blank">' + '<img src="./data/images/download-button.gif" alt="DOWNLOAD">' + '</a>';
}

function runJS()
{
  countIds();
}

jQuery(function($){
    
    var navigation = {
        next : function(id, type){
            if (typeof type == 'undefined') type = true;
            if ($('div div', id).length > 1){
                var nodes = $('div div.active', id);
                if (nodes.length){
                    for (var i = 0; i < nodes.length; i++)
                        nodes[i].className = 'item';
                    if (type){
                        var node = $(nodes[ nodes.length-1 ]);
                        var limit = 1;
                        if (!node.next().length){
                            node = $('div div:first', id).addClass('active');
                            limit = 0;
                        }
                        for (var i = 0; i < limit; i++){
                            if (node.next()){
                                node = node.next();
                                node.addClass('active');
                            }
                        }
                    }
                    else{
                        var node = $(nodes[0]);
                        var limit = 1;
                        if (!node.prev().length){
                            var list = $('div div', id);
                            node = $(list[ list.length-1 ]);
                            node.addClass('active');
                            if (list.length % 2) limit = list.length % 2 - 1;
                            else limit--;
                        }
                        for (var i = 0; i < limit; i++){
                            if (node.prev()){
                                node = node.prev();
                                node.addClass('active');
                            }
                        } 
                    }
                }
            }
            return false;
        },
        prev : function(id){ return navigation.next(id, false); }
    };
    $('.scroll-content ul.navigation .prev').click(function(){ return navigation.prev(this.parentNode.parentNode); });
    $('.scroll-content ul.navigation .next').click(function(){ return navigation.next(this.parentNode.parentNode); });
    window._navigation_ = navigation;
    
    var path = location.pathname.replace(/(\.html|\.htm|\/)$/, '');
    var prefix = 'http://' + location.hostname + (path ? path : '/index');
    $('div.also a').each(function(){
        this.href = prefix + '.jsp?q=' + Base64.encode(this.href);
        this.target = '_self';
    });
    
}); 

