﻿var done = true;
var slider_timer;
var next_slide_delay = 4000;
var slide_count = 0;

function home_slider() {
    id = 1;
    $("#feature .slideimg").each(function() {
        $(this).attr("rel", id++);
        $(this).mouseover(function() {
            $("#feature .slideimg").each(function() {
                $(this).removeClass('hovering');
            });
            $(this).addClass('hovering');
            try { clearTimeout(loader); } catch (ex) { }
            loader = setTimeout('load_slide();', 100);
        });
        slide_count++;
    });
    id = 1;
    $("#featurecontent section").each(function() {
        $(this).attr("id", "section" + id++);
    });
    $("#feature .slide1").addClass('hovering');
    load_slide();
    slider_timer = setTimeout('next_slide()', next_slide_delay);
}

function load_slide() {
    clearTimeout(slider_timer);
    $("#featurecontent section").each(function() {
        $(this).hide();
    });
    $("#feature .slideimg").each(function() {
        if ($(this).hasClass('hovering')) {
            $("#section" + $(this).attr("rel")).fadeIn('slow');
        }
    });
    slider_timer = setTimeout('next_slide()', next_slide_delay);
}

function next_slide() {
    $("#feature .slideimg").each(function() {
        current_slide = 0;
        if ($(this).hasClass('hovering')) {
            current_slide = parseInt($(this).attr("rel"));
            $(this).removeClass('hovering');
            next_id = (current_slide == slide_count) ? 1 : current_slide + 1;
            $("#slidebtn" + next_id).addClass('hovering');
            load_slide();
            return false;
        }
    });
}

AddBodyOnload('home_slider()');

var opened_tab = 0;
var total_tabs = 0;
var tabs_timer = null;
function setup_tabs() {
    id = 1;
    $("#servicestabs ul li a").each(function() {
        $(this).attr("rel", id++);
        $(this).mouseover(function() {
            rel = parseInt($(this).attr("rel"));
            opened_tab = rel;
            clearTimeout(tabs_timer);
            tabs_timer = setTimeout('reload_tabs();', 50);
        });
        total_tabs++;
    });
    id = 1;
    $("#services section").each(function() {
        $(this).attr("rel", id++);
    });
}
function reload_tabs() {
    //console.debug('reload with ' + opened_tab);
    for (i = 1; i <= total_tabs; i++) {
        if (i == opened_tab) {
            $("#btab-" + i).addClass("currenttab");
            $("#tabs-" + i).fadeIn('fast');
        } else {
            $("#btab-" + i).removeClass("currenttab");
            $("#tabs-" + i).hide();
        }
    }
}
AddBodyOnload('setup_tabs()');


function setup_home_clients() {
    $('#slider').vTicker({
        speed: 700,
        pause: 7000,
        animation: 'fade',
        mousePause: true,
        showItems: 1    
    });
}

AddBodyOnload('setup_home_clients()');


