//*****************************Constantes***************************************
var PATH_FOND = 'http://www.pep76.asso.fr/css/images/';
var BACK_HOVER = 'tab_hover.png';
var BACK_REPOS = 'tab_repos.png';

var PATH_MAP76 = 'http://www.pep76.asso.fr/css/images/sms/carte_76.png';

//*****************************diaporama****************************************
var boolPreloadDiapo = false;

function diapo()
{
    $(document).ready(function()
    {
        $('#diaporama').cycle(
        {
            fx: 'fade',
            timeout: 7000,
            speed: 2500
	});
    });
}

function preload_diapo()
{
    $(document).ready(
    function()
    {
        $('#header').append('<div id="loader_diapo"><p>Chargement des images cours...</p></div>');
        $('#loader_diapo').css("opacity", "0.7");

        var z = 0; //initialise les z-index
        var nbImg = 0;
  
        $('#diaporama img').each(function()
        {
            //alert('test');
            z++;
            var img = new Image();
            img.src = $(this).attr('src');

            if(boolPreloadDiapo == false)
            {
                nbImg++;

                if(nbImg == z) //supp le calque qd ttes img st prechargees
                {
                    boolPreloadDiapo = true;
                    $('#loader_diapo').fadeOut('slow');
                }
            }
            else{$('#loader_diapo').fadeOut('slow');}
        });
    });
}

//****************************navigation****************************************
var current_page;

function anim_menu()
{
    $(document).ready(
    function()
    {
        $('#navi_list .top_li .top_a')
        .mouseover(function()
        {          
            if(!$(this).is("#focus"))
            {
                $(this).css({color: '#4269b7'}); //bleu 3471b7 attention pas le meme que les onglets car deformation
                $(this).parent('li').css("background-image", "url("+PATH_FOND+BACK_HOVER+")");
                $(this).css("background-image", "url("+PATH_FOND+BACK_HOVER+")");
            }            
        })
        .mouseout(function()
        {
            //if($(this).children('a#focus').length == 0)
            if(!$(this).is("#focus"))
            {
                $(this).css({color: '#ffffff'});
                $(this).parent('li').css("background-image", "url("+PATH_FOND+BACK_REPOS+")");
                $(this).css("background-image", "url("+PATH_FOND+BACK_REPOS+")");
            }            
        })
    });
}

function drop_menu()
{
    $(document).ready(
    function()
    {
	$('#navi_list .top_li').hover(function()
        {
            if($(this).children('ul').length > 0)
            {
                $(this).children('ul').fadeIn("fast");
                //$('ul', this).slideDown(500);
            }
        }
	,function()
        {
            if($(this).children('ul').length > 0)
            {
                $(this).children('ul').fadeOut("fast");
                //$('ul', this).slideUp(500);
            }
        });

        $('#navi_list .sub_li').mouseover(function ()
        {          
            $(this).children('a').css("color","#d9cbac");
            $(this).children('a').stop().animate({paddingLeft: "10px"}, 150 );
        });
        $('#navi_list .sub_li').mouseout(function ()
        {
            $(this).children('a').css("color","#4269b7"); //bleu
            $(this).children('a').stop().animate({paddingLeft: "0"}, 150 );
        });
    });
}

//********************************icon contact**********************************
function drop_icon(div, icone)
{
    $(document).ready(
    function()
    {
        $(icone).mouseover(function ()
        {          
            $(div).stop().animate({top: "255px"}, 200 );
        })     
        .mouseout(function ()
        {
            $(div).stop().animate({top: "230px"}, 200 );
        });
    });
}

//**************************Set input focus*************************************
function setIeFocus()
{
    $(document).ready( function()
    {
        $('.inputText').addClass("idleField");

        $('.inputText').focus(function()
        {
            $(this).removeClass("idleField").addClass("focusField");
        });

        $('.inputText').blur(function()
        {
            $(this).removeClass("focusField").addClass("idleField");
        });
    });
}

//*******************************menu gauche************************************
function alt_menu_left()
{
    $(document).ready(
    function()
    {
        $('ul.menu_left_body li a')
	.mouseover(function()
        {          
            $(this).stop().animate(
            {
                paddingLeft: "30px"
            }, 200 );
        })
	.mouseout(function()
        {
            $(this).stop().animate(
            {
                paddingLeft: "15px"
            }, 200 );
        })
    });
}

//****************************actualites****************************************
function actu_hover()
{
    $(document).ready(
    function()
    {       
        $('#actus').children('a').find('img')
	.hover(function()
        {           
            var src = $(this).attr("src").match(/[^\.]+/) + "_hover.png";
            //alert(src);
            $(this).attr("src", src);
        },
	function()
        {
            var src = $(this).attr("src").replace("_hover", "");
            $(this).attr("src", src);
        });
    });
}

//*****************************Open liens utiles********************************
function deroul_liens(cible)
{
    $(document).ready(
    function()
    {
         $('img.img_drop').click(function()
         {
             $(cible).slideToggle('medium');
         });
     });
}

//***************************affichage carte 76*********************************

function preload_map()
{
    $(document).ready(
    function()
    {
        $('#map_76').append('<div id="loader"><p>Chargement de la carte en cours...</p></div>');
        $('#loader').css("opacity", "0.7");

        var z = 0; //initialise les z-index
        var nbImg = 0;

        var map = new Image();
        map.src = PATH_MAP76;
       
        $('#map_76 a').each(function()
        {
           z++;
           //alert('z :'+z);
           $(new Image()).attr('src', $(this).attr('name')).load(function()
           {             
               nbImg++;
               //alert('nbImg :'+nbImg);
               if(nbImg+1 == z) //supp le calque qd ttes img st prechargees + correction bug altitude
               {
                    $('#loader').fadeOut('slow');
               }
           });
        });         
    });
}

function hover_map76()
{
    $(document).ready(
    function()
    {
        $("#map_76 a").hover(function()
        {
            var img = $(this).attr('name');
            var titre = $(this).attr('title');
            var texte = $(this).children('input').val();

            document.getElementById("vignette").innerHTML =
            '<table>'+
                '<tr>'+
                    '<td width="250px"><img src="'+img+'" /></td>'+
                    '<td>'+titre+'<br/>'+texte+'</td>'+
                '</tr>'+
            '<table>';

            $("#vignette").stop(true, true).animate({opacity: "show", 'filter': ''}, "slow"); //filter pr bug ie
        },
        function()
        {
            $("#vignette").stop(true, true).animate({opacity: "hide", 'filter': ''}, "fast");
	    });
    });
}

jQuery(document).ready(function()
{
   $(document).mousemove(function(e)
   {
        var posX = 0;
        var posY = 0;

        posX = (e.pageX-510) + 'px';
        posY = (e.pageY-255) + 'px';

        $("#vignette").css('z-index', '100');
        $("#vignette").css("top",posY);
        $("#vignette").css("left",posX);
   });
})

//****************************Diaporama Chalet**********************************
function diaporama()
{       
    $(document).ready(function()
    {
        $('#gallery a').lightBox(
        {
            overlayBgColor: 'black',
            overlayOpacity: 0.8,
            imageLoading: PATH_FOND+'chargement3.gif',
            imageBtnClose: PATH_FOND+'fermer.png',
            imageBtnPrev: PATH_FOND+'previous.png',
            imageBtnNext: PATH_FOND+'next.png',
            containerResizeSpeed: 800,
            txtImage: 'Image',
            txtOf: 'sur'
        });
    });
}


