

function checkFields(fields){
    /*
    if (document.getElementById("tx_locator_pi1_zipcode").value == "") {
        document.getElementById("tx_locator_pi1_city").value = "Eisenach";
        $("#content-text .radius select").val("1000");
    }
    */
    if ($("#content-text #tx_locator_pi1_zipcode").val() == "") {
        $("#content-text #tx_locator_pi1_city").val('Eisenach');
        $("#content-text .radius select").val("50000");
    }
    
    //document.forms.locator.submit();
    $('#content-text .locator-search form').submit();    
}

function checkFieldsSidebar(fields){
    if ($("#sidebar #tx_locator_pi1_zipcode").val() == "") {
        $("#sidebar #tx_locator_pi1_city").val('Eisenach');
        $("#sidebar .radius select").val("50000");
    }
    //document.forms.locator.submit();
    $('#sidebar .locator-search form').submit();    
}

$(document).ready(function(){
    
    //button sidebar
    $('#sidebar .tx_locator_pi1_submit_button2').click(function(event) {
        checkFieldsSidebar();
    });    
    
    //button main map
    $('#content-text .tx_locator_pi1_submit_button').click(function(event) {
        checkFields();
    });    
    
    // Catch Menu click and submit form
    $('#nav132 a').click(function(event) {
        event.preventDefault();
        $("#sidebar #tx_locator_pi1_city").val('Eisenach');
        $("#sidebar .radius select").val("50000");
        $('#sidebar .locator-search form').submit();  
    });    
    
    // Enter-button to submit zipcode search form in sidebar
    $('#sidebar .locator-search #tx_locator_pi1_zipcode').keypress(function(event)
    {
        var keycode = (event.keyCode ? event.keyCode : event.which);
        if(keycode == '13'){
            checkFieldsSidebar();
        }
    });    
    
    // Enter-button to submit zipcode search form in main map
    $('#content-text .locator-search #tx_locator_pi1_zipcode').keypress(function(event)
    {
        var keycode = (event.keyCode ? event.keyCode : event.which);
        if(keycode == '13'){
            checkFields();
        }
    });    
    
    // automaticall submit locator form if it's displayed in content area
    //if (false)
    if ($('#content-text .tx_locator_searchform').length > 1)
    {
        //document.getElementById("tx_locator_pi1_city").value = "Hatzfeld/Eder";
        //$('.tx-locator-pi1 form').submit();
    }
        
    /*
    if ($("#mapAll").length)
    {
        GEvent.addListener(map, "visible_changed", function()
        {
            console.log("test");
        });
        
        GEvent.addListener(map, "moveend", function()
        {
            console.log("moveend");
        });
    }
    */

    $("input#search-input").bind(
        'focus',
        function(){
            $("input#search-input").val("")
        }
    );


    

    

    $('#theme').cycle({ slideExpr: 'img' });
/*
    // center gallery single view
    $('#content .billitongallery-singlepic-pic').each(function()
        {
            var width = $('.billitongallery-singlepic-pic').width();
            var margin = '-' + Math.round(width/2);
            
            $(this).css({
                position:   'relative',
                left:       '50%',
                marginLeft: margin + 'px'
            });
        });
*/

    jQuery('a.lightbox').fancybox(
    {
        zoomSpeedIn:   300,
        zoomSpeedOut:  300,
        overlayShow:   true,
        titlePosition: 'inside' // alternativen: 'over' (transparent), 'outside' (achtung: nur einzeiliger text moeglich)
    });

    // fancybox for gallery - no titles are set here
    jQuery('a.thickbox').fancybox(
    {
        zoomSpeedIn:   300,
        zoomSpeedOut:  300,
        overlayShow:   true,
        titleShow:     false
    });


    /* center billiton_gallery singleView */
    function centerSingle()
    {
        $('#content .billitongallery-singlepic-pic').each(function()
        {
            var width = $('.billitongallery-singlepic-pic').width();
            var margin = '-' + Math.round(width/2);
            
            $(this).css({
                position:   'relative',
                left:       '50%',
                marginLeft: margin + 'px'
            });
        });
    }
    



    // call it for initial centering
    centerSingle();


    /* center billiton_gallery thumbnails */
    
    function centerThumbs()
    {
        $('#content .picrow-inner').each(function()
        {
            var width = $('.picrow-inner').width();
            var marginL = '-' + Math.round(width/2);
            
            var heightInner = $('.picrow-inner').height();
            var heightOuter = $('.thumb-view').height();
            var marginB = Math.round((heightOuter - heightInner)/2);
            
            $(this).css({
                position:   'relative',
                left:       '50%',
                marginLeft: marginL + 'px',
                top: marginB + 'px'
            });
        });
    }
    
    // call it for initial centering
    centerThumbs();

    /**
     * Re-center thumbs after each click.
     *
     * two important facts:
     * 1. bind event not on buttons, but on their parents (because of event bubbling, the parent
     *    get's the event _after_ the button = our click handler is called after the gallery click handler
     * 2. bind not only click, but also dblclick event (gallery plugin binds to dblclick aswell, to
     *    allow faster browsing through the thumbnails)
     *
     * additional information:
     * - for more information on events and especially event order see here: http://www.quirksmode.org/js/events_order.html
     * - jquery by default calls events on the bubbling phase and NOT on the capturing phase (because capturing phase is not supported by IE = not cross-browser)
     */
    $('.btn-browse-page-back, .btn-browse-page-fwd').parent().bind('click dblclick', centerThumbs);

    // teaser - make h1 a link
    $('.teaser-0, .teaser-1').each(function()
    {
        var missingLink = $(this).find('.csc-textpic dt').children('a').clone();
        missingLink = missingLink.empty();
        $(this).find('h1').wrapInner(missingLink);
    });
    
    $('body').addClass('js');

    // menüpunkte zentrieren
    $('#inpage-menu li a').each(function () {
        //$(this).text().wrap('<span class="wrp"></span>');
        var spanHeight = $(this).find('span.wrp').height();
        if(spanHeight < 18){
            $(this).addClass('oneline');

        };
    });

    $('.content-rows .content-row-1 li:last, .content-rows .content-row-2 li:last, .content-rows .content-row-3 li:last ').css({
        'background' : 'url(/fileadmin/layouts/main/public/gfx/background-last.png) no-repeat 0 0',
        'padding-bottom' : '2px'    
    });

});


