content['siteItem'] = Class.create({

  THREAD_ID: null,
  EXEC_UID: null,
  arrParams:  null,

  initialize: function(arrInstVars, arrParams, arrLang)
  {
    this.THREAD_ID    = arrInstVars.THREAD_ID;
    this.EXEC_UID     = arrInstVars.EXEC_UID;
    
    this.arrImages = $$('a[_name="preview"]');
    this.arrImages.each(function(el)
    {
        el.observe('click', this._showMediumPhoto.bind(this))
    }.bind(this));

	this.arrImages = $$('div#'+this.EXEC_UID+'-galleryContent a[_name="preview"]');
  
    if($('pictureLink')) $('pictureLink').observe('click', this._showGallery.bind(this));
    if($('slideShowLink')) $('slideShowLink').observe('click', this._showGallery.bind(this));
	

	if($('map_canvas') && $('map_canvas').getAttribute('_addressQ')!='')
	{	
	  $('showPhoto').observe('click', function()
	  {
		$('showPhoto').removeClassName('inactive');
		$('showMap').addClassName('inactive');
		$('pictureLink').removeClassName('mapSelect');
		$("map_canvas").hide();
	  }.bind(this))	
	  
	  $('showMap').observe('click', function()
	  {
		$('showPhoto').addClassName('inactive');
		$('showMap').removeClassName('inactive');
		$('pictureLink').addClassName('mapSelect');
		$("map_canvas").show();
	  }.bind(this))	
	  
	
      if (GBrowserIsCompatible()) {
        var map = new GMap2($("map_canvas"));
		map.addControl(new GSmallMapControl());
        
		var geocoder = new GClientGeocoder();
		var address = $("map_canvas").getAttribute('_addressQ');
		
		var p1 = $("map_canvas").getAttribute('_p1');
		var p2 = $("map_canvas").getAttribute('_p2');
		if(!p1||!p2)
		{

		  this.pnt = {x: false, y:false};
		  geocoder.getLatLng(
			address,
			function(point) {
			  if (!point) {
				$$('[name="forMap"]').invoke('hide');
				$('pictureLink').removeClassName('mapSelect');
			  } else {
			    this.pnt = point;
				$$('[name="forMap"]').invoke('show');
				$('showPhoto').addClassName('inactive');
				$('showMap').removeClassName('inactive');
				map.setCenter(point, 13);
				var marker = new GMarker(point);
				map.addOverlay(marker);
				//marker.openInfoWindowHtml($("map_canvas").getAttribute('_address'));
			  }
			  new Ajax.Request('/?call_element=component.rcGeoMapper', 
			  {
				  method: 'post',
				  parameters: {_x: this.pnt.x, _y: this.pnt.y, 
					contentType: $("map_canvas").getAttribute('_contentType'), 
					_id: $("map_canvas").getAttribute('_id')}
			  });			  
			}.bind(this)
		  );

		}
		else
		{
			$$('[name="forMap"]').invoke('show');
			$('showPhoto').addClassName('inactive');
			$('showMap').removeClassName('inactive');			
			var point = new GLatLng(parseFloat(p2), parseFloat(p1));
			map.setCenter(point, 13);
			var marker = new GMarker(point);
			map.addOverlay(marker);
			//marker.openInfoWindowHtml($("map_canvas").getAttribute('_address'));			
			
		}
      } 
	}
	else
	{
		$$('[name="forMap"]').invoke('hide');
		$('pictureLink').removeClassName('mapSelect');
	}

  },

  _showGallery: function(evt)
  {
    evt.stop();
    $(document).fire('slideShow:start', {intStartImgNum: evt.findElement('a[_num]').getAttribute('_num'), arrImagesElements: this.arrImages});
  },
  
  _showMediumPhoto: function(evt)
  {
    evt.stop();
	
	if($('showPhoto'))
	{
		$('showPhoto').removeClassName('inactive');
		$('showMap').addClassName('inactive');
		$('pictureLink').removeClassName('mapSelect');
		if($("map_canvas")) $("map_canvas").hide();	
	}
    
    if(this.isLock) return;
    this.isLock=true;
    
    var elPreview = evt.findElement('a[_medium]');
    var big = elPreview.getAttribute('_medium');
    
    $('pictureLink').setAttribute('_num', elPreview.getAttribute('_num'));
    
    new Effect.Opacity('picture', 
    { 
      duration: 0.6, from: 1, to: 0,
      afterFinish: function()
      {
        $('picture').replace('<img class="picture" id="picture" src='+big+' style="display:none;" />');
        $('picture').setStyle({opacity: 0}).show();
        (function(){
        new Effect.Opacity('picture', { duration: 0.6, from: 0, to: 1, afterFinish: function(){this.isLock = false;}.bind(this)});
        }.bind(this)).defer();        
      }.bind(this) 
    });
  }
});
arrJsLoaded['content.siteItem.js']=true;init.jsLoaded("content.siteItem.js");