 var i;
 var t;
 var counter;
 var photo_count;

$(document).ready(function() {
	counter=2;
	photo_count=$(".portfolio_item").length;
	i=photo_count-8;
	t=i;

	setBigPhoto(counter);

	$(".arrow_u").empty();
	$(".arrow_u").append('<img src="images/arrow4_g.png" id="up" />');

	if(photo_count<8){
	$(".arrow_d").empty();
	$(".arrow_d").append('<img src="images/arrow4_g_d.png" id="up" />');
	}
}
);

function setBigPhotoObject(url,descr){
		$("#big_img").fadeOut(function () {

		$("#big_ph").addClass("loading");
		$("#big_ph").height($("#big_img").height());
		$("#big_ph").width($("#big_img").width());

        $("#big_img").load(function () {
			$("#big_img").fadeIn();
			$("#big_ph").removeClass("loading");
			$("#big_ph").height($("#big_img").height());
			$("#big_ph").width($("#big_img").width());
		}).error(function () {
		}).attr("src", url);
		$(".comment").empty();
		$(".comment").append(descr);
			}
		);
}

function go(where){
if(where=='next')
{
counter++;
if(counter>(prod_name.length-3))counter=2;
setBigPhoto(counter);
}
else
{
counter--;
if(counter<1)counter=prod_name.length-4;
setBigPhoto(counter);
}

}

function setBigPhoto(counter){

		$("#big_img").fadeOut(function () {
		$("#big_ph").addClass("loading");
		$("#big_ph").height($("#big_img").height());
		$("#big_ph").width($("#big_img").width());

        $("#big_img").load(function () {
			$("#big_img").fadeIn();
			$("#big_ph").removeClass("loading");
			$("#big_ph").height($("#big_img").height());
			$("#big_ph").width($("#big_img").width());
		}).error(function () {
		}).attr("src", prod_img[counter]);
		$("#center").empty();
		$("#center").append(prod_name[counter]);
		$("#left").empty();
		$("#left").append(prod_name[counter-1]);
		$("#right").empty();
		$("#right").append(prod_name[counter+1]);

		$("#center").attr('href','/object/'+prod_alias[counter]);
		$("#left").attr('href','/object/'+prod_alias[counter-1]);
		$("#right").attr('href','/object/'+prod_alias[counter+1]);

			}
		);
}


function justSlideVert(next){
	if(next==true){
		i++;
		if(i>0){
		$(".arrow_d").empty();
		$(".arrow_d").append('<a href="#" onclick="justSlideVert(false);return false;"><img src="/images/arrow_d.jpg" id="down"  /></a>');
		}

		if(i>=t){
		i=t;
		$(".arrow_u").empty();
		$(".arrow_u").append('<img src="/images/arrow4_g.png" id="down"  />');
		}

		$(".photo").animate({left: '+=91'}, 1000);
	}
	else
	{
		i--;
		if(i<t)
		{
		$(".arrow_u").empty();
		$(".arrow_u").append('<a href="#" onclick="justSlideVert(true);return false;"><img src="/images/arrow_u.jpg" id="down"  /></a>');
		}

		if(i<=0){
		i=0;
		$(".arrow_d").empty();
		$(".arrow_d").append('<img src="/images/arrow4_g_d.png" id="down"  />');
		}

	$(".photo").animate({left: '-=91'}, 1000);

	}
}

function setPhoto(id){
$('.foto_holder').empty();
$('.foto_holder').append('<img src="/images/loading.gif" />');
$('.foto_holder').load('/ajax_plan?id_photo='+id,'','');
}
