var main = function() {

	/* Admin box */
	if($('admin_link').getElement('a.signon'))
	{
		$('admin_link').getElement('a.signon').addEvent('click', function(e){
			var container = new Element('div', {'id': 'admin_container'});
			var box = new Element('div', {'id': 'admin_box'});
			var form = new Element('form', {'action': 'index.php5', 'method':'POST', 'html' : '<h2>Identification</h2><label>Login</label><input type="text" name="login" /><label>Mot de passe</label><input type="password" name="password" /><input type="submit" id="submit_admin" value="Connexion" />'});
			form.inject(box);
			container.inject(document.body, 'bottom');
			box.inject(document.body, 'bottom');
			e.stop();
		});
	}
	
	/* Shadowization ! */
	var header_shadows = new Element('div', {'class' : 'shadows'});
	header_shadows.innerHTML = '<div class="top_shadows"><div class="shadow_hg"></div><div class="shadow_hd"></div></div><div class="shadow_g"></div><div class="shadow_d"></div>';
	$('header').appendChild(header_shadows);
	var main_shadows = new Element('div', {'class' : 'shadows'});
	main_shadows.innerHTML = '<div class="top_shadows"><div class="shadow_hg"></div></div><div class="shadow_g"></div><div class="shadow_d"></div><div class="bottom_shadows"><div class="shadow_bg"></div><div id="cale"></div><div class="shadow_bd"></div></div>';
	$('main').appendChild(main_shadows);
    var footer_shadows = new Element('div', {'class' : 'shadows'});
	footer_shadows.innerHTML = '<div class="shadow_g"></div><div class="shadow_d">';       
	$('footer').appendChild(footer_shadows);
    var menu_shadows = new Element('div', {'class' : 'shadows'});
	menu_shadows.innerHTML = '<div class="shadow_g"></div><div class="shadow_d">';       
    $('menu').appendChild(menu_shadows);
	$$('#slideview ul li').each(function(e, i){
		var slideview_shadow = new Element('span', {'class' : 'slideview_shadow'});
		slideview_shadow.inject(e, 'top');
	});
    
	var bg = new Element('div', {'id' : 'back'});
	bg.inject($('body_wrap'), 'top');
	bg.setStyle('opacity', '0.7');
	
    $$('.flickr_pic').each(function(item, index){
        item.setStyle('opacity', 0.5);
        item.addEvents({
            'mouseover' : function(e){
                this.fade(1);
            },
            'mouseout' : function(e){
                this.fade(0.5);
            }
        });
    });
    
	/* Item Links */
	var items = $$('.item');
	if(items.length > 1)
	{
		items.each(function(item, index){
		  var longdesc = item.getElement('.long_item_description');
		  if(longdesc) {
			  var vSlide = new Fx.Slide(longdesc);
			vSlide.hide();
		  }else
			vSlide = null;
			new Element('div', {'class' : 'item_shadow'}).inject(item, 'top');
			var is = item.getElement('.item_shadow');
			var link = item.getElement('a.expand_link');
			is.setStyle('cursor', 'pointer');
			is.addEvent(
				'click', function(e){
					e.stop();
					if(vSlide)
						vSlide.toggle();
					if(link)
					{					
						if(vSlide.open == false)
							link.innerHTML = '-';
						else
							link.innerHTML = '+';	
					}			
				}
			);
			var links = item.getElements('a.expand');
			links.each(function(el, i){
				el.addEvent(
				'click', function(e){
					e.stop();
					if(vSlide)
						vSlide.toggle();		
					if(link)
					{			
						if(vSlide.open == false)
							link.innerHTML = '-';
						else
							link.innerHTML = '+';
					}				
				});
			});
		});
	}
	
    // Slidehow on homepage
    if($('slideshow'))
    {
        var info = $('info_projet').set('opacity',0.3);
        var nS5 = new noobSlide({
            mode: 'horizontal',
            box: $('box'),
            size: 620,
            items: sampleObjectItems,
            addButtons: {
                previous: $('prev'),
                next: $('next')
            },
            onWalk: function(currentItem){
                info.empty();
                new Element('h3').set('html','<a href="'+currentItem.link+'">'+currentItem.title+'</a>'+currentItem.title).inject(info);
                new Element('p').set('html','<b>Cat&eacute;gorie</b>: '+currentItem.category+' &nbsp; &nbsp; <b>Date</b>: '+currentItem.date).inject(info);
            },
            autoPlay: true
        });
    }

    // Tags
	$$('.keywords_input').each(function(el, i){
		var ac = new TextboxList(el, {unique: true, plugins: {autocomplete: 
				{
					queryRemote: true,
					remote: {url: 'autocomplete.php5'}
				}
			}
		});
	});
	
	// FancyZoom
	setupZoom();
}

window.addEvent('domready', function() {
    main();
});
