﻿var tabs;
var step = 0;
var imagerotation;

$(document).ready(function () {

	tabs = $("ul.tabs li a");
    tabs.mouseover(function () {
        selectTab($(this));
    });
	setTimeout("stepControl()", 2000);

	var imagerotation = $(".imagerotation");

	var i = rand(imagerotation.length);
	imagerotation.eq(i - 1).show();

});


function rand(n) {
	return (Math.floor(Math.random() * n + 1));
}


function rotateImage(index) {
    imagerotation.hide();
    index++;
    if (index >= imagerotation.size())
        index = 0;
    imagerotation.eq(index).show();    
    setTimeout("rotateImage(" + index + ")", 2000);
}

function stepControl() {
    step++;
    
    if (step >= 5) {
        step = 0;
        var i = tabs.index($(tabs).parent().children(".active"));
        i++;
        if (i >= tabs.size())
            i = 0;
        selectTab(tabs.eq(i));     
    }
    setTimeout("stepControl()", 2000);
}

function selectTab(element) {
    step = 0;
    tabs.removeClass("active");
    element.addClass("active");
    var i = tabs.index(element);
    var colors = ["f29400", "e2231a", "8b478b", "00507d", "009fd0", "bcc400", "ce1463"];
    $("ul.tabs").attr("style", "border-left-color:#" + colors[i] + ";");
    $(".box2 .b2t").html("<h1 style=\"color:#" + colors[i] + ";\">" + element.html() + "</h1>");
    $(".prod").attr("src", "/templates/pages/comp2/g/prod_" + (i + 1) + ".jpg");
    $(".tabdesc").html(element.attr("title"));
    Cufon.replace(".b2t h1", { fontFamily: 'nb' });
    Cufon.now();
}
