// JavaScript Document

var currentItemId = "0";

function objMove (objId, leftPx) {
	$("#"+objId).animate({
		left: leftPx+'px'
	}, 1200 );
}

$(document).ready(function() {
	setTimeout("objMove('g_1', '380')", 0);
	setTimeout("objMove('g_2', '470')", 300);
	setTimeout("objMove('g_3', '560')", 600);
	setTimeout("objMove('g_4', '660')", 900);
	setTimeout("objMove('g_5', '760')", 1200);
	setTimeout("slideGallery('4')", 2400);
});

function removeIndex (itemId) {
	$("#"+itemId).css({ 'z-index': '0' });
}

function resetSize() {
		$("#g_1").animate({
			width: "70px",
			height: "146px",
			top: "50px",
			left: "360px"
		}, 420, function() {
			removeIndex("g_1");
		});
		$("#g_2").animate({
			width: "70px",
			height: "146px",
			top: "50px",
			left: "250px"
		}, 440, function() {
			removeIndex("g_2");
		});
		$("#g_3").animate({
			width: "70px",
			height: "146px",
			top: "50px",
			left: "130px"
		}, 460, function() {
			removeIndex("g_3");
		});
		$("#g_4").animate({
			width: "70px",
			height: "146px",
			top: "50px",
			left: "10px"
		}, 480, function() {
			removeIndex("g_4");
		});
		$("#g_5").animate({
			width: "70px",
			height: "146px",
			top: "50px",
			left: "-110px"
		}, 500, function() {
			removeIndex("g_5");
		});




}

function defaultSize (itemId, widthPx, heightPx) {
	$("#"+itemId).animate({
		width: widthPx+"px",
		height: heightPx+"px",
		top: "40px"
	}, 300 );
}

function addSize (itemId, widthPx, heightPx) {
	var leftPx = parseFloat($("#"+itemId).css('left'));
	var leftSetup = leftPx - 230;
	$("#"+itemId).css({ 'z-index': '40' });
	$("#"+itemId).animate({
		width: widthPx+"px",
		height: heightPx+"px",
		top: "23px",
		left: leftSetup+"px"
	}, 300 );
}

// Соседи (1, 4)

function moveNeighbor (neighbor, selected) {
	
	if (neighbor <= 5) {	
		if (neighbor < selected) {
			moveLeftNeighbors(neighbor);
		} else if (neighbor > selected) {
			moveRightNeighbors(neighbor);
		}
		neighbor = neighbor + 1;
		moveNeighbor(neighbor, selected);
	}
}

// Подвинуть левых соседей
		function moveLeftNeighbors(neighbor) {
			
			
			var neighborLeftPx = parseFloat($("#g_"+neighbor).css('left'));
			neighborLeftPx = neighborLeftPx - 50;
			$("#g_"+neighbor).animate({
				left: neighborLeftPx+"px"
			}, 300 );
		}
		
// Подвинуть правых соседей
		function moveRightNeighbors(neighbor) {
			
			var neighborRightPx = parseFloat($("#g_"+neighbor).css('left'));
			neighborRightPx = neighborRightPx + 70;
			$("#g_"+neighbor).animate({
				left: neighborRightPx+"px"
			}, 300 );			
		}
		
// Устанавливаем текущий элемент

function slideGallery (itemId) {
	
	
	
	if (itemId == currentItemId) {
		alert("Current");
	} else {
	
			//resetSize();
					
			if (itemId == "1") { 
				$("#gallery_container").animate({ 
					left: "390px" 
				}, 1100, function (){
					//changeText('Стенды');
					//setLink("service_outdoor_info.html");
					//addSize("g_"+itemId, "169", "360");
					var currentItemId = itemId;
				});
			} else if (itemId == "2") {
				$("#gallery_container").animate({ 
					left: "135px" 
				}, 1100, function (){
					//changeText('Объемные буквы');
					//setLink("service_outdoor_bukv.html");
					//addSize("g_"+itemId, "215", "360");
					var currentItemId = itemId;
				});
			} else if (itemId == "3") {
				$("#gallery_container").animate({ 
					left: "-30px" 
				}, 1100, function (){
					//changeText('Крышные установки');
					//setLink("service_outdoor_krish.html");
					//moveNeighbor (1, itemId);
					//addSize("g_"+itemId, "242", "360");
					var currentItemId = itemId;
				});
			} else if (itemId == "4") {
				$("#gallery_container").animate({ 
					left: "-230px"
				}, 1100, function (){
					//changeText('Витрины');
					//setLink("service_vitrini.html");
					//moveNeighbor (1, itemId);
					//addSize("g_"+itemId, "252", "360");
					var currentItemId = itemId;
				});
			} else if (itemId == "5") {
				$("#gallery_container").animate({ 
					left: "-370px"
				}, 1100, function (){
					//changeText('Штендеры');
					//setLink("service_outdoor_shtender.html");
					//addSize("g_"+itemId, "122", "360");
					var currentItemId = itemId;
				});

			} 
	}
		
}

/// Text Bubble




$(document).ready(function() {
});










