/*function trace(obj) {
	console.log(obj);	
}*/

var Core = {
	init:function() {
		this.slideCaps = $$('.slideCaptionContent');
		this.slides = $$('.slideImg');
		this.currentSlide = 1;
		this.showSlide(this.currentSlide);
		this.pe = new PeriodicalExecuter(function() {
			Core.showSlide(Core.nextSlide);
		}, 5);

		var showSlideFunc = function() {
			if(this != Core.currentSlide && !Core.running) {
				Core.nextSlide = this;
				Core.running = true;
				Core.hideSlide(Core.currentSlide,true);
				var hideCaps = Effect.Queues.get('hideCap');
				hideCaps.effects.each(function(x) { x.cancel(); });
				Core.pe.stop();
			}
		}
		$$('.thumb').each(function(x,i) {
			Event.observe(x, 'click', showSlideFunc.bind($(x).getAttribute('_num')));
				   
		});
	}
	,hideSlide:function(slideNum,force) {
		var delay = (force ? 0:3);
		var scope = (!force ? 'hideCap':'hideSlide');
		new Effect.Parallel([ new Effect.Move($('slideCaptionContent'+slideNum), { sync:true, x: 0, y: 234, mode: 'absolute' }),
							  new Effect.Move($('slideCaptionBG'), { sync:true, x: 0, y: 234, mode: 'absolute' })
							],{ delay:delay,queue: { scope: scope }
											,afterFinish:function() { 
												Effect.Fade($('slideImg'+slideNum),{ duration:2, delay:0});
												if(force) {
													Core.showSlide(Core.nextSlide,true);
												}
											}
							 });
	}
	,showSlide:function(slideNum,force) {
		this.currentSlide = parseInt(slideNum,10);
		if(!force) {
			if($('slideImg'+(slideNum+1)))
				this.nextSlide = slideNum+1;
			else
				this.nextSlide = 1;
		}
			
		$('slideImg'+slideNum).appear({duration:2,delay:0});
		new Effect.Parallel([ new Effect.Move($('slideCaptionContent'+slideNum), { sync:true, x: 0, y: 140, mode: 'absolute' }),
							  new Effect.Move($('slideCaptionBG'), { sync:true, x: 0, y: 140, mode: 'absolute' })
							]
							,{ afterFinish:function() {
												if(!force)
													Core.hideSlide(slideNum);
												else
													Core.running = false;
											}
							});
	}
}


var Popup = {
	show:function(el) {
		this.fadeDiv = document.createElement('DIV');
		var body = $$('BODY')[0];
		body.appendChild(this.fadeDiv);
		$(this.fadeDiv).innerHTML = '&nbsp;';
		$(this.fadeDiv).addClassName('fadeBG');
		$(this.fadeDiv).style.height = body.getHeight()+'px';
		
		var content = $(el).up().next('.moreInfo').cloneNode(true);
		trace(content);
		content.style.display = '';
		$('popupContent').update(content);
		$('popupFrame').show();
		$('popupFrame').style.position = 'absolute';
		//new Effect.Appear($('popupFrame'),{y:800,duration:1.0});
		$('popupFrame').style.top = '-850px';
		var x = ((document.viewport.getWidth()-$('popupFrame').getWidth())/2);
		$('popupFrame').style.left = x+'px';
		var y = ((document.viewport.getHeight()-$('popupFrame').getHeight())/2)+900;
		new Effect.Move($('popupFrame'),{y:y,duration:0.6});
	}
	,close:function(el) {
		var y = ((document.viewport.getHeight()-$('popupFrame').getHeight())/2)+900;
		new Effect.Move($('popupFrame'),{y:-y,duration:0.6,afterFinish:function() {  Popup.fadeDiv.remove(true); } });
	}
	
}
















































