
//показываем картинку
function show_img(src,gall_id)
{
$(gall_id+" .image img").each(function(){if(src===$(this).attr("src")){$(this).fadeIn("slow"); if((""+$(this).attr("label")).length>1){$(gall_id+" p").text($(this).attr("label"));} }else {$(this).hide();}});
$(gall_id+" .numbers a").removeAttr("class");

}

function myGallery(gall_id)
{

$(gall_id+".image img").hide();
var img_n="0";
$(gall_id+" .image img").each(function(){
						img_n++;
						$(gall_id+" .numbers .num").append("<a href='javascript:void(0)' onclick='show_img(\""+$(this).attr("src")+"\",\""+gall_id+"\"); $(this).attr(\"class\",\"act\");'>"+img_n+"</a>");
						$(gall_id+" .numbers .n .num").css("width",((img_n)*33)+"px");
						});
//прячем стрелки если картинок мало
if(img_n>5)	{$(gall_id+" .left").show();$(gall_id+" .right").show();}else
{$(gall_id+" .left").hide(); $(gall_id+" .right").hide();}		
//--------------------------------------------------------			

$(gall_id+" .numbers a:first").click();

//кнопка влево
$(gall_id+" .right").click(function(){

				var l=""+(parseInt($(gall_id+" .numbers .n .num").css("left"))-70)+"px";
				if(parseInt($(gall_id+" .numbers .num").css("left"))-70 + parseInt($(gall_id+" .numbers .num").css("width"))<parseInt($(gall_id+" .numbers").css("width")))
				{
					var end=parseInt($(gall_id+" .numbers").css("width"))-parseInt($(gall_id+" .numbers .num").css("width"));
					$(gall_id+" .numbers .num").animate({left: (+end+"px")},500,function(){}); 
				}else	
				{
				$(gall_id+" .numbers .num").animate({left:l},500,function(){}); 
				}
				//alert("right");
				});

//кнопка вправо
$(gall_id+" .left").click(function(){
						var l=(parseInt($(gall_id+" .numbers .num").css("left"))+70)+"px";
						if((parseInt($(gall_id+" .numbers .num").css("left"))+70)>0)
				{
				$(gall_id+" .numbers .num").animate({left:"0"},500,function(){});
				}else{
						$(gall_id+" .numbers .num").animate({left:l},500,function(){}) 
						}
						});

}



/*программы*/
function init_pop(id_button, id_pop)
{
myGallery(id_pop);
//кнопка свадьбы
$(id_button).click(function(){
								$(id_pop).css("top","-400px");
								$(id_pop).animate({top:"200px"},1000);
});
//кнопка закрыть свадьбы
$(id_pop+" .close").click(function(){$(id_pop).animate({top:"1800px"},1000,function(){$(id_pop).css("top","-400px");  });});


						
						
//
var dis=0;
$(""+id_pop+" .ar-b").click(function(){
						//alert("1");
						//alert((parseInt($(".inner>p").css("top"))));
						
						if(((parseInt($(id_pop+" .inner>p").css("height"))+parseInt($(id_pop+" .inner>p").css("top")))>204)&&(dis==0))
						{
						dis=1;
						var pos=''+(parseInt($(id_pop+" .inner>p").css("top"))-50)+'px';
						//alert(pos);
						$( id_pop+" .inner>p").animate({top: pos},500, function(){dis=0;});						
						}
						return true;
						});
//$(id_pop+" .pop-txt .ar-b").click();
						
$(""+id_pop+" .pop-txt .ar-t").click(function(){
			//alert("x");
						if((parseInt($(id_pop+" .inner>p").css("top"))<0)&&(dis==0))
						{
						dis=1;
						var pos=''+(parseInt($(id_pop+" .inner>p").css("top"))+50)+'px';
						$(id_pop+" .inner>p").animate({top: pos},500,function(){dis=0;});						
						}
						});	
//$(id_pop+" .pop-txt .ar-b").click();
						
}
