var preloadedImage = new Array();
	preloadedImage[0] = new Image();
	preloadedImage[0].src = "images/close.gif";
	preloadedImage[1] = new Image();
	preloadedImage[1].src = "images/cil.gif";

var scaleValues = new Array();
	scaleValues[0] = 33;
	scaleValues[1] = 153;
	scaleValues[2] = 283;
	scaleValues[3] = 403;
	scaleValues[4] = 523;
	scaleValues[5] = 643;
	scaleValues[6] = 773;
	scaleValues[7] = 893;

var interval;
var currentIndex = 1;
var photosCount = 0;
var delta = 0;

function animateScale(value, time)
{
	$(".progress-line").stop(true, true).animate( {width: value}, time );
	clearInterval(interval);	
}

function moveFrame(delta)
{
	currentIndex += delta;
	if ( currentIndex < 0 ) currentIndex = photosCount - 1;
	if ( currentIndex == photosCount ) currentIndex = 0;

	if ( delta == -1 )
		$next = $(".photos li.active").prev();
	else
		$next = $(".photos li.active").next();
	var cl = $next.find("img").attr("class");

	$(".photos li.active").removeClass("active");
	$(".photos img." + cl).parent().addClass("active");

	$(".describing .visible").removeClass("visible");
	$(".describing div:eq(" + currentIndex + ")").addClass("visible"); 	
}
	
$(document).ready(function(){

	// ----------------------- main page -------------------------------
	
	$(".contact-info").click(function(){
		$(".true-cil").fadeIn(350);
	});
	
	$(".cil-close").click(function(){
		$(this).parent().fadeOut(350);
	});
	
	$(".header ul a").hover(
		function() { 
			$ul = $(this).parent().parent();
			$li = $(this).parent();
			$li.addClass("over");
			var index = $ul.find("li").index($li);
			animateScale(scaleValues[index], 333);
		},
		function() {
			$(this).parent().removeClass("over");
			interval = setInterval( 'animateScale(0, 333)', 250 );
		}
	);
	
	$(".photos img").each(function(i){
		$(this).attr("class", i);
	});
	
	photosCount = $(".photos img").length;
	
	$(".slideshow-button").hover(
		function() {
			$(this).addClass("button-over");
		},
		function() {
			$(this).removeClass("button-over");
		}
	);

	$(".left-button").click(function(){
		delta = -1;
	});
	
	$(".right-button").click(function(){
		delta = 1;
	});
	
	if ($(".photos").length)
		$(".photos").jCarouselLite({
			btnPrev: ".left-button",
			btnNext: ".right-button",
			mouseWheel: true,
			speed: 200,
			visible: 3,
			easing: "jswing",
			beforeStart: function() { setTimeout( "moveFrame(" + delta + ")", 100 ); }
		});

	$(".photos img").click(function(){
		var index = $(this).attr("class");
		if ( index != currentIndex )
			if ( index == (currentIndex+1)%photosCount )
				$(".right-button").click();
			else
				$(".left-button").click();
	});
	
	$(".production ul li strong").click(function(){
		var num = $(this).attr("class");
		$(".window-" + num).fadeIn(350);
	});
	
	// ----------------------- inside pages -------------------------------
	
	$(".prevs .tab2").click(function(){
		if ( ! $(this).parent().hasClass("over") ) {
			$(".ml-visible").hide("fast").removeClass("ml-visible");
			$(".prevs .over").removeClass("over");
			
			var index = $(".prevs .tab").index($(this));
			$(".ml-" + index).show("fast").addClass("ml-visible");
			$(this).parent().addClass("over");
		}
	});
	
	$(".call-window").click(function(){
		$("." + $(this).attr("id") + "-window").fadeIn(350);
		return false;
	});
	
});
