// JavaScript Document

<!--

var sectionClass = new Class({

	Implements: [Chain, Options, Events],

	options: {
		objectParent: undefined,
		objectMove: undefined,
		objectDescription: undefined,
		objectClickEvent: undefined
	},

	initialize: function(options){
		this.setOptions(options);
		this.status = 'close';
		this.idParent = this.options.objectParent.get('id');
		
		this.sectionContent = this.options.objectMove.getElement('.section_description');
		this.sectionContent.hide();
		
		this.backbutton = $('btn_back');
		
		this.objectSlideDescr = new Fx.Slide(this.options.objectDescription, {
			mode: 'horizontal',
			duration: 1000
		}).hide();

		this.options.objectClickEvent.addEvent('click', function() {this.start()}.bind(this));
	},

	start: function() {
		if(this.status == 'open')  {
			/*this.status = 'close';
			this.closelink();*/
		}
		else {
			this.openlink();
		}
	},

	openlink: function(){
		this.status = 'open';
		
		if(this.options.objectDescription.getElement('iframe')) {
			this.options.objectDescription.getElement('iframe').setStyle('display', 'block');
			//alert('ci entra');
			//$('gmaps').set('src','http://maps.google.it/maps?f=q&amp;source=s_q&amp;hl=it&amp;geocode=&amp;q=Via+Sigieri,+4,+20135+Milano&amp;sll=45.838965,8.770584&amp;sspn=0.007026,0.01929&amp;ie=UTF8&amp;ll=45.459906,9.20089&amp;spn=0.008429,0.016308&amp;z=15&amp;output=embed');
			//if(frames['gmaps']) frames['gmaps'].location.href = 'http://maps.google.it/maps?f=q&amp;source=s_q&amp;hl=it&amp;geocode=&amp;q=Via+Sigieri,+4,+20135+Milano&amp;sll=45.838965,8.770584&amp;sspn=0.007026,0.01929&amp;ie=UTF8&amp;ll=45.459906,9.20089&amp;spn=0.008429,0.016308&amp;z=15&amp;output=embed';
			//else document.all.gmaps.src = 'http://maps.google.it/maps?f=q&amp;source=s_q&amp;hl=it&amp;geocode=&amp;q=Via+Sigieri,+4,+20135+Milano&amp;sll=45.838965,8.770584&amp;sspn=0.007026,0.01929&amp;ie=UTF8&amp;ll=45.459906,9.20089&amp;spn=0.008429,0.016308&amp;z=15&amp;output=embed';
		}
		$('lnk_home').removeEvents('click');
		$('lnk_home').addEvent('click', function() {this.closelink()}.bind(this));
		$('lnk_home').show();
		
		this.backbutton.removeEvents('click');
		this.backbutton.addEvent('click', function() {this.closelink()}.bind(this));

		$('box_button_pages').getElements('li[id^=page_]').each(function(item, index){
			if(item.get('id') != this.idParent) item.fade('out');
		}, this);
		
		var x = new Chain();

		var moveOblo = function(xChain) {
			
			new Fx.Move(this.options.objectMove, {
				relativeTo: $('wall_row_2'),
				position: 'upperLeft',
				offset: {x: 25, y: 40},
				duration: '1000', 
				transition: 'cubic:out',
				onComplete: function() {
					xChain.callChain();
				}
			}).start();
			
		}.bind(this, x);
		
		var showElements = function() {
			this.options.objectMove.setStyles({
				width: 745,
				height: 345
			});
			
			this.backbutton.show();
			this.sectionContent.show();

			this.objectSlideDescr.slideIn();

		}.bind(this);

		x.chain(moveOblo);
		x.chain(showElements);
		x.callChain();
	},


	closelink: function(){
		this.status = 'close';
		var x = new Chain();
		
		var closeSlider = function(xChain){ 
			new Fx.Slide(this.options.objectDescription, {
				mode: 'horizontal',
				duration: 1000,
				onComplete: function() {
					xChain.callChain();
				}
			}).slideOut();
			
		}.bind(this, x);


		var moveOblo = function(xChain){
			this.options.objectMove.setStyles({
				width: this.options.objectParent.getStyle('width'),
				height: this.options.objectParent.getStyle('height')
			});
			
			this.sectionContent.hide();
			this.backbutton.hide();
			
			new Fx.Move(this.options.objectMove, {
				relativeTo: this.options.objectParent,
				duration: '1000', 
				position: 'upperLeft',
				offset: {x: 0, y: 0},
				transition: 'cubic:out',
				onComplete: function() {
					xChain.callChain();
				}
			}).start();
		
		}.bind(this, x);
		
		var returnToInitial = function(){
			$('box_button_pages').getElements('li[id^=page_]').each(function(item, index){
				if(item.get('id') != this.idParent) item.fade('in');
			}, this);
			
			$('lnk_home').hide();
		}.bind(this);
		
		
		x.chain(closeSlider);
		x.chain(moveOblo);
		x.chain(returnToInitial);
		x.callChain();
	}
});



//-->