(function($){
    $(document).ready(function() {
        $('#tabs_content').css('overflow', 'hidden');
        
        var labels = {};
        var lang = window.location.pathname.substr(1, 2);
        if(lang == 'en'){
            labels = {
                'adresse':  "Address",
                'ville':  "City",
                'region':  "Region",
                'province':  "Province",
                'phone':  "Phone number",
                'contact':  "More information",
                'close':  "Close",
                'url':  "Visit web site"
            };
        } else {
            labels = {
                'adresse':  "Adresse",
                'ville':  "Ville",
                'region':  "Région",
                'province':  "Province",
                'phone':  "Téléphone",
                'contact':  "Information supplémentaire",
                'close':  "Fermer la fenêtre",
                'url':  "Visitez le site web"
            };
        }
        
        var l = new Lieu({
            links: $$('.calendar_table a.lnk_lieu'),
            labels: labels,
            langue: lang
        });
        
        function showNewContent(txt, xml, xhr) {
            $('#tabs_content').show('slow', hideLoader);
            var links = $$('.calendar_table a.lnk_lieu');
            l.options.links = links;
            l.bindLinks();
        }
        function hideLoader() {
            //$('#load').fadeOut('normal');
        }

        var hash = window.location.hash.substr(1);
        var href = $('#group_tabs  a').each(function(){
            var href = $(this).attr('href');
            if(hash == href){
                var toLoad = hash//+'.html #tabs_content';
                toLoad += '?tstamp=' + new Date().getTime();
                //$('#tabs_content').load(toLoad)
                var self = this;
                function loadContent() {
                    $('#tabs_content').load(toLoad, null, showNewContent)
                    highlightLinks(self)
                }
                $('#tabs_content').hide('normal',loadContent);
            }
        });

        $('#group_tabs  a').click(function(){	  
            var toLoad = $(this).attr('href');//+' #tabs_content';
            //$('#load').remove();
            //$('#wrapper').append('<span id="load">LOADING...</span>');
            //$('#load').fadeIn('normal');
            var h = $(this).attr('href')//.substr(0,$(this).attr('href').length-5);
            toLoad += '?tstamp=' + new Date().getTime();
            function loadContent() {
                $.get(toLoad, null, function(html, status){
                    var page = $(html);
                    var div = null;
                    page.each(function(i, el){
                        el = $(el);
                        el.find("div").each(function(i, el){
                            if(el.id == "tabs_content")
                                div = el;
                        });
                    });
                    $("#tabs_content").html("");
                    $("#tabs_content").append( $(div).contents() );
                    showNewContent(html, null, null);
                });
                //$('#tabs_content').load(toLoad, null, showNewContent);
            }
            $('#tabs_content').hide('normal', loadContent);
            window.location.hash = h;
            return false;
            
        });

    });

})(jQuery);

function highlightLinks(obj) {
   var linkList = document.getElementById("group_tabs").getElementsByTagName("a");
   for (i = 0; i < linkList.length; i++) {
      linkList[i].className = "";
   }
   obj.className = "btnOver";
}
