//window.winHeight=document.all?document.body.clientHeight:window.innerHeight;

var openConcours;
var firstConcours = true;
var heightCncrs;
var widthCncrs;
var cssTopCncrs;
var totalHeightCncrs;
var finalHeightCncrs;

var openEspaces;
var firstEspaces = true;
var heightEspcs;
var widthEspcs;
var cssTopEspcs;
var totalHeightEspcs;
var finalHeightEspcs;

var openEditions;
var firstEditions = true;
var heightEdtns;
var widthEdtns;
var cssTopEdtns;
var totalHeightEdtns;
var finalHeightEdtns;

var openAffiches;
var firstAffiches = true;
var heightAffchs;
var widthAffchs;
var cssTopAffchs;
var totalHeightAffchs;
var finalHeightAffchs;

var openIdentites;
var firstIdentites = true;
var heightIdntts;
var widthIdntts;
var cssTopIdntts;
var totalHeightIdntts;
var finalHeightIdntts;

$(document).ready(function(){
    //window.winHeight=document.all?document.body.clientHeight:window.innerHeight;
    $("#Presentation").mouseover(function(){
        $(this).css({zIndex:"1000"});
    }).mouseout(function(){
        $(this).css({zIndex:"0"});
    });
    $("#Logo").mouseover(function(){
        $(this).css({zIndex:"1000"});   
        $(this).find("img").attr({src: "assets/images/Menu/logobleu.png"});
    }).mouseout(function(){
        $(this).css({zIndex:"0"});
        $(this).find("img").attr({src: "assets/images/Menu/logo.png"});
    });
    $("#Actualites").mouseover(function(){
        $(this).css({zIndex:"1000"});
    }).mouseout(function(){
        $(this).css({zIndex:"0"});
    });
    $("#Travaux").mouseover(function(){
        $(this).css({zIndex:"1000"});
    }).mouseout(function(){
        $(this).css({zIndex:"0"});
    });
    
    
    openIdentites = false;
    $("#T_identites").find(".imgPress").mousedown(function(){
        if (!openIdentites) {
            $("#T_identites").find(".contentSousMenu").toggle();
            heightIdntts = $("#T_identites").find(".OuterRowTemplate").height();
            if (firstIdentites) {
                widthIdntts = $("#T_identites").find(".OuterRowTemplate").width();
                firstIdentites = false;
            }
            $("#T_identites").find(".contentSousMenu").toggle();
            
            cssTopIdntts = $("#T_identites").css("top");
            totalHeightIdntts = parseInt(cssTopIdntts)+parseInt(heightIdntts)+32;
            
            if (detectIfScroll(totalHeightIdntts)) {
                finalHeightIdntts = (window.winHeight-parseInt(cssTopIdntts))-32;
                $("#T_identites").find(".contentSousMenu").css("height", finalHeightIdntts);
                $("#T_identites").find(".contentSousMenu").css("width", parseInt(widthIdntts)+17);
            } else {
                $("#T_identites").find(".contentSousMenu").css("height", heightIdntts);
                $("#T_identites").find(".contentSousMenu").css("width", parseInt(widthIdntts)+1);
            }
            $("#T_identites").find(".contentSousMenu").slideDown(100);
            openIdentites = true;
        } else {
            var lastHeightIdntts = $("#T_identites").height();
            $("#T_identites").find(".contentSousMenu").css("height", parseInt(lastHeightIdntts)-32);
            $("#T_identites").find(".contentSousMenu").slideUp(100);
            openIdentites = false;
        }
        resetIdentites();
        $("#T_identites").css({zIndex:"900"});
    });

    
    openAffiches = false;
    $("#T_Affiches").find(".imgPress").mousedown(function(){
        if (!openAffiches) {
            $("#T_Affiches").find(".contentSousMenu").toggle();
            heightAffchs = $("#T_Affiches").find(".OuterRowTemplate").height();
            if (firstAffiches) {
                widthAffchs = $("#T_Affiches").find(".OuterRowTemplate").width();
                firstAffiches = false;
            }
            $("#T_Affiches").find(".contentSousMenu").toggle();
            
            cssTopAffchs = $("#T_Affiches").css("top");
            totalHeightAffchs = parseInt(cssTopAffchs)+parseInt(heightAffchs)+29;
            
            if (detectIfScroll(totalHeightAffchs)) {
                finalHeightAffchs = (window.winHeight-parseInt(cssTopAffchs))-29;
                $("#T_Affiches").find(".contentSousMenu").css("height", finalHeightAffchs);
                $("#T_Affiches").find(".contentSousMenu").css("width", parseInt(widthAffchs)+17);
            } else {
                $("#T_Affiches").find(".contentSousMenu").css("height", heightAffchs);
                $("#T_Affiches").find(".contentSousMenu").css("width", parseInt(widthAffchs)+1);
            }
            $("#T_Affiches").find(".contentSousMenu").slideDown(100);
            openAffiches = true;
        } else {
            var lastHeightAffchs = $("#T_Affiches").height();
            $("#T_Affiches").find(".contentSousMenu").css("height", parseInt(lastHeightAffchs)-29);
            $("#T_Affiches").find(".contentSousMenu").slideUp(100);
            openAffiches = false;
        }
        resetAffiches();
        $("#T_Affiches").css({zIndex:"900"});
    });
    
    
    openEditions = false;
    $("#T_Editions").find(".imgPress").mousedown(function(){
        if (!openEditions) {
            $("#T_Editions").find(".contentSousMenu").toggle();
            heightEdtns = $("#T_Editions").find(".OuterRowTemplate").height();
            if (firstEditions) {
                widthEdtns = $("#T_Editions").find(".OuterRowTemplate").width();
                firstEditions = false;
            } 
            $("#T_Editions").find(".contentSousMenu").toggle();
            
            cssTopEdtns = $("#T_Editions").css("top");
            totalHeightEdtns = parseInt(cssTopEdtns)+parseInt(heightEdtns)+33;
            
            if (detectIfScroll(totalHeightEdtns)) {
                finalHeightEdtns = (window.winHeight-parseInt(cssTopEdtns))-33;
                $("#T_Editions").find(".contentSousMenu").css("height", finalHeightEdtns);
                $("#T_Editions").find(".contentSousMenu").css("width", parseInt(widthEdtns)+17);
            } else {
                $("#T_Editions").find(".contentSousMenu").css("height", heightEdtns);
                $("#T_Editions").find(".contentSousMenu").css("width", parseInt(widthEdtns)+1);
            }
            $("#T_Editions").find(".contentSousMenu").slideDown(100);
            openEditions = true;
        } else {
            var lastHeightEdtns = $("#T_Editions").height();
            $("#T_Editions").find(".contentSousMenu").css("height", parseInt(lastHeightEdtns)-33);
            $("#T_Editions").find(".contentSousMenu").slideUp(100);
            openEditions = false;
        }
        resetEditions();
        $("#T_Editions").css({zIndex:"900"});
    });
    
    
    openEspaces = false;
    $("#T_Espaces").find(".imgPress").mousedown(function(){
        if (!openEspaces) {
            $("#T_Espaces").find(".contentSousMenu").toggle();
            heightEspcs = $("#T_Espaces").find(".OuterRowTemplate").height();
            if (firstEspaces) {
                widthEspcs = $("#T_Espaces").find(".OuterRowTemplate").width();
                firstEspaces = false;
            }
            $("#T_Espaces").find(".contentSousMenu").toggle();
            
            cssTopEspcs = $("#T_Espaces").css("top");
            totalHeightEspcs = parseInt(cssTopEspcs)+parseInt(heightEspcs)+29;
            
            if (detectIfScroll(totalHeightEspcs)) {
                finalHeightEspcs = (window.winHeight-parseInt(cssTopEspcs))-29;
                $("#T_Espaces").find(".contentSousMenu").css("height", finalHeightEspcs);
                $("#T_Espaces").find(".contentSousMenu").css("width", parseInt(widthEspcs)+17);
            } else {
                $("#T_Espaces").find(".contentSousMenu").css("height", heightEspcs);
                $("#T_Espaces").find(".contentSousMenu").css("width", parseInt(widthEspcs)+1);
            }
            $("#T_Espaces").find(".contentSousMenu").slideDown(100);
            openEspaces = true;
        } else {
            var lastHeightEspcs = $("#T_Espaces").height();
            $("#T_Espaces").find(".contentSousMenu").css("height", parseInt(lastHeightEspcs)-29);
            $("#T_Espaces").find(".contentSousMenu").slideUp(100);
            openEspaces = false;
        }
        resetEspaces();
        $("#T_Espaces").css({zIndex:"900"});
    });
    
    
    openConcours = false;
    $("#T_Concours").find(".imgPress").mousedown(function(){
        if (!openConcours) {
            $("#T_Concours").find(".contentSousMenu").toggle();
            heightCncrs = $("#T_Concours").find(".OuterRowTemplate").height();
            if (firstConcours) {
                widthCncrs = $("#T_Concours").find(".OuterRowTemplate").width();
                firstConcours = false;
            }
            $("#T_Concours").find(".contentSousMenu").toggle();
            
            cssTopCncrs = $("#T_Concours").css("top");
            totalHeightCncrs = parseInt(cssTopCncrs)+parseInt(heightCncrs)+29;
            
            if (detectIfScroll(totalHeightCncrs)) {
                finalHeightCncrs = (window.winHeight-parseInt(cssTopCncrs))-29;
                $("#T_Concours").find(".contentSousMenu").css("height", finalHeightCncrs);
                $("#T_Concours").find(".contentSousMenu").css("width", parseInt(widthCncrs)+17);
            } else {
                $("#T_Concours").find(".contentSousMenu").css("height", heightCncrs);
                $("#T_Concours").find(".contentSousMenu").css("width", parseInt(widthCncrs)+1);
            }
            $("#T_Concours").find(".contentSousMenu").slideDown(100);
            openConcours = true;
        } else {
            var lastHeightCncrs = $("#T_Concours").height();
            $("#T_Concours").find(".contentSousMenu").css("height", parseInt(lastHeightCncrs)-29);
            $("#T_Concours").find(".contentSousMenu").slideUp(100);
            openConcours = false;
        }
        resetConcours();
        $("#T_Concours").css({zIndex:"900"});
    });
});
function getHeight() {
	var y = 0;
	if (self.innerHeight) {
		y = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		y = document.documentElement.clientHeight;
	} else if (document.body) {
		y = document.body.clientHeight;
	}
	return y;
}
window.onresize = function (){
    //window.winHeight=document.all?document.body.clientHeight:window.innerHeight;
	window.winHeight=getHeight();
}
function detectIfScroll(passY) {
    //window.winHeight=document.all?document.body.clientHeight:window.innerHeight;
    window.winHeight=getHeight();
    if (passY>window.winHeight) {
        return true;
    } else {
        return false;
    }
}
function resetIdentites(){
    $("#T_Editions").find(".contentSousMenu").slideUp(100);
    $("#T_Affiches").find(".contentSousMenu").slideUp(100);
    $("#T_Espaces").find(".contentSousMenu").slideUp(100);
    $("#T_Concours").find(".contentSousMenu").slideUp(100);
    openAffiches = false;
    openEspaces = false;
    openConcours = false;
    openEditions = false;
    $("#T_Editions").css({zIndex:"0"});
    $("#T_Affiches").css({zIndex:"0"});
    $("#T_Espaces").css({zIndex:"0"});
    $("#T_Concours").css({zIndex:"0"});
}
function resetAffiches(){
    $("#T_identites").find(".contentSousMenu").slideUp(100);
    $("#T_Editions").find(".contentSousMenu").slideUp(100);
    $("#T_Espaces").find(".contentSousMenu").slideUp(100);
    $("#T_Concours").find(".contentSousMenu").slideUp(100);
    openIdentites = false;
    openEspaces = false;
    openConcours = false;
    openEditions = false;
    $("#T_identites").css({zIndex:"0"});
    $("#T_Editions").css({zIndex:"0"});
    $("#T_Espaces").css({zIndex:"0"});
    $("#T_Concours").css({zIndex:"0"});
}
function resetEditions(){
    $("#T_identites").find(".contentSousMenu").slideUp(100);
    $("#T_Affiches").find(".contentSousMenu").slideUp(100);
    $("#T_Espaces").find(".contentSousMenu").slideUp(100);
    $("#T_Concours").find(".contentSousMenu").slideUp(100);
    openIdentites = false;
    openAffiches = false;
    openEspaces = false;
    openConcours = false;
    $("#T_identites").css({zIndex:"0"});
    $("#T_Affiches").css({zIndex:"0"});
    $("#T_Espaces").css({zIndex:"0"});
    $("#T_Concours").css({zIndex:"0"});
}
function resetEspaces(){
    $("#T_identites").find(".contentSousMenu").slideUp(100);
    $("#T_Editions").find(".contentSousMenu").slideUp(100);
    $("#T_Affiches").find(".contentSousMenu").slideUp(100);
    $("#T_Concours").find(".contentSousMenu").slideUp(100);
    openIdentites = false;
    openAffiches = false;
    openConcours = false;
    openEditions = false;
    $("#T_identites").css({zIndex:"0"});
    $("#T_Editions").css({zIndex:"0"});
    $("#T_Affiches").css({zIndex:"0"});
    $("#T_Concours").css({zIndex:"0"});
}
function resetConcours(){
    $("#T_identites").find(".contentSousMenu").slideUp(100);
    $("#T_Editions").find(".contentSousMenu").slideUp(100);
    $("#T_Affiches").find(".contentSousMenu").slideUp(100);
    $("#T_Espaces").find(".contentSousMenu").slideUp(100);
    openIdentites = false;
    openAffiches = false;
    openEspaces = false;
    openEditions = false;
    $("#T_identites").css({zIndex:"0"});
    $("#T_Editions").css({zIndex:"0"});
    $("#T_Affiches").css({zIndex:"0"});
    $("#T_Espaces").css({zIndex:"0"});
}
function masqueSousMenuTravaux(){
    $("#T_identites").find(".contentSousMenu").hide();
    $("#T_Editions").find(".contentSousMenu").hide();
    $("#T_Affiches").find(".contentSousMenu").hide();
    $("#T_Espaces").find(".contentSousMenu").hide();
    $("#T_Concours").find(".contentSousMenu").hide();
}
