	jQuery(document).ready(function() {
		
	/*status*/
		var status = {
			stat_27: 'Объект в продаже',
			stat_78: 'Построенный объект',
			stat_79: 'Перспективный проект'
		}

		/*gallery main*/	
		$('.mycarousel').jcarousel();
		var galleredObj = $('.gallered');


	   galleredObj.bind( 'click' , function(){
   	
		var tthis = $(this);	
   	var tthisAll = tthis.parents('ul.projects').children('li').children('a');	
   	
	   var urll=$(this).attr('href');

		var ImgHrefObj = $(this).parents('div.region').children('.project').children('a:first');
		var gallText = $(this).attr('title');

      ImgHrefObj.each(function(){

		var ImgObj = $(this).children('img:first');
		var ImgAltWraper = $(this).children('b:first');
		var ImgAltObj = ImgAltWraper.children('span:first');
		var ImgStatObj = ImgHrefObj.children('i.stat:first');


		var data = urll,
		re = {};
		data.replace(/([^=&,?]+)=([^&]*)/g, function(m, key, value){
   		 re[key] = value;
		}); 

     
		newImg = new Image();

		myUrl=re['url'];
		myWidth=re['w'];
		myHeight=re['h'];
		newImg.src = myUrl;
		
      if(ImgObj.attr('src') != myUrl){
         		
   		tthisAll.each(function(){
				tthisAll.removeClass('active');
			});
      	tthis.addClass('active');

      
        ImgObj.fadeOut('100',function(){
          ImgObj.attr('width',myWidth)
					.attr('height',myHeight)
					.attr('alt',gallText)
					.attr('src',myUrl);
		
			ImgHrefObj.attr('title',gallText)
						.attr('href',urll);

			ImgAltObj.text(gallText);
			
			var mgClassObj = tthis.attr('class')
			
			if(mgClassObj.indexOf('stat_27') != -1){
				ImgStatObj.text(status.stat_27);
			}else if(mgClassObj.indexOf('stat_78') != -1){
				ImgStatObj.text(status.stat_78);
			}else if(mgClassObj.indexOf('stat_79') != -1){
				ImgStatObj.text(status.stat_79);
			}
			


			ImgObj.attr('width',myWidth)		 	

        })
          .attr('src','/_pic/p.gif').attr('alt','')
           ImgObj.fadeIn('100')     
      };
    });
    return false;
    })//.unbind('click')


});
		
