$(document).ready(function(){

    $('select#speedC').selectmenu({style:'dropdown'});
    $(".accueil a").html("accueil");
    $(".actu a").html("news");
    $(".staations").html("stations");
    $(".coonseils").html("conseil");
    $( "button, input:submit").button();
    $('.contentEcole').hide();
    $('.contentInscription').hide();
    $('.adr').hide();
    $('.contactEcole').hide();

    $("#navigation ul").hide();
    $(".menusub").mouseover(function(){
        $(this).find(".submenu").show();
        $('#jQuery').addClass('bgMenu');

    }).mouseout(function(){
        $('#jQuery').removeClass('bgMenu');
        $(this).find(".submenu").hide();

    })
});

var subs = {};
var currentOpenSub;

function ajaxMenuStations(id){
    if (id != currentOpenSub){
        $('.menuStation li').removeClass('menubghover');
        $('li[name="'+id+'"]').addClass('menubghover');

        if (subs[id] == undefined){
            $.get('scripts/php/jqueryMenu.php?id='+ id, function(data){
               subs[id] = data;
                $('.listStations').html(data);
                $('.listStations').slideDown()
            });
        } else {
            $('.listStations').html(subs[id]);
            $('.listStations').slideDown()
        }
        
        currentOpenSub = id;
    }
}


function showEcoleHistory(){
    $('.contentEcole').toggle("slow");
    $('.nextEcole').hide();
}

function showInscriptionHome(){
    $('.contentInscription').toggle("slow");
    $('.nextInscription').hide();
}

function onComplete(data, textStatus){
    $('div#lienEcole').append(data);
}

//a custom format option callback
var addressFormatting = function(text){
    var newText = text;
    //array of find replaces
    var findreps = [
    {
        find:/^([^\-]+) \- /g,
        rep: '<span class="ui-selectmenu-item-header">$1</span>'
    },

    {
        find:/([^\|><]+) \| /g,
        rep: '<span class="ui-selectmenu-item-content">$1</span>'
    },

    {
        find:/([^\|><\(\)]+) (\()/g,
        rep: '<span class="ui-selectmenu-item-content">$1</span>$2'
    },

    {
        find:/([^\|><\(\)]+)$/g,
        rep: '<span class="ui-selectmenu-item-content">$1</span>'
    },

    {
        find:/(\([^\|><]+\))$/g,
        rep: '<span class="ui-selectmenu-item-footer">$1</span>'
    }
    ];

    for(var i in findreps){
        newText = newText.replace(findreps[i].find, findreps[i].rep);
    }
    return newText;
}


