var direct = 0;
var ii = 0;
var jj = 0; 
var count = 0;
var flag = true;
var podkastShowed = 0;

$().ready(function() {
	$('.light').lightBox();
	
/*	
	if ($('.spiridon_table').length > 0) {
		
		$(".spiridon_table").tablesorter({	
			sortList: [[0,0],[1,0]], 
			headers: { 
					   1: { sorter: "text"},
					   2: { sorter: "text"},
					   4: { sorter: "floating"},
					   5: { sorter: "floating"},
					 }
		});
	}		
*/	
	}
	
);

function checkCatalogForm()
{
	if (checkForm('catalog')) 
		return true;
	return false;
}


function showPodkastParent(id)
{
	document.getElementById("podkast_a_"+id).onclick();
	return false;
}
function showPodkast(t, id)
{
	if (t.className == "cur")
	{
		t.className = "";
		$('#podkast_'+id).hide();
	}
	else
	{
		podkastShowed = id;
		t.className = "cur";
		$('#podkast_'+id).show();
		$.post("/classes/ajax/showPodkast.php", {"pid" : id}, showPodkastAjax);
	}
	return false;
}
function SortTable(name, direct, id)
{
	$.post("/classes/ajax/showPodkast.php", {"order" : name,"direct" : direct, "pid" : id}, showPodkastAjax);
	return false;
}
function showPodkastAjax(a)
{
	$("#podkast_" + podkastShowed).html(a);
}

function mySlide (id, direct) {
	var i = 0;
	var clear = setInterval(function () {
		if (direct == 'right') {
			$(id).css({
				left: parseInt($(id).css("left")) - 4 + "px"
			});
		}
		else {
			$(id).css({
				left: parseInt($(id).css("left")) + 4 + "px"
			});
		}
		i += 4;
		if (i >= 60) {
			clearInterval(clear);
		}
	}, 10);
}

function moveRight (num) {
	if (flag) {
		flag = false;
		if (ii == undefined) {
			ii = $("#slides-in"+num).children().length;
		}
		if (ii > 9) {
			mySlide("#slides-in"+num, 'right');
			$("#prev-disabled_"+num).css({
				background: "transparent url(/css/images.png) no-repeat scroll 100% -144px"
			});
			--ii;
			++jj;
			if (ii == 9) {
				$("#next-disabled_"+num).css({
					background: "transparent url(/css/images.png) no-repeat scroll 100% -216px"
				});
			}
		}
		else {
			$("#next-disabled_"+num).css({
				background: "transparent url(/css/images.png) no-repeat scroll 100% -216px"
			});
		}
	}
	flag = true;
return false;
}

function moveLeft (num) {
	if (flag) {
		flag = false;
		if (jj > 0) {
			mySlide("#slides-in"+num, 'left');
			$("#next-disabled_"+num).css({
				background: "transparent url(/css/images.png) no-repeat scroll 100% -288px"
			});
			++ii;
			--jj;
			if (jj == 0) {
				$("#prev-disabled_"+num).css({
					background: "transparent url(/css/images.png) no-repeat scroll 100% -72px"
				});
			}
		}
		else {
			$("#prev-disabled_"+num).css({
				background: "transparent url(/css/images.png) no-repeat scroll 100% -72px"
			});
		}
	}
	flag = true;
return false;
}

function showPicture(id, num)
{
	//удаляем старую картинку
	gebi("pictureAlt_"+num).innerHTML = "";
	gebi("pictureSrc_"+num).src = "";
	
	//Показываем блок с навигаций для определенного альбома
	$("#pictureCtr_" + num).show();
		
	//вставляем номер картинки по счету
	$("#pictureNum_" + num).text(gebi("pictureIteration_"+id).value);
	
	//Проверяем сслыку "предыдущая"
	if (gebi("pictureIteration_"+id).value == 1)
		$("#prevLink_" + num).addClass("disable");
	else
		$("#prevLink_" + num).removeClass("disable");
		
	//Проверяем сслыку "следующая"
	if (gebi("pictureIteration_"+id).value == gebi("pictureAllNum_"+num).innerHTML)
		$("#nextLink_" + num).addClass("disable");
	else
		$("#nextLink_" + num).removeClass("disable");
		
	//делаем картинку отмеченной в ленте
	if (gebi("pictureNowView_" + num).value != 0) 
		$("#miniPhotoWrapper_" + gebi("pictureNowView_" + num).value).removeClass("bit-cur");
		
	$("#miniPhotoWrapper_" + id).addClass("bit-cur");
	gebi("pictureNowView_" + num).value = id;
	
	//Удаляем старую картинку и вставляем новую
	gebi("pictureAlt_"+num).style.display = "block";
	gebi("pictureAlt_"+num).innerHTML = '<span class="str">' + gebi("pictureAltImage_" + id).value + '</span>';
	gebi("pictureSrc_"+num).style.display = "block";
	gebi("pictureSrc_"+num).src = "/images/" + gebi("pictureFullImage_" + id).value;
	
	return false;
}
function showNextPicture(num)
{
	lastNum = 1+ 1*gebi("pictureNum_" + num).innerHTML;
	if (lastNum < 1*gebi("pictureAllNum_"+num).innerHTML+1)
		return showPicture(gebi("pictureIterationReverse_" + num + "_" + lastNum).value, num);
	return false;
}
function showPrevPicture(num)
{
	lastNum = 1*gebi("pictureNum_" + num).innerHTML - 1;
	if (lastNum > 0)
		return showPicture(gebi("pictureIterationReverse_" + num + "_" + lastNum).value, num);
	return false;
}
function galleryClose(num)
{
	$("#pictureCtr_" + num).hide();
	gebi("pictureAlt_"+num).style.display = "none";
	gebi("pictureSrc_"+num).style.display = "none";
	return false;
}
function showVideo(id)
{
	if (gebi("video_"+id).style.display == "none")
	{
		$("#video_"+id).slideDown();
		$("#video_wrap_"+id).addClass("cur");
	}
	else
	{
		$("#video_"+id).slideUp();
		$("#video_wrap_"+id).removeClass("cur");
		
	}
	return false;
}

function gebi(id)
{
	return document.getElementById(id);
}
function setPictureInBlock(num, id){
//	$("#pictureNum_" + num).text($("#pictureIteration_"+id));
}

function showFaqQuestion(id)
{
	if (gebi("question_answer_" + id).style.display == "none") 
	{
		$("#question_" + id).addClass("q-cur");
		$("#question_answer_" + id).slideDown();
	}
	else
	{
		$("#question_" + id).removeClass("q-cur");
		$("#question_answer_" + id).slideUp();
		
	}
	return false;
}

function showArticle(id)
{
	if (document.getElementById("article_" + id).style.display == "none") 
		$("#article_" + id).slideDown();
	else
		$("#article_" + id).slideUp();
	return false;
}

function checkFaq()
{
	str = checkForm('faq');
	if (str) 
		$.post("/classes/ajax/sendFaq.php", str, sendSuccessFaqForm);
	return false;
}
function sendSuccessFaqForm()
{
//	$("fieldset").hide();
	document.forms[0].reset();
	$("#alert-faq").hide();
	$("#success-faq").show();
}
function checkForm(name)
{
	flag = true;
	str = {};
	$('.need-' + name).each(function()	{
		if (this.value == "") 
		{
			flag = false;
			this.parentNode.className = "alert";
		}
		else 
			this.parentNode.className = "";
	});
	if (flag)
	{
		$(".need-"+name).each(function()
		{
			str[this.name] = this.value;
		});
		$(".not-need-"+name).each(function()
		{
			str[this.name] = this.value;
		});
		$("#error-"+name).hide();
		return str;
	}
	else
	{
		$("#error-"+name).show();
		return false;
	}
	return false;
}

var lineSelect = new Array(0,0,0,0);

/*линии гранулирования*/
function showLine(line, id)
{
	if (lineSelect[line - 2]) 
	{
		for (i = line; i < 6; i++) {
			lineSelect[i - 1] = 0;
			$("#line" + (i + 1)).hide();
		}
		$('.itogi').hide();
		$('#name_'+lineSelect[line-2]).removeClass("cur");
		$('#desc_'+lineSelect[line-2]).hide();
	}
	
	$("#line"+line).show();
	$('.line'+line+"desc").hide();
	$('.line'+line+"names").hide();
	$('.line'+line+"name_"+id).show();
	
	lineSelect[line-2] = id;
	$('#name_'+id).addClass("cur");
	$('#desc_'+id).show();
	return false;
}
function showItog(id)
{
	if (lineSelect[3]) 
	{
		$('#desc_' + lineSelect[3]).hide();
		$('#name_' + lineSelect[3]).removeClass("cur");
		$('#itog_' + lineSelect[3]).hide();
	}
	lineSelect[3] = id;
	$('.desc_' + id).show();
	$('.name_' + id).addClass("cur");
	$('#itog_' + id).show();
	return false;
}
function showItogData(num, id)
{
	if (document.getElementById("itog_data_" + num + "_" + id).style.display == "none") {
		document.getElementById("itog_data_" + num + "_" + id).style.display = "block";
		document.getElementById("sver_itog_data_" + num + "_" + id).style.display = "block";
	}
	else {
		document.getElementById("itog_data_" + num + "_" + id).style.display = "none";
		document.getElementById("sver_itog_data_" + num + "_" + id).style.display = "none";
	}
	return false;
}

function showDesc(line, id)
{
	if (lineSelect[line-1] == 0)
		$("#desc_"+id).show();
	else
		return false;
}
function hideDesc(line, id)
{
	if (lineSelect[line-1] == 0)
		$("#desc_"+id).hide();
	else
		return false;
}











