function fixSubmenuWidth(){
    $(".submenu:first").width($(".submenu:first").width()+2);
}
var inFocusAnimationIsRunning = 0;
var infocusSlideShowInterval;
var InFocusFadeInSpeed = 1000;
function inFocusSlideShow(){
    inFocusAnimationIsRunning = 1;
    if( $(".switch_tabs .tabMenu li.active").next("li").find("a").length == 0){
        $(".switch_tabs .tabMenu li:first").find("a").click();
    } else{
        $(".switch_tabs .tabMenu li.active").next("li").find("a").click();
    }
}
$(document).ready(function() {
        $(".printPage").click(function() {
                window.print();
                return false;
            });
        if(navigator.platform == "iPad") {
            $("#quickThemeSelector input.submit").css("background", "grey");
            $("#quickThemeSelector input.submit").css("padding", "0");
            $("#quickThemeSelector input.submit").css("width", "auto");
            $("#search input.submit").css("background", "grey");
            $("#search input.submit").css("padding", "0");
            $("#search input.submit").css("width", "auto");
        }
        $(".bookmark").click(function() {       
                var Text = document.title;
                var URL = self.location.href;
                if (window.sidebar.addPanel) { // firefox
                    window.sidebar.addPanel(Text, URL, "");
                } else if(window.opera && window.print) { // opera
                    var elem = document.createElement('a');
                    elem.setAttribute('href', URL);
                    elem.setAttribute('title', Text);
                    elem.setAttribute('rel', 'sidebar');
                    elem.click();
                } else if(document.all) { // ie
                    window.external.AddFavorite(URL, Text);
                }
                return false;
            });
        $(".bigFont").click(function() {
                changeTaille(2);
            });
        $(".smallFont").click(function() {
                changeTaille(-2);
            });
        $("#quickThemeSelector select").change(function(){
                if($(this).val().length>0) 
                    $(this).parents("form").submit();
            });        
        $("#quickThemeSelector > form").submit(function(){
                return ($("#quickThemeSelector select").val().length>0);
            });
        $(".switch_tabs div.content_tab").not(":first").hide();
        if($(".switch_tabs div.content_tab").length < 2){
            $(".switch_tabs ul.tabMenu").remove();
        } else {
            $(".switch_tabs ul.tabMenu").html("");
            $(".switch_tabs div.content_tab").each(function(i) {
                    i++;
                    $(this).attr("id", "inner_tab_focus_" + i);
                    $(".switch_tabs ul.tabMenu").append("<li class='tooltip_"+i+"'><a href='"+ "#inner_tab_focus_" + i +"'>"+i+"</a></li>");
                    var tooltipTitle = $(this).find("h3").html();
                    if($(this).find("img").length>0){
                        var tooltipImageSrc = $(this).find("img").attr("src");    
                        var tooltipImage = "<img src='"+$(this).find("img").attr("src")+"' with='83' height='69' align='top' style='margin-top:10px;display:block' />";
                    } else {
                        var tooltipImage = "";
                    } 
                    $(".switch_tabs ul.tabMenu li.tooltip_"+i).qtip({ content: {text: tooltipTitle + tooltipImage}, style: { width: 117, tip: 'bottomMiddle', name: 'light', color: '#595959', border: { color: '#3F95C3' } }, position: { corner: { target: 'topMiddle', tooltip: 'bottomMiddle' } } });
                });
        }
        $(".switch_tabs ul.tabMenu li:first").addClass("active");
        $(".switch_tabs .content_tab").hide();
        $(".switch_tabs").each(function() {
                $(this).find('.content_tab:eq(0)').show();
            });
        $(".switch_tabs .tabMenu a").click(function(){ 
                var activeContent = $(this.hash);
                $(this).parents('.switch_tabs').find('.content_tab:visible').fadeOut(InFocusFadeInSpeed, function(){activeContent.fadeIn(InFocusFadeInSpeed);});
                $(this).parent().siblings().removeClass('active');
                $(this).parent().addClass('active');
                this.blur();
                return false;});
        if (inFocusAnimationIsRunning == 0){
            infocusSlideShowInterval = setInterval("inFocusSlideShow()", 9000);
        }
        $("#blockFocusTabs").mouseout(function(){                
                if (inFocusAnimationIsRunning == 0){
                    InFocusFadeInSpeed = 2000;
                    infocusSlideShowInterval = setInterval("inFocusSlideShow()", 9000);
                }});
        $("#blockFocusTabs").mouseover(function(){
                InFocusFadeInSpeed = 500;
                clearInterval(infocusSlideShowInterval);
                inFocusAnimationIsRunning = 0; });
        $("dt.title_map").each(function(i){
                var pos = i+1;
                $(this).find("a:first").attr("href", "#inner_tab_siteMap_" + pos);
                $(this).next("dd").attr("id", "inner_tab_siteMap_" + pos); });
        $("dt.title_map a").click(function(){        
                var src = $(this).find("img:first").attr("src");
                src = "fileadmin/unesco/" + src;
                $(this).find("img:first").attr("src", src); });
        $("#sidebar .subcr h2").next("div.content").each(function(i){
                if($(this).find("a:visible, strong").length == 0){
                    $(this).prev("h2").hide();
                    $(this).hide(); }});
        var cal = $("#sidebar div.content iframe");
        if(cal.length>0) cal.parents("div.content").show().prev("h2").show();
        setTimeout("fixSubmenuWidth()", 1);
        $("body").click(function(){
                $("#bookmark-content").hide();
            });        
        $("a.share").click(function(){
                $(this).next("#bookmark-content").toggle();
                return false;
            });
        $("#actionsList a.send").click(function(){
                var w = window.open($(this).attr('href'), 'tipafriend', 'width=620,height=550,scrollbars=no,resizable=yes');
                w.focus();     
                return false;                
            });        
        if( $("#tip-to-friend").length>0){
            $("a.lnk_topPage").hide().prev("br").hide();
        }
        $("#siteName").next("p").find("a:contains(unesco.org)").click(function(){
                if(window.location.href.match(/unesco.org\/(\w\w)\//)==null){
                    return true;
                } else{
                    window.location.href = "http://"+location.host+ "/" + window.location.href.match(/unesco.org\/(\w\w)\//)[1] + "/";
                    return false;
                }                
            });
        $("body").append('<div id="unesco_gallery" style="display: none">'+
                         '<a class="prev" style="flo">&laquo;</a>'+ 
                         '<a class="next">&raquo;</a>'+ 
                         '<div class="info"><br />'+
                         '<img class="progress" src="fileadmin/unesco/images/ajax-loader.gif" />'+
                         '</div>');
        if($(".photo-gallery .csc-textpic-imagecolumn a.lightbox").length>0){
            $(".photo-gallery .csc-textpic-imagecolumn a.lightbox").overlay({ target: '#unesco_gallery', expose: '#f1f1f1' }).gallery({ autohide: false, speed: 400 });
        }
  });
 


