// JavaScript Document

function show_submenu() {
    $(this).toggleClass('over');
    $(this).find('ul').css('top', ($(this).offset().top + 10) + 'px');
    return false;
}

function hide_submenu() {
    $(this).toggleClass('over');
    return false;
}

$(document).ready(function() {
    /* fix short page height */
    var container_height = $('.container').height();
    var available_height = $(window).height();
    if (container_height < available_height)
        $('.content-wrapper').height(available_height - 300 - 16 - 35);
    /* force open the menu on ie */
    $('#nav > li').mouseover(show_submenu);
    $('#nav > li').mouseout(hide_submenu);

    init_tables();
});

var timeout_id = null;

function init_tables() {
    var tables = $('.tabs-content .panel:visible table');
    $('.tabs-content .panel:visible .nav').empty();
    if(tables.length > 1)
        for(i=0; i<tables.length; i++)
            $('.tabs-content .panel:visible .nav').append('<a href="#'+i+'" onclick="return iter_tables('+i+')">'+(i+1)+'</a>');
    iter_tables(0);
}

function iter_tables(index) {
    if(timeout_id)
        clearTimeout(timeout_id);
    var tables = $('.tabs-content .panel:visible table');
    if(index == (tables.length))
        index = 0;
    tables.hide();
    tables.slice(index, index+1).show();
    var links = $('.tabs-content .panel:visible .nav a');
    links.removeClass('active');
    links.slice(index, index+1).addClass('active');
    timeout_id = setTimeout('iter_tables('+(index+1)+')', 5000);
    return false;
}

function show_item(w, i) {
    $('.tabs-content .panel').hide();
    $('.tabs-content .'+i).show();
    $('.tabs-wrapper .ttabs .tit a').removeClass('active');
    $(w).addClass('active');
    init_tables();
    return false;
}
function show_partners(w) {
    return show_item(w, 'partners');
}
function show_costumers(w) {
    return show_item(w, 'costumers');
}
function show_cases(w) {
    return show_item(w, 'cases');
}

