window.addEvent('domready', function() {
	
	rootCommittee = $('RootCommittee').get('html');
	
	var myMenu = new MenuMatic();  
	
	/*if ($('committeePictures').get('html') != '') {
		dir = $('committeeDir').get('value');//+'mini/';
		pictures = $('committeePictures').get('html');
		pictures = eval('(' + pictures + ')');

		var myShow = new Slideshow('photosComite', pictures, {href: rootCommittee  + 'photos.html', delay:5000,duration:1500,height: 150, width: 150, hu: dir});
	}
	*/
	if ($chk($('highlights-wrapper'))) {
		var tabs, contents;

        $$('.highlights li').setStyle('width', $('contenuText').getDimensions().width+'px');
        $$('.highlights li .content').setStyle('width', $('contenuText').getDimensions().width-250+'px');
        tabs = $$('.highlights-links');
        contents = $$('.highlights');

        var tabView = new MooTabs(tabs, contents, {autoPlayWait: 5000});
		$('highlights-wrapper').addEvent('mouseover', function() {
			tabView.stop();
		});
		$('highlights-wrapper').addEvent('mouseout', function() {
			tabView.play();
		});
		
	}
	
	var myTips = new Tips('.eventsRight',{
		className: 'custom',
		fixed: true,
		hideDelay: 50,
		showDelay: 50
	});
	
	$$('img.tips').each(function(el, index) {
		tab = el.get('alt').split('::');
		el.store('tip:title', tab[0]);
		el.store('tip:text', tab[1]);
	});
	

	var tipz = new Tips('img.tips',{
		className: 'custom',
		fixed: true,
		hideDelay: 50,
		showDelay: 50
	});
	
		
	$$('#poll input').addEvent('click', function(el) {
		if (confirm('Voulez-vous voter pour cette option ?')) {
			req = new Request.HTML ({
				url : 'general/poll-vote.html',
				update : $('poll'),
				onComplete : initPolls
			});
			req.get({
				'question':this.get('value')
			});
		}
	});
	
	initPolls();
	
	if ($chk($('hot-link'))) initQuickLinks();
	
	if ($chk($('new-mp'))) fadeInOut($('new-mp'));
	if ($chk($('member'))) fadeInOut($('member'));
	if ($chk($('photo-demande'))) fadeInOut($('photo-demande'));
	
});

function initLinks() {
	
}

function fadeInOut(div) {
	div.set('tween', {duration:'short'});
	div.fade('out');
	
	div.get('tween').addEvent('complete', function() {
		div.fade('toggle');
	});
}

function initMP() {
	$('new-mp').set('tween', {duration:'long'});
	$('new-mp').fade('out');
	
	$('new-mp').get('tween').addEvent('complete', function() {
		$('new-mp').fade('toggle');
	});
}

function initQuickLinks() {
	$('hot-link').addEvent('click', function(e) {
		e.stop();
		label = prompt('Ceci vous permet d\'ajouter un lien dans votre quick-link. Tous vos liens peuvent être gérer depuis votre administration de profil.', 'Label du lien');
		if (label != "") {
			req = new Request.HTML({
				url : $('hot-link').get('href'),
				update : $('quick-links')
			});
			
			req.get({
				'label': label,
				'link' : window.location.toString()
			});
		}
		
	});
}


function initPolls() {
	if ($chk($('poll-results'))) {
		total = $('poll-total').get('html').toInt();
		var count = 0;
		$$('#poll-results div.cont').each(function(el) {
			percent = el.get('html').toInt()/total;
			el.set('html', '');
			bar = new dwProgressBar({
				container : el,
				startPercentage : 0,
				displayText : true,
        		speed:1000  
			});
			bar.set.delay(1500+(count++*500), bar, (percent*100).toInt());
		});
	}
	
}

var OneRowHeight = 0;
	function dynamicHeight(textArea) {
		// alert(textArea);
		OneRowHeight = textArea.style.height;
		var rows = textArea.value.split('\n');
		nRows=-1;
		for (i=0;i < rows.length; i++) {
			if (rows[i].length >= textArea.cols) nRows+= Math.floor(rows[i].length/textArea.cols);
		}
		nRows += rows.length;
		if (nRows >= textArea.rows) {
			textArea.rows = Math.min(2, nRows);
			textArea.style.height = "auto";
		} else if (nRows == 1) {
			textArea.rows = 1;
		} else if (nRows == 0) {
			textArea.rows = 1;
			textArea.style.height = OneRowHeight;
		}
}

window.addEvent('domready', function() {
		
		if ($chk($('speedLinks'))) {
			
			myKeyboard = new Keyboard();
			myKeyboard.addShortcut('speedsearch', {
			    'keys': 'ctrl+y',
			    'description': 'Save the current document',
			    'handler': handler
			});
		
			$('speedLinks').setStyle('display', 'none');
			$('speedLinks').setStyle('opacity', 0.99);
			
			ll = new LLSearch({
				inputID: 'speedSearch',
				listID: 'speedLinks',
				onEnter: function(e, term) {
					base = term.getElement('a').get('href').contains('http://') ? '' : $$('base').get('href');
					document.location.href = base + term.getElement('a').get('href');
				}
			});
			ll.addEvent('click', function(e, term) {
				base = term.getElement('a').get('href').contains('http://') ? '' : $$('base').get('href');
					document.location.href = base + term.getElement('a').get('href');
			});
			$('speedSearch').addEvent('focus', function(){
				$('speedLinks').setStyle('display', 'block');
			});
			$('speedSearch').addEvent('blur', function(){
				var hide = function() {$('speedLinks').setStyle('display', 'none')};
				hide.delay(500);
			});
		
		}
});
	
	function handler() {
		$('speedSearch').focus();
	}
