$.noConflict();
jQuery(document).ready(function($) {


    $('#load').click(function(e) {
        
        //Cancel the link behavior
        //        e.preventDefault();
        showLoading(e);
    //        //Get the A tag
    //        //		var id = $(this).attr('href');
    //
    //        //Get the screen height and width
    //        var maskHeight = $(document).height();
    //        var maskWidth = $(window).width();
    //
    //        //Set heigth and width to mask to fill up the whole screen
    //        $('#mask').css({
    //            'width':maskWidth,
    //            'height':maskHeight
    //        });
    //
    //        //transition effect
    //        $('#mask').fadeIn(500);
    //        $('#mask').fadeTo("fast",0.5);
    //
    //        //Get the window height and width
    //        var winH = $(window).height();
    //        var winW = $(window).width();
    //
    //        //Set the popup window to center
    //        $("#dialog").css('top',  winH/2-$("#dialog").height()/2);
    //        $("#dialog").css('left', winW/2-$("#dialog").width()/2);
    //
    //        //transition effect
    //        $("#dialog").fadeIn(1000);

    });
    
    //if close button is clicked
    $('.window .close').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();

        $('#mask').hide();
        $('.window').hide();
    });
    ////Loading Screen ende////


    $('.kwicks li div').css('opacity', 0);
    $('.kwicks').kwicks({
        min : 100,
        max : 400,
        spacing : 0
    });

    $('.kwicks li').hover(function() {
        $('.kwicks li div').css('opacity', 0);

        $(this).children('div').animate({
            opacity: 1
        }, 2000, function() {
            // Animation complete.
            });
    });

    $('#coin-slider').coinslider({
        width: 630, // width of slider panel
        height: 250, // height of slider panel
        spw: 7, // squares per width
        sph: 5, // squares per height
        delay: 3000, // delay between images in ms
        sDelay: 30, // delay beetwen squares in ms
        opacity: 0.9, // opacity of title and navigation
        titleSpeed: 500, // speed of title appereance in ms
        effect: 'rain', // random, swirl, rain, straight
        navigation: false, // prev next and buttons
        links : true, // show images as links
        hoverPause: true // pause on hover

    });

    //Autocomplete start
    $("#searchit").autocomplete("/fileadmin/php/get_branches_list.php", {
        width: 240,
        matchContains: true,
        //mustMatch: true,
        //minChars: 0,
        //multiple: true,
        //highlight: false,
        //multipleSeparator: ",",
        selectFirst: false
    });

    $("#ort").autocomplete("/fileadmin/php/get_plz_list.php", {
        width: 240,
        matchContains: true,
        //mustMatch: true,
        //minChars: 0,
        //multiple: true,
        //highlight: false,
        //multipleSeparator: ",",
        selectFirst: false
    });
    //Autocomplete end

    $(function() {
        $('#kategorie_erw').change(function(){
            $.ajax({
                url: ('/fileadmin/php/tmpl_erw_suche.php'),
                data: 'parent=' + $(this).val(),
                type: 'GET',
                timeout: 2000,
                //dataType: 'json',
                error: function() {
                    alert('Error loading json data!');
                },


                success: function(json){
                    var std_output = "";
                    std_output = $('#kategorie_erw').val();

                    if(std_output == "all"){
                        std_output = "<option value='all'>- alle -</option>";
                        $('#themengebiete_erw').html(std_output);
                        $('#branche_erw').html(std_output);
                    }
                    else {
                        $('#themengebiete_erw').html(json);
                    }
                }
            })
        });

        $('#themengebiete_erw').change(function(){
            $.ajax({
                url: ('/fileadmin/php/tmpl_erw_suche.php'),
                data: 'themenge=' + $(this).val(),
                type: 'GET',
                timeout: 2000,
                //dataType: 'json',
                error: function() {
                    alert('Error loading json data!');
                },
                success: function(themen){

                    var std_output = "";
                    std_output = $('#themengebiete_erw').val();

                    if(std_output == "all"){
                        std_output = "<option value='all'>- alle -</option>";
                        $('#branche_erw').html(std_output);
                    }
                    else {
                        $('#branche_erw').html(themen);
                    }
                }
            })
        });

    });

    $("#ort_erw").autocomplete("/fileadmin/php/get_plz_list.php", {
        width: 400,
        matchContains: true,
        //mustMatch: true,
        //minChars: 0,
        //multiple: true,
        //highlight: false,
        //multipleSeparator: ",",
        selectFirst: false
    });


    $("#unternehmen_erw").autocomplete("/fileadmin/php/get_keywords_list.php", {
        width: 400,
        matchContains: true,
        //mustMatch: true,
        //minChars: 0,
        //multiple: true,
        //highlight: false,
        //multipleSeparator: ",",
        selectFirst: false
    });
    //Slidedown Erweiterte Suche start

    $(".slidedown_suche").click(function(e){
        e.preventDefault();
        if($('#div_erw_suche_toggle').is(":hidden")){
            $('#div_erw_suche_toggle').slideDown("slow");
        } else{
            $('#div_erw_suche_toggle').slideUp('fast');
        }
    });

    //Slidedown Erweiterte Suche ende


    //erweiterte Suche submit
    $('#load_erw').click(function(e){
        //    e.preventDefault();
        //        alert('ext search')
        showLoading(e);
        $('#erweiterteSuche').submit();
    });

    function showLoading(e){
        //Cancel the link behavior
        e.preventDefault();
        //Get the A tag
        //		var id = $(this).attr('href');

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set heigth and width to mask to fill up the whole screen
        $('#mask').css({
            'width':maskWidth,
            'height':maskHeight
        });

        //transition effect
        $('#mask').fadeIn(500);
        $('#mask').fadeTo("fast",0.5);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center
        $("#dialog").css('top',  winH/2-$("#dialog").height()/2);
        $("#dialog").css('left', winW/2-$("#dialog").width()/2);

        //transition effect
        $("#dialog").fadeIn(1000);
    }

//    $("choose_basis").hover(
//      function () {
//        if($('#basic_options').is(":hidden")){
//            $('#basic_options').slideDown("slow");
//        }
//      },
//      function () {
//        if(!$('#basic_options').is(":hidden")){
//            $('#basic_options').slideUp('fast');
//        }
//      }
//    );
});

