// Onload document
$(document).ready( function () {

   

    
    // =========================================================================
    // Language menu

    // Hidden language_menu
    $("#language_menu").hide();

    $("#language").click( function () {
        // If the menu is displayed, we close it
        if ($("#language_menu:visible").length != 0) {
            $("#language_menu").slideUp("fast");
        }
        // we display the language_menu
        else {
            $("#language_menu").slideDown("fast");
        }
        // prevents follow the link
        return false;
    });

    $("body").click( function () {
        // Click outside language menu
        // If the menu is displayed, we close it
        if ($("#language_menu:visible").length != 0) {
            $("#language_menu").slideUp("fast");
        }
    });


    // =========================================================================
    // top menu Second Level

    // Hidden
    $("#top_menu li ul").hide();

//    $("#top_menu li").hover( function () {
//        // If the menu is not displayed, we open it
//        $("#top_menu li ul").hide();
//        $(this).children("ul").slideDown("fast");
//    },
//    function () {
//        // If the menu is not displayed, we open it
//        $(this).children("ul").fadeOut("fast");
//
//    });

    // =========================================================================
    // popup

   $("a[rel^='login']").prettyPopin({
			width : 280,
			opacity: 0.5,
			animationSpeed: 'fast',
			followScroll: true,
			loader_path: 'images/prettyPopin/loader.gif',
			callback: function(){

                        }
		});



   $("a[rel^='popup']").prettyPopin({
			width : 320,
			opacity: 0.5,
			animationSpeed: 'fast',
			followScroll: true,
			loader_path: 'images/prettyPopin/loader.gif',
			callback: function(){

                        }
		});
   $("a[rel^='freepopup']").prettyPopin({
			opacity: 0.5,
			animationSpeed: 'fast',
			followScroll: true,
			loader_path: 'images/prettyPopin/loader.gif',
			callback: function(){

                        }
		});

   $("#search_result").hide();


   $("#f_search_searchengine").keyup(function()
        {
            var searchbox = $(this).val();
            if (searchbox.length >3) {
                var dataString = 'f_search_searchengine='+ searchbox;
                if(searchbox=='') {}
                else {
                    $.ajax({
                        type: "GET",
                        url: "ajax/search/",
                        data: dataString,
                        cache: false,
                        success: function(html)
                        {
                            if ($("#search_result:visible").length == 0) {
                                $("#search_result").slideDown("fast");
                            }
                            if (html == '') {
                                $("#search_result").slideDown("fast");
                            }
                            $("#search_result").html(html).show();
                        }
                    });
                }
            }
            else {
                if ($("#search_result:visible").length != 0) {
                    $("#search_result").slideUp("fast");
                }
            }
            return false;
        });

    $("body").click( function () {
        if ($("#search_result:visible").length != 0) {
            $("#search_result").slideUp("fast");
        }
    });

   // ==========================================================================
    // Tooltips
    $("*[tooltip]").mouseover( function () {
        var tooltip = $(this).attr("tooltip");
        var html = $(this).html();
        $(this).html(html+'<div class="tooltip">'+tooltip+'</div>');
    });
    $("*[tooltip]").mouseout( function () {
        var tooltip = $(this).attr("tooltip");

        $("div[class^='tooltip']").remove();
    });

    // ==========================================================================
    // Preview
    $("*[preview]").mouseover( function () {
        var preview = $(this).attr("preview");
        var html = $(this).html();
        $(this).html(html+'<div class="preview"><img src="downloads/preview/'+preview+'" width="250" /><br />'+preview+'</div>');
    });
    $("*[preview]").mouseout( function () {
        var preview = $(this).attr("preview");

        $("div[class^='preview']").remove();
    });



        // =========================================================================
    // Tabs
    $(".tabContent").hide();
    $(".tabContent:first").show();

    $(".tab a").click(function() {
        $(".tab li").removeClass("active");
        $(this).parents("li").addClass('active');
        var idTab = $(this).attr("href");
        $(".tabContent").hide();
        $(idTab).show();
        return false;
    });

} ) ;