var fadetime = 4000;
var z_all = 0;
var aktBild = 0;
function hide_popup(ele) {
    ele.stop().animate({'opacity': 0, 'right': -10, 'bottom': 0}, 1000, function() {
        ele.parents('.hotspot').css('z-index', 3);
        ele.css('z-index', 1); 
    });
    
        ele.parents('.hs_frame').hide(0);
}
function fadeElement(fadetime, bild, text, container) {
    
    var width = (text.index(container+'.rahmen_inhalt') + 1) /  $(container+'.rahmen_inhalt').size() * 233;   
    //  var maxWidth = $('body').width()-240;
    // var maxHeight = $('body').height();
    var refer = $('.from_site').text();
resizeBG();
    //$('.ajax_animation .resizeable img').css('width',maxWidth);
    //$('.ajax_animation .resizeable img').css('height',maxHeight);
    $('.big_hotspot').hide(0);
    $('.hotspot').hide(0);
    //alert(refer);

    if (refer.search('aktuelles') == -1 && refer != 'http://www.warendorf.eu/') {
                
        if ($(container+'.rahmen_inhalt').size() == 1) {
                fadetime = 500;
        }
      
        if (bild.index(container+'.rahmen_bild') == text.index(container+'.rahmen_inhalt')) {
            text.fadeIn(fadetime, function() {
                          
                if (text.index(container+'.rahmen_inhalt') < $(container+'.rahmen_inhalt').size()-1) {    

                    text.fadeOut(fadetime, function() { 
                        fadeElement(fadetime, bild, text.next(), container);
                        
                    });
                } else {
                    $('#abbruchbutton').hide(0);
                   
                 if (text.index(container+'.rahmen_inhalt') == $(container+'.rahmen_inhalt').size()-1) {
                 $('#abbruchbutton').hide(0)
                 window.setTimeout(function(){

                 $('.ajax_animation').fadeOut(800, function(){
                    hide_popup($('.highslide-html-content, .animation'));
                    $('.QOverlay').remove();
                        $('.ajax_animation').css('display', 'none');
            			$('.ajax_animation').html('');
            			$('.presenter-dimming').fadeOut(400);
                        return false;
                    
                    });
                    }, 2000);
                }
                
                if ($('.ajax-container .hotspot_edit').css('display') == 'none') {
                        $('.big_hotspot').fadeIn(500, function () {
                           $('.hotspot').fadeIn(500); 
                           $('.highslide-html-content, .animation').css({'opacity':0});
                        });
                    }
                    return false;
                }
            });
        } else {
            $.dequeue(bild);
            $.dequeue(bild.next());
            
            bild.next().fadeIn(fadetime/4, function() {
                bild.fadeOut(fadetime/2);
                $('.ajax_animation .presenter .fortschritt').animate({'width': width}, 1800);
                fadeElement(fadetime, bild.next(), text, container);
            });
        }
        
    } else {
        text.show(0);
        if ($('.ajax-container .hotspot_edit').css('display') == 'none') {
            $('.from_site').prepend($('.big_hotspot').css('display'));
            $('.big_hotspot').fadeIn(1000, function () {
               $('.hotspot').fadeIn(1000); 
               $('.highslide-html-content, .animation').css({'opacity':0});
            });
        }
    }
}

function startanimation(container) {

  	$(container+".rahmen_inhalt").css("display", 'none');
    $(".ajax_animation .rahmen_bild").css("display", 'none');
	$(container+".rahmen_bild:first").css("display", 'block');
    
    var width = 1 /  $(container+'.rahmen_inhalt').size() * 233;
    $('.ajax_animation .presenter .fortschritt').css('width', width);
    
    fadeElement(fadetime, $(container+'.rahmen_bild:first'), $(container+'.rahmen_inhalt:first'), container);
    
   /* $('.rahmen_inhalt').each(function(index) {
        if ($(this).children('p').size() > 0) {
            var tele = $(this); 
            $(this).append('<div class="sens" style="position:absolute; top:0; left:0; height:190px; width:420px; cursor:pointer;">&nbsp;</div>');
            
            $(this).children('.sens').mouseover(function () {
                tele.find('a').eq(0).css('background-image', 'url("fileadmin/system/image/newslink_over.png")');
            });
            $(this).children('.sens').mouseout(function () {
                tele.find('a').eq(0).css('background-image', 'url("fileadmin/system/image/newslink.png")');
            });
            
            $(this).children('.sens').click(function () {
                document.location.href = tele.find('p a').attr('href');
            });
        }
    });
*/

    $("#rahmen_rechts_unten").fadeIn(fadetime, function () {
        $("#rahmen_presenter").fadeIn(fadetime);		
    });
    if ($(container+'.rahmen_inhalt').size() > 1) {
      
		$('#abbrechenbutton').bind('mouseenter', function() {
			$('#abbrechenbutton img').css('display', 'block');
		});
		$('#abbrechenbutton').bind('mouseleave', function() {
			$('#abbrechenbutton img').css('display', 'none');
		});
        $('#abbruchbutton').show(0);
	}
       
    $('#abbruchbutton img.abbrechen_klein').mouseover(function() {
    	$(this).hide(0);
    	$('#abbruchbutton img.abbrechen_gross').show(0);
    });
    
    $('#abbruchbutton img.abbrechen_gross').bind('mouseleave', function(){
    	$(this).hide(0);
    	$('#abbruchbutton img.abbrechen_klein').show(0);
    });
    
  /*  
    $('#abbruchbutton img.abbrechen_gross').click(function() {
        $('#abbruchbutton img').unbind('mouseover mouseleave');
        $('#abbruchbutton img').hide(0);

    	$(container+'.rahmen_inhalt').stop().hide(0);
    	$(container+'.rahmen_inhalt').eq($(container+'.rahmen_inhalt').size()-2).show(0);

    	$(container+'.rahmen_bild').stop().hide(0);
    	$(container+'.rahmen_bild').eq($(container+'.rahmen_bild').size()-2).show(0);
    	$(this).parent().hide(0);
    });
    */
    
}

