window.addEvent('domready', function(){
	
	if($$('body .page')[0]){
		$$('body .page')[0].addClass(Browser.Platform.name);
		$$('body .page')[0].addClass(Browser.name);
		$$('body .page')[0].addClass(Browser.name+Browser.version);
	}
	
	if($('fichiers_large'))
		if($('fichiers_large').getElements('tr').length == 1){$('fichiers_large').getParent().hide()}
	
	if($('fichiers_small'))
		if($('fichiers_small').getElements('tr').length == 1){$('fichiers_small').getParent().hide()}
	
	if($('medias'))
		if($('medias').getElements('li').length == 0){$('medias').getParent().hide()}
	
	if($('actualites_liste'))
		$('actualites_liste').getElements('.item').each(function(e){
			if(e.getElement('a').get('href')){
				e.addEvent('click', function(ev){
					ev.preventDefault();
					window.location.href=e.getElement('a').get('href');
				});
			}
		})
		
	
    // Sous-Menu de la Nav Horizontale
    if($('menu')){
        $$('#menu .gotchildren').each(function(el) {
            el.addEvent('mouseenter', function(e) {
                e.stop();
                el.addClass('hover');
                el.getElements('.child_item_menu').addClass('hover');
            });
            el.addEvent('mouseleave', function(e) {
                e.stop();
                el.removeClass('hover');
                el.getElements('.child_item_menu').removeClass('hover');
            });
        });
    }
    if($$('#menu .gotchildren .child_item_menu')){
        $$('#menu .gotchildren .child_item_menu').each(function(el) {
            el.addEvent('mouseenter', function(e) {
                e.stop();
                el.addClass('hover');
                el.getParent().addClass('hover');

            });
            el.addEvent('mouseleave', function(e) {
                e.stop();
                el.getParent().removeClass('hover');
                el.removeClass('hover');
            });
        });
    }
    if($$('#menu li.item_menu.gotchildren .child_item_menu ul li')){
        $$('#menu li.item_menu.gotchildren .child_item_menu ul li').each(function(el) {
            el.addEvent('mouseenter', function(e) {
                e.stop();
                el.addClass('hover');
            });
            el.addEvent('mouseleave', function(e) {
                e.stop();
                el.removeClass('hover');
            });
        });
    }

    // Bouton Ok du moteur de recherche
    if($('submitsearch')){
            $('submitsearch').addEvent('mouseenter', function(e) {
                    e.stop();
                    $('submitsearch').tween('background-color', '#a6c53b');
            });
            $('submitsearch').addEvent('mouseleave', function(e) {
                    e.stop();
                    $('submitsearch').tween('background-color', '#5D6F1C');
                    $('submitsearch').getElements('.titre').tween('opacity', 0);
            });
    }

    // Liens en bas du footer
    if($$('#copyright .liens li a')){
        $$('#copyright .liens li a').each(function(el) {
            el.addEvent('mouseenter', function(e) {
                e.stop();
                el.tween('color', '#a6c633');
            });
            el.addEvent('mouseleave', function(e) {
                e.stop();
                el.tween('color', '#666666');
            });
        });
    }

    // Contenu Scroll
    if($('contenu_scroll')){
            var c = $('contenu_scroll');
            botoescroll(c, {height:220, width:0, top:0, thumbHeight:0});
    }

    // Contenu Scroll Actus
    if($('contenu_scroll_actu')){
            var csa = $('contenu_scroll_actu');
            botoescroll(csa, {height:364, width:0, top:0, thumbHeight:0});
    }
    
    // Contenu Scroll Actus
    if($('contenu_scroll_actu_projet')){
        var csa = $('contenu_scroll_actu_projet');
        botoescroll(csa, {height:273, width:0, top:0, thumbHeight:0});    	
    }


    if($$('#actualites .actualite')){
        $$('#actualites .actualite').each(function(el) {
        	
        	if(el.getChildren(".image a")){
        		var link = el.getChildren(".image a")[0].get('href');
        		if(link){
        			el.addEvent('click', function(e) {
        				window.location = link;
        			});
        		}
        	}
        	
            el.addEvent('mouseenter', function(e) {
                    e.stop();
                    el.addClass('hover');
            });
            el.addEvent('mouseleave', function(e) {
                    e.stop();
                    el.removeClass('hover');
            });
        });
    }

    if($$('#content #actualites_liste .contenu .item')){
        $$('#content #actualites_liste .contenu .item').each(function(el) {
            el.addEvent('mouseenter', function(e) {
                    e.stop();
                    el.addClass('hover');
            });
            el.addEvent('mouseleave', function(e) {
                    e.stop();
                    el.removeClass('hover');
            });
        });
    }

    // Une autre liste d'Actualités
    if($$('#content .listeactu .item')){
        $$('#content .listeactu .item').each(function(el) {
            el.addEvent('mouseenter', function(e) {
                    e.stop();
                    el.addClass('hover');
            });
            el.addEvent('mouseleave', function(e) {
                    e.stop();
                    el.removeClass('hover');
            });
        });
    }

    // Listes des projets
    if($$('#projets .bloc_projet_live, #systemes .bloc_systeme_live')){
        $$('#projets .bloc_projet_live, #systemes .bloc_systeme_live').each(function(el) {
        	
        	if(el.getChildren(".photo a")){
        		var link = el.getChildren(".photo a")[0].get('href');
        		if(link){
        			el.addEvent('click', function(e) {
        				window.location = link;
        			});
        		}
        	}
        	
            el.addEvent('mouseenter', function(e) {
                    e.stop();
                    el.addClass('hover');
            });
            el.addEvent('mouseleave', function(e) {
                    e.stop();
                    el.removeClass('hover');
            });
        });
    }
     if($$('#projets .bloc_projet, #systemes .bloc_systeme')){
    	var i = 1;
        $$('#projets .bloc_projet, #systemes .bloc_systeme').each(function(el) {
        	
        	if(el.getChildren(".photo a")){
        		var link = el.getChildren(".photo a")[0].get('href');
        		if(link){
        			el.addEvent('click', function(e) {
        				window.location = link;
        			});
        		}
        	}
        	
        	if(i%2==0)
        		el.addClass("odd");
        	
            el.addEvent('mouseenter', function(e) {
                    e.stop();
                    el.addClass('hover');
            });
            el.addEvent('mouseleave', function(e) {
                    e.stop();
                    el.removeClass('hover');
            });
            i++;
        });
    }
   
    // Produits - Fiche
    if($('menuplayer')){
        var tabs = new SimpleTabs($('menuplayer'), {
                selector: 'h6.tab'
        });
    }
    if($$('.presentation a')){
        $$('.presentation .a').each(function(el) {
            el.addEvent('mouseenter', function(e) {
                    e.stop();
                    el.set('class', 'selected');
            });
            el.addEvent('mouseleave', function(e) {
                    e.stop();
                    el.set('class', '');
            });
        });
    }
    if($('presentationtitre') && $('donneestechtitre')){
        $('presentationtitre').addEvent('click', function(e) {
            e.stop();
            $('presentationtext').setStyle('display', 'block');
            $('presentationtitre').addClass('selected');

            $('donneestechtext').setStyle('display', 'none');
            $('donneestechtitre').removeClass('selected');
        });
        $('donneestechtitre').addEvent('click', function(e) {
            e.stop();
            $('presentationtext').setStyle('display', 'none');
            $('presentationtitre').removeClass('selected');

            $('donneestechtext').setStyle('display', 'block');
            $('donneestechtitre').addClass('selected');
        });
    }

    if($$('#content #actualites .actualite')[0])
    	$$('#content #actualites .actualite')[0].addClass("first");
    
    
    // Calendrier
    if($$('#calendrier .tableCalendrier tr.days td')){
        $$('#calendrier .tableCalendrier tr.days td').each(function(el) {
            el.addEvent('mouseenter', function(e) {
                    e.stop();
                    el.addClass('selected');
            });
            el.addEvent('mouseleave', function(e) {
                    e.stop();
                    el.addClass('selected');
            });
        });
    }
    
    //form partenaires
    if($$('form div a.form')){
    	
    	$$('form div a.form').each(function(el) {
             el.addEvent('click', function(e) {
                 e.stop();
                 el.getParent('form').submit();
             });
         });
    	
    }
    
    
    if($$('#medias li'))
    	$$('#medias li').each(function(e){
    		var href = e.getElement('a').get('href');
    		reg = new RegExp(".flv|.avi|.mpg|.mpeg")
    		if(reg.test(href)){
    			e.addClass('movie');
    			f = new Element('div').addClass('filtre')
    			f.inject(e.getElement('a'), 'top');
    		}
    	});
    
    
    
});
