jQuery( function( $ ) {
	var navigName = navigator.appName;
    var navigVersion = navigator.appVersion;
    var minusLeft = 279;
    if(navigName == "Microsoft Internet Explorer"){
    	var minusLeft = minusLeft+54;
    }
	// back links
	$('div.debut a').click(function(){
		$.scrollTo( 0, 800, { queue:true } );
		return false;
	});
	
	// next links
	$('div.liens_saisons ul li a').click(function(e){
		var pos = $(this.hash).findPos();
		$.scrollTo( {top:0, left:pos.x-minusLeft}, 800, { queue:true } );
		return false;
	});
	
	// next links
	$('div.liste_alpha ul li a').click(function(e){
		var pos = $(this.hash).findPos();
		$.scrollTo( {top:0, left:pos.x-minusLeft}, 800, { queue:true } );
		return false;
	});
	
	// next links
	$('div.suivant a').click(function(e){
		var pos = $(this.hash).findPos();
		$.scrollTo( {top:0, left:pos.x-minusLeft}, 800, { queue:true } );
		return false;
	});
	
	// gestion styles bouton
	$('input.btn').mouseover(function(e){
		$(this).addClass( 'btn_hover' );
		return false;
	});
	$('input.btn').mouseout(function(e){
		$(this).removeClass( 'btn_hover' );
		return false;
	});
	$('input.bt').mouseover(function(e){
		$(this).addClass( 'bt_hover' );
		return false;
	});
	$('input.bt').mouseout(function(e){
		$(this).removeClass( 'bt_hover' );
		return false;
	});
});

jQuery.fn.extend({
   findPos : function() {
       obj = jQuery(this).get(0);
       var curleft = obj.offsetLeft || 0;
       var curtop = obj.offsetTop || 0;
       while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft
                curtop += obj.offsetTop
       }
       return {x:curleft,y:curtop};
   }
});

function getWindowHeight() {
    var windowHeight=0;
    if (typeof(window.innerHeight)=='number') {
        windowHeight=window.innerHeight;
    }
    else {
     if (document.documentElement&&
       document.documentElement.clientHeight) {
         windowHeight = document.documentElement.clientHeight;
    }
    else {
     if (document.body&&document.body.clientHeight) {
         windowHeight=document.body.clientHeight;
      }
     }
    }
    return windowHeight;
}
function getWindowWidth() {
    var windowWidth=0;
    if (typeof(window.innerWidth)=='number') {
        windowWidth=window.innerWidth;
    }
    else {
     if (document.documentElement&&
       document.documentElement.clientWidth) {
         windowWidth = document.documentElement.clientWidth;
    }
    else {
     if (document.body&&document.body.clientWidth) {
         windowWidth=document.body.clientWidth;
      }
     }
    }
    return windowWidth;
}

function getScrollBarSize()
{
    var userAgent = navigator.userAgent.toLowerCase();
    var size = 0;
    if ( userAgent.indexOf('mac') != -1 )
    {
		if ( userAgent.indexOf('firefox') != -1 )
		{
			size = 15;
		}
		else if ( userAgent.indexOf('safari') != -1 )
		{
			size = 15;
		}
		else if ( userAgent.indexOf('opera') != -1 )
		{
			size = 15;
		}
    }
    else if( userAgent.indexOf('windows') != -1 )
    {
		if ( userAgent.indexOf('firefox') != -1 )
		{
			size = 17;
		}
		else if ( userAgent.indexOf('safari') != -1 )
		{
			size = 17;
		}
		else if ( userAgent.indexOf('opera') != -1 )
		{
			size = 17;
		}
		else if ( userAgent.indexOf('msie') != -1 )
		{
			size = 0;
		}
    }
    
    return size;
}

function setFooter()
{
    var userAgent = navigator.userAgent.toLowerCase();
    var scrollBarSize = getScrollBarSize();
    if (document.getElementById)
    {
        var windowHeight=getWindowHeight();
        if(document.getElementById('contentTable'))
        {
            var contentWidth=document.getElementById('contentTable').offsetWidth+290;
        }
        else
        {
            var contentWidth=document.getElementById('page').offsetWidth;
        }
        if (windowHeight>0)
        {
            var contentHeight= document.getElementById('top').offsetHeight;
            var logoHeight= document.getElementById('logo_compa').offsetHeight;
            var leftNavHeight= document.getElementById('left_nav').offsetHeight;
            var footerElement=document.getElementById('footer');
            var footerContentElement=document.getElementById('footer_content');
            var footerHeight=footerElement.offsetHeight;
            var windowWidth = getWindowWidth();
            if( windowWidth > 990 || contentWidth > 990)
            {
            	if ( contentWidth < windowWidth )
            	{
    				contentWidth = windowWidth-scrollBarSize;
            	}	
            }
            if (windowHeight-(contentHeight+footerHeight)>=0)
            {
                footerElement.style.position='relative';
                if( document.getElementById('contentTable') )
        		{
    				contentWidth = contentWidth+scrollBarSize;
        		}
                if( windowWidth < contentWidth )
                {
    				windowHeight = windowHeight-scrollBarSize;
                }
                footerElement.style.top=(windowHeight-(contentHeight+footerHeight))+'px';
            }
            else {
                footerElement.style.position='static';
            }
            footerElement.style.width=(contentWidth)+'px';
            footerContentElement.style.width=(contentWidth)+'px';
        }
    }
}
/************************************************************************************************************/

function fixColumns(){
                
                var c1 = document.getElementById("colonneA");
                var c2 = document.getElementById("colonneB");
                
                if(c1.offsetHeight && c2.offsetHeight ){
                    maxheight=Math.max(c1.offsetHeight,c2.offsetHeight)+'px';
                }
                var max2 = Math.max(c1.offsetHeight,c2.offsetHeight)+'px';                
                c1.style.height = max2;
                c2.style.height = maxheight;
                
        }
/********************************************************************************************************/
function derouler (element) {
    if(document.getElementById(element))
    {
		var lien = document.getElementById(element);
	    var list_deroul = document.getElementById(element + "_deroule");
	    lien.onmouseover = function(){
            list_deroul.style.display='block';
        }
	    lien.onmouseout = function(){
            list_deroul.style.display='none';
        }
	    list_deroul.onmouseover = function(){
            this.style.display='block';
        }
	    list_deroul.onmouseout = function(){
            this.style.display='none';
        }
    }
}

// GETELEMENTSBYCLASSNAME
	function getElementsByClassName(oElm, strTagName, strClassName){
	    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	    var arrReturnElements = new Array();
	    strClassName = strClassName.replace(/\-/g, "\\-");
	    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	    var oElement;
	    for(var i=0; i<arrElements.length; i++){
	        oElement = arrElements[i];      
	        if(oRegExp.test(oElement.className)){
	            arrReturnElements.push(oElement);
	        }   
	    }
	    return (arrReturnElements)
	}
// FIN GETELEMENTSBYCLASSNAME


function setPageWidth(){
	if( document.getElementById('contentTable_contener') )
    {
    	var contentWidth=document.getElementById('footer_content').offsetWidth;
		document.getElementById('contentTable_contener').style.width=contentWidth;
    }
}

function openProjCultBloc(currentBlocId)
{
    var currentBlocUrl = "/layout/set/nolayout/content/view/bloc_open/"+currentBlocId;
    var updateBlocId = false;
    var navigName = navigator.appName;
    var navigVersion = navigator.appVersion;
    $.ajax({
        type:'GET',
        url:currentBlocUrl,
        success:function(html){
            var arrBlocks = jQuery.makeArray($("div.horizontal_scroll div.obj_block"));
            arrBlocks.reverse(); // utilisation d'une méthode "Array"
            jQuery.each(arrBlocks, function()
            {
                var blocId = this.id;
                if(blocId != currentBlocId)
                {
                    if(document.getElementById('bloc_ouvert'+blocId) || document.getElementById('bloc_deplie'+blocId))
                    {
                        updateBlocId = blocId;
                    }
                }
            });
            if(updateBlocId)
            {
                $.ajax({
                    type:'GET',
                    url:"/layout/set/nolayout/content/view/bloc_close/"+updateBlocId,
                    success:function(html2){
                        var objBloc = document.getElementById(updateBlocId);
                        $('#'+updateBlocId).html(html2);
                        objBloc.style.width='141px';
                        if(navigName == "Microsoft Internet Explorer"){
                            var ObjBlocContainer = document.getElementById('bloc_objet_bis_'+updateBlocId);
                            ObjBlocContainer.style.width='141px';
                        }
                        
                        var currentObjBloc = document.getElementById(currentBlocId);
                        currentObjBloc.style.width='480px';
                        if(navigName == "Microsoft Internet Explorer"){
                            var currentObjBlocContainer = document.getElementById('bloc_objet_bis_'+currentBlocId);
                            currentObjBlocContainer.style.width='480px';
                        }
                        $('#'+currentBlocId).html(html);
                        
                        setFooter();
                    }
                });
            }
            else
            {
            
                var currentObjBloc = document.getElementById(currentBlocId);
                currentObjBloc.style.width='480px';
                if(navigName == "Microsoft Internet Explorer"){
                    var currentObjBlocContainer = document.getElementById('bloc_objet_bis_'+currentBlocId);
                    currentObjBlocContainer.style.width='480px';
                }
                $('#'+currentBlocId).html(html);
                
                setFooter();
            }
        }
    });
}

function deployProjCultBloc(currentBlocId)
{
    var navigName = navigator.appName;
    var navigVersion = navigator.appVersion;
    $.ajax({
        type:'GET',
        url:"/layout/set/nolayout/content/view/bloc_unfolded/"+currentBlocId,
        success:function(html){
            var currentObjBloc = document.getElementById(currentBlocId);
            currentObjBloc.style.width='480px';
            if(navigName == "Microsoft Internet Explorer"){
                var currentObjBlocContainer = document.getElementById('bloc_objet_bis_'+currentBlocId);
                currentObjBlocContainer.style.width='480px';
            }
            $('#'+currentBlocId).html(html);
            
            var minusLeft = 279;
            if(navigName == "Microsoft Internet Explorer"){
                var minusLeft = minusLeft+54;
            }
            var pos = $('#bloc_objet_bis_'+currentBlocId).findPos();
            $.scrollTo( {top:0, left:pos.x-minusLeft}, 800, { queue:true } );
            
            setFooter();
        }
    });
}

function closeProjCultBloc(currentBlocId)
{
    var currentBlocUrl = "/layout/set/nolayout/content/view/bloc_close/"+currentBlocId;
    var currentObjPC = document.getElementById(currentBlocId);
    var navigName = navigator.appName;
    var navigVersion = navigator.appVersion;
    $.ajax({
        type:'GET',
        url:currentBlocUrl,
        success:function(html){
            $('#'+currentBlocId).html(html);
            currentObjPC.style.width='141px';

            if(navigName == "Microsoft Internet Explorer"){
	            var currentObjBlocContainer = document.getElementById('bloc_objet_bis_'+currentBlocId);
	            currentObjBlocContainer.style.width='141px';
            }
            setFooter();
        }
    });
}

function openHorRubBloc(currentBlocId)
{
    var currentBlocUrl = "/layout/set/nolayout/content/view/full_ajax/"+currentBlocId;
    var updateBlocId = false;
    var navigName = navigator.appName;
    var navigVersion = navigator.appVersion;
    $.ajax({
        type:'GET',
        url:currentBlocUrl,
        success:function(html){
            var arrBlocks = jQuery.makeArray($("div.horizontal_scroll div.obj_block"));
            arrBlocks.reverse(); // utilisation d'une méthode "Array"
            jQuery.each(arrBlocks, function()
            {
                var blocId = this.id;
                if(blocId != currentBlocId)
                {
                    if(document.getElementById('bloc_deplie'+blocId))
                    {
                        updateBlocId = blocId;
                    }
                }
            });
            if(updateBlocId)
            {
                $.ajax({
                    type:'GET',
                    url:"/layout/set/nolayout/content/view/bloc/"+updateBlocId,
                    success:function(html2){
                        $('#'+updateBlocId).html(html2);
                        $('#'+currentBlocId).html(html);
                        setFooter();
                    }
                });
            }
            else
            {
                $('#'+currentBlocId).html(html);
                setFooter();
            }
        }
    });
}

function closeHorRubBloc(currentBlocId)
{
    var currentBlocUrl = "/layout/set/nolayout/content/view/bloc/"+currentBlocId;
    $.ajax({
        type:'GET',
        url:currentBlocUrl,
        success:function(html){
            $('#'+currentBlocId).html(html);
            setFooter();
        }
    });
}

function openGlosRubBloc(currentBlocId)
{
    var currentBlocUrl = "/layout/set/nolayout/content/view/full_ajax/"+currentBlocId;
    var updateBlocId = false;
    var navigName = navigator.appName;
    var navigVersion = navigator.appVersion;
    $.ajax({
        type:'GET',
        url:currentBlocUrl,
        success:function(html){
            var arrBlocks = jQuery.makeArray($("div.horizontal_scroll div.mots_block"));
            arrBlocks.reverse(); // utilisation d'une méthode "Array"
            jQuery.each(arrBlocks, function()
            {
                var blocId = this.id;
                if(blocId != currentBlocId)
                {
                    if(document.getElementById('bloc_deplie'+blocId))
                    {
                        updateBlocId = blocId;
                    }
                }
            });
            if(updateBlocId)
            {
                $.ajax({
                    type:'GET',
                    url:"/layout/set/nolayout/content/view/listitem/"+updateBlocId,
                    success:function(html2){
                        $('#'+updateBlocId).html(html2);
                        $('#'+currentBlocId).html(html);
                        setFooter();
                    }
                });
            }
            else
            {
                $('#'+currentBlocId).html(html);
                setFooter();
            }
        }
    });
}

function closeGlosRubBloc(currentBlocId)
{
    var currentBlocUrl = "/layout/set/nolayout/content/view/listitem/"+currentBlocId;
    $.ajax({
        type:'GET',
        url:currentBlocUrl,
        success:function(html){
            $('#'+currentBlocId).html(html);
            setFooter();
        }
    });
}

function openAllProjCultBloc()
{
    var currentBlocUrl = "/layout/set/nolayout/content/view/bloc_open/";
    var navigName = navigator.appName;
    var navigVersion = navigator.appVersion;

    var arrBlocks = jQuery.makeArray($("div.horizontal_scroll div.obj_block"));
    arrBlocks.reverse(); // utilisation d'une méthode "Array"
    jQuery.each(arrBlocks, function()
    {
        var blocId = this.id;
        $.ajax({
            type:'GET',
            url:"/layout/set/nolayout/content/view/bloc_open/"+blocId,
            success:function(html){
                var objBloc = document.getElementById(blocId);
                $('#'+blocId).html(html);
            }
        });
    });
}