var myBateaux = {	
	start: function(){
		var mf = new MooFlow($('flowlist2'), {
			startIndex: 1,
			heightRatio: 0.7,
			offsetY:30,
			useKeyInput: true,
			useViewer: false
		});
	} 
};

var initNav = function() {	
	
	var parent = $('nav');

	var items = parent.getElements('ul');

	items.each(function(el,i) {
		el.addEvent('mouseover',function(){this.getParent('li').addClass('active')});	
	});
	items.each(function(el,i) {
		el.addEvent('mouseout',function(){this.getParent('li').removeClass('active')});	
	});
	parent.MooDropMenu({
		onOpen: function(el){
			el.fade('in');
		},
		onClose: function(el){
			el.fade('out');
		},
		onInitialize: function(el){
			el.fade('hide').set('tween',{duration:240});
		}
	});
	
	
};

// MooFlow Viewer (extra JS MooFlowViewer.js) 
MooFlow.implement({

	attachViewer: function(){
		return this;
	},
	flowStart: function(){
		this.hideIcon();
	},
	
	flowComplete: function(){
		this.createIconTip();	
	},
	
	showUI: function(){
		if(this.cap) this.cap.fade(1);
		this.nav.tween('bottom', 10);	
		this.fireEvent('start');
		this.update();
	},
		
	createIconTip: function(){
		var cur = this.getCurrent();
		if(!$chk(cur.rel)||!$chk(cur.href)) return;
		this.tipFx = new Fx({link:'cancel'});
		if(!$chk(this.icon)) { this.icon = new Element('a').addClass('show').setStyles({'display':'none','opacity':'0'}).inject(this.MooFlow); }
		this.icon.addEvent('click', this.onClickView.bind(this, cur));
		this.icon.addEvent('mouseenter', this.showTip.bind(this, cur));
		this.icon.addEvent('mouseleave', this.hideTip.bind(this, cur));
		if(!$chk(this.tip)){ this.tip = new Element('div').addClass('tooltip').setStyles({'display':'none','opacity':'0'}).inject(this.MooFlow); }
		this.tip.set('html', cur.alt);
		this.icon.addClass(cur.rel.toLowerCase());
		this.icon.setStyle('display','block').fade(0.6);
	},

	showTip: function(cur){
		this.tip.setStyles({'top':0,'display':'block'});
		this.tipFx = new Fx.Morph(this.tip,{link:'cancel'}).start({'opacity': 0.8, 'top': 50});
	},
	
	hideTip: function(cur){
		this.tipFx.start({'opacity': 0, 'top': 0});
	},

	hideIcon: function(){
		if($chk(this.icon) && $chk(this.icon.getParent())) this.icon.destroy();
		if($chk(this.tip) && $chk(this.tip.getParent())) this.tip.destroy();
		this.icon = this.tip = null;	
	},
		
	onClickView: function(cur){
		switch (cur.rel.toLowerCase()){
			case 'image':
			this.loadImage(cur);
			break;
			case 'link':
			window.open(cur.href, cur.target || '_blank');
			break;
			default:
		}
	},
	
	loadImage: function(cur){
		this.icon.removeClass('image');
		this.image = new Asset.image(cur.href, {onload: this.showImage.bind(this)});
	},
	
	showImage: function(){
		var cur = this.getCurrent();
		var c = cur.con.getFirst().getCoordinates();
		this.image.inject(document.body).setStyle('border','5px solid white');
		this.image.addEvent('click', this.hideImage.bind(this));
		this.image.setStyles({'left':c.left,'top':c.top,'width':c.width,'height':c.height,'position':'absolute','z-index':'103'});
		var imageFx = new Fx.Morph(this.image, {transition: Fx.Transitions.Sine.easeOut});
		var to = {x: this.image.get('width'), y: this.image.get('height')};
		var box = document.getSize(), scroll = document.getScroll();
		var pos = {x: scroll.x + ((box.x - to.x) / 2).toInt(), y: scroll.y + ((box.y - to.y) / 2).toInt() };
		var vars = {left: pos.x, top: pos.y, width: to.x, height: to.y};
		imageFx.start(vars);
	},
	
	hideImage: function(){
		this.icon.removeClass('viewerload').addClass('image');
		this.image.dispose();
	}
});

var scanPage = function() {
	$$("a").filter(function(el) {
		return el.rel && el.rel.test(/^lightbox/i);
	}).slimbox({/* Put custom options here */}, null, function(el) {
		return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
	});
};

var navSlideShow;
var initSlideShow = function() {
	var title = $('titrune').getElement('a');
	var texte = $('textune');
	
	var datum = $('datune');
	var titles = $$('.alaune');
	var texts = $$('.texteune');
	var navs = $('jnav').getElements('a');
	
	navSlideShow = new SlideShow('slideshow', {
		selector: 'img',
		autoplay: true,
		delay: 5500,   
		transition: 'pushLeft',		
		onShow: function(data){ 
			navs[data.previous.index].removeClass('current');
			navs[data.next.index].addClass('current');
			var curr = titles[data.next.index];
			var currt = texts[data.next.index];
			
			title.set('href',curr.get('href')).set('text',curr.get('text'));
			datum.set('text',curr.get('title'));
			texte.set('html',currt.get('html') )
		}		
	});	
	navs.each(function(item, index){
		item.addEvent('click', function(e){
			e.stop();
			var transition = (navSlideShow.index < index) ? 'pushLeft' : 'pushRight';
			navSlideShow.show(index, {transition: transition});
		});
	});
	$('bprev').addEvent('click', function(e){
		e.stop();
		var transition = 'pushRight' ;
		navSlideShow.show('previous', {transition: transition});
	});  
	
	$('bnext').addEvent('click', function(e){
		e.stop(); 
		var transition = 'pushLeft' ;
		navSlideShow.show('next', {transition: transition});
	}); 	 

};


