function showPic( theid, dir )
{
	//afla care este poza curent
	h     = $('#'+theid);
	tfoto = $(h).children('.poza');
	nfoto = false;
	pfoto = false;
	for( i=0; i<tfoto.length; i++ )
	{
		if( $(tfoto[i]).attr('class') == "poza curenta" )
		{
			if(i>0) pfoto = i-1;
			cfotopoz = i;
			if(i<tfoto.length-1) nfoto = i+1;
		}
	}
	//verifica daca exista poza dorita
	canShow = false;
	if( dir == "next" && nfoto >=0 ) canShow = nfoto;
	if( dir == "prev" && pfoto >=0 ) canShow = pfoto;
	//arata poza daca este pozibil
	if( canShow!==false )
	{
		//ascunde poza curenta
		$(tfoto[cfotopoz]).removeClass('curenta');
		$(tfoto[cfotopoz]).animate({opacity: 0},250);
		setTimeout('$(tfoto['+cfotopoz+']).hide()',250);
		//arata noua poza
		$(tfoto[canShow]).addClass('curenta');
		setTimeout('$(tfoto['+canShow+']).show()',250);
		$(tfoto[canShow]).animate({opacity: 0},250)
						.animate({opacity: 1},250);
	}
	setTimeout('refreash_caseta_foto( "'+theid+'" )',50);
}
function refreash_caseta_foto( theid )
{
	h  = $('#'+theid);
	//ia totalul de poze
	hasPrev = false;
	hasNext = false;
	tfoto = $(h).children('.poza');
	for( i=0; i<tfoto.length; i++ )
	{
		if( $(tfoto[i]).attr('class') == "poza curenta" ){
			if(i>0) hasPrev = true;
			cfoto = i+1;
			if(i<tfoto.length-1) hasNext = true;
		}
	}
	hc = $(h).children('.caseta_foto_nav').children('.counter_holder');
	$(hc).children('.counter_foto').html(cfoto+" din "+tfoto.length);
	next_arrow = $(hc).children('.next_arrow');
	prev_arrow = $(hc).children('.prev_arrow');
	$(next_arrow).removeClass('arrow_dr_gri');
	$(prev_arrow).removeClass('arrow_st_gri');
	$(next_arrow).removeClass('arrow_dr_rosu');
	$(prev_arrow).removeClass('arrow_st_rosu');
	if( hasPrev ) $(prev_arrow).addClass('arrow_st_rosu');
	else $(prev_arrow).addClass('arrow_st_gri');
	if( hasNext ) $(next_arrow).addClass('arrow_dr_rosu');
	else $(next_arrow).addClass('arrow_dr_gri');
		
}
function init_caseta_foto( theid )
{
	h  = $('#'+theid);
	tfoto = $(h).children('.poza');
	if( tfoto.length <= 1 ) return false;
	$(h).append('<div style="overflow:hidden; width:126px" class="caseta_foto_nav"><div style="background:url(images/design/articol/ca_st.png) no-repeat; width:8px; height:18px; float:left; overflow:hidden"></div><div class="counter_holder" style="width:110px; border-top:1px solid #DDDDDD; height:13px; float:left; padding-top:5px; overflow:hidden"><div class="next_arrow"></div><div align="center" class="counter_foto">loading</div><div class="prev_arrow"></div></div><div style="background:url(images/design/articol/ca_dr.png) no-repeat; width:8px; height:18px; float:left; overflow:hidden"></div></div>');
	hc = $(h).children('.caseta_foto_nav').children('.counter_holder');
	next_arrow = $(hc).children('.next_arrow');
	prev_arrow = $(hc).children('.prev_arrow');
	$(next_arrow).click(function (){
		showPic(theid,'next');
	});
	prev_arrow.click(function (){
		showPic(theid,'prev');
	});
	refreash_caseta_foto( theid );
}