
// milliseconds
var slideshow_fadingspeed = 2000;
var slideshow_pause = 5000;

var container_fadingspeed = 500;

var tx_FreshMapMenu_Menu_ActItem = null;

$(document).ready(function(){

    $("#Butterflybigleft").ppdrag({ zIndex: 10000 });
    $("#Butterflybigright").ppdrag({ zIndex: 10000 });
    $("#Butterflysmall").ppdrag({ zIndex: 10000 });

    $(window).resize(function() {
        resizer();
    });

    $('body a').each(function() {
        $(this).focus(function() {
            if ( $(this).blur() ) { $(this).blur(); }
        })
    });

    startSlideshow();

    if( $(".tx-erdalgallery-pi1").length > 0 ) {
      $().piroBox({
        my_speed: 400,
        bg_alpha: 0.8,
        slideShow : true,
        slideSpeed : 4,
        close_all : '.piro_close,.piro_overlay'
      });
    }

    if( $('.tx_FreshMapMenu').length > 0 ) {
        start_tx_FreshMapMenu();
    }
    
    if( $('.tx_pp_map').length > 0 ) {
        start_tx_pp_map();
    }
    $(window).trigger("resize");
    resizer();	

});

function startSlideshow() {

    $('#Slideshow').bxSlider({
        mode: 'fade',
        speed: slideshow_fadingspeed,
        pause: slideshow_pause,
        auto: true,
        controls: false,
        auto_direction: 'left',
        next_text: 'next image',
        prev_text: 'previous image',
        width: 462,
        height: 318,
        wrapper_class: 'ssc'
    });

}

function start_tx_FreshMapMenu() {

    if(tx_FreshMapMenu_Menu_ActItem == null) {
        tx_FreshMapMenu_Menu_ActItem = $('.tx_FreshMapMenu_Menu ul li:first a');
        $(tx_FreshMapMenu_Menu_ActItem).addClass('tx_FreshMapMenu_Menu_ActItem');

        var MapIndex = $(tx_FreshMapMenu_Menu_ActItem).attr('href').replace('#','');
        var MapName = '#tx_FreshMapMenu_MainMap_' + MapIndex;
        var TextName = '#tx_FreshMapMenu_Text_' + MapIndex;
        var InfoTextName = '.tx_FreshMapMenu_Map_InfoText_' + MapIndex;
        var UseMapSrc = '#'+MapIndex + '_map';
        var NewMapSrc = $(MapName).attr('src');
        var NewTextHTML = $(TextName).html();
        var NewInfoTextHTML = $(InfoTextName).html();

        $('#tx_FreshMapMenu_Text').fadeOut('250');
        $('.tx_FreshMapMenu_Map_InfoText').fadeOut('250');
        $('#tx_FreshMapMenu_MainMap').fadeOut('250', function(){
            $('#tx_FreshMapMenu_MainMap').attr('src', NewMapSrc );
            $('#tx_FreshMapMenu_MainMap').attr('usemap', UseMapSrc );
            $('#tx_FreshMapMenu_Text').html( NewTextHTML );
            $('.tx_FreshMapMenu_Map_InfoText').html( NewInfoTextHTML );
           
            $('#tx_FreshMapMenu_MainMap').fadeIn('250');
            $('#tx_FreshMapMenu_Text').fadeIn('250');
            $('.tx_FreshMapMenu_Map_InfoText').fadeIn('250');
            $(window).trigger("resize");
        })
        $('.tx_FreshMapMenu_InfoImage_BigMapLink').attr('target','_blank');
        var pageUID =  parseInt( MapIndex.replace('MM0','') ) + 25;
        $('.tx_FreshMapMenu_InfoImage_BigMapLink').attr('href','index.php?id='+pageUID);
        
        $('.tx_FreshMapMenu_InfoImage_BigMapLink').click( function() {
            var bigmapwin= window.open('index.php?id='+pageUID, "bigmapwin", "width=960,height=530,menubar=no,location=no,resizable=no,scrollbars=no,toolbar=no");
            bigmapwin.focus();
            return false
        }); 
    }

    $(".tx_FreshMapMenu_Menu a").each(function(){

        $(this).click(function(){
            $(tx_FreshMapMenu_Menu_ActItem)
                .removeClass('tx_FreshMapMenu_Menu_ActItem')
                .css('background', 'transparent');
            tx_FreshMapMenu_Menu_ActItem = this;
            $(tx_FreshMapMenu_Menu_ActItem)
                .addClass('tx_FreshMapMenu_Menu_ActItem')
                .css('background', '#58651d');

            var MapIndex = $(this).attr('href').replace('#','');
            var MapName = '#tx_FreshMapMenu_MainMap_' + MapIndex;
            var TextName = '#tx_FreshMapMenu_Text_' + MapIndex;
            var InfoTextName = '.tx_FreshMapMenu_Map_InfoText_' + MapIndex;            
            var UseMapSrc = '#'+MapIndex + '_map';
            var NewMapSrc = $(MapName).attr('src');
            var NewTextHTML = $(TextName).html();
            var NewInfoTextHTML = $(InfoTextName).html();

            $('#tx_FreshMapMenu_Text').fadeOut('250');
            $('.tx_FreshMapMenu_Map_InfoText').fadeOut('250');
            $('#tx_FreshMapMenu_MainMap').fadeOut('250', function(){
                $('#tx_FreshMapMenu_MainMap').attr('src', NewMapSrc );
                $('#tx_FreshMapMenu_MainMap').attr('usemap', UseMapSrc );
                $('#tx_FreshMapMenu_Text').html( NewTextHTML );
                $('.tx_FreshMapMenu_Map_InfoText').html( NewInfoTextHTML );
                $('#tx_FreshMapMenu_MainMap').fadeIn('250');
                $('#tx_FreshMapMenu_Text').fadeIn('250');
                $('.tx_FreshMapMenu_Map_InfoText').fadeIn('250');
                $(window).trigger("resize");
            })

            if( parseInt( MapIndex.replace('MM0','') ) == 4 ) {
    	        $('.tx_FreshMapMenu_InfoImage_BigMapLink').attr('href','index.php?id=5');
            	$('.tx_FreshMapMenu_InfoImage_BigMapLink').attr('target','_top');
            	$('.tx_FreshMapMenu_InfoImage_BigMapLink').unbind('click');
            } else {
            	var pageUID = parseInt( MapIndex.replace('MM0','') ) + 25;
    	        $('.tx_FreshMapMenu_InfoImage_BigMapLink').attr('href','index.php?id='+pageUID);
            	$('.tx_FreshMapMenu_InfoImage_BigMapLink').attr('target','bigmapwin');
            	
                $('.tx_FreshMapMenu_InfoImage_BigMapLink').click( function() {
                    var bigmapwin= window.open('index.php?id='+pageUID, "bigmapwin", "width=960,height=530,menubar=no,location=no,resizable=no,scrollbars=no,toolbar=no");
                    bigmapwin.focus();
                    $(window).trigger("resize");
                    return false
                });            	
            	
            }
            return false;
        })


        
        $(this).hover(

            function () {
                if( $(this).hasClass('tx_FreshMapMenu_Menu_ActItem') == false )
                    $(this).css('background', '#92A408');
            },

            function () {
                if( $(this).hasClass('tx_FreshMapMenu_Menu_ActItem') == false )
                    $(this).css('background', 'transparent');
            }
        );


    })

    $('#MM01_map area').each(function() {
        $(this).hover(

                function (e) {
                    if  ($.browser.mozilla) {
                        var mousePosX = e.layerX;
                        var mousePosY = e.layerY;
                    } else {
                        if  ($.browser.webkit) {
                            var mousePosX = e.offsetX - 210;
                            var mousePosY = e.offsetY - 399;
                        } else {
                            var mousePosX = e.offsetX;
                            var mousePosY = e.offsetY;
                        }
                    }

                    if(mousePosX > 129 && mousePosY > 160) {
                        $('.tx_FreshMapMenu_InfoImage').css('top', '4px');
                    } else {
                        $('.tx_FreshMapMenu_InfoImage').css('top', '164px');
                    }
                    var imageSRC = '#tx_FreshMapMenu_InfoImage_' + $(this).attr('id');
                    var InfoImage = $(imageSRC).attr('src');
                    $('#tx_FreshMapMenu_InfoImage').attr('src', InfoImage);
                    $('.tx_FreshMapMenu_InfoImage').stop(true,true).fadeIn('30');
                },

                function (e) {
                    $('.tx_FreshMapMenu_InfoImage').stop(true,true).fadeOut('30');
                }

        );
    })

    $('#MM02_map area').each(function() {
        $(this).hover(

                function (e) {
                    if  ($.browser.mozilla) {
                        var mousePosX = e.layerX;
                        var mousePosY = e.layerY;
                    } else {
                        if  ($.browser.webkit) {
                            var mousePosX = e.offsetX - 210;
                            var mousePosY = e.offsetY - 399;
                        } else {
                            var mousePosX = e.offsetX;
                            var mousePosY = e.offsetY;
                        }
                    }

                    if(mousePosX > 129 && mousePosY > 160) {
                        $('.tx_FreshMapMenu_InfoImage').css('top', '4px');
                    } else {
                        $('.tx_FreshMapMenu_InfoImage').css('top', '164px');
                    }
                    var imageSRC = '#tx_FreshMapMenu_InfoImage_' + $(this).attr('id');
                    var InfoImage = $(imageSRC).attr('src');
                    $('#tx_FreshMapMenu_InfoImage').attr('src', InfoImage);
                    $('.tx_FreshMapMenu_InfoImage').stop(true,true).fadeIn('30');
                },

                function (e) {
                    $('.tx_FreshMapMenu_InfoImage').stop(true,true).fadeOut('30');
                }

        );
    })

}

function start_tx_pp_map() {
    
    $('#tx_pp_map_areas area').each(function() {
        $(this).hover(

                function (e) {
                    var htmlSRC = '#tx_pp_map_info_src_' + $(this).attr('href').replace('#','');
                    var Infohtml = $(htmlSRC).html();
                    $('.tx_pp_map_info').html(Infohtml);
                    $('.tx_pp_map_info').stop(true,true).fadeIn('30');
                },

                function (e) {
                    $('.tx_pp_map_info').stop(true,true).fadeOut('30');
                }

        );
        $(window).trigger("resize");
    })    	
	
}
