(function($) {

        $.fn.tageshoroskop = function(userOptions) {

            var parent = $(this);
            //mh, not needed yet:
            var defaults = {};
            var options = $.extend(defaults,userOptions);

            var xmlPath = '/statics/typology/Tageshoroskop/tag_aktuell.xml';
            var textAreas = parent.children('#taho_text_areas').children();
            var boxes = parent.children('#taho_thumbnails').children('.taho_thumbnail_box');
            //on start, show random element
            var current = Math.round(Math.random() * 11);
            boxes.eq(current).addClass('taho_thumbnail_box_active');
            textAreas.eq(current).show();

            //load texts from XML
            $.ajax({
                type: "GET",
                url: xmlPath,
                dataType: "xml",
                success: function(xml) {
                    $(xml).find('sign').each(function(index){
                        textAreas.eq(index).children('.taho_text').prepend('<p>'+$(this).find('text').text()+'</p>');
                    });
                }
            });

            
            //observe every box and listen to clicks
            boxes.each(function(index, element) {
                var box = $(this);
                box.children('a').click(function() {
                    if(current != index) {
                        //hide all, fadeOut current, fadeIn new one 
                        boxes.removeClass('taho_thumbnail_box_active');
                        box.addClass('taho_thumbnail_box_active');
                        textAreas.eq(current).siblings().stop(true,true).hide()
                        .end().stop(true,true).fadeOut(function() {
                            textAreas.eq(index).stop(true,true).fadeIn();
                        });
                        current = index;
                    }
                    return false;
                });
            });

        };

})(jQuery);


(function($) {

    $.fn.tahoTextwechsel = function() {

        var parent = $(this);
        var links = parent.find('#taho_textlinks').children();
        var texts = parent.find('div.hd-text'); 
        var current = 1;
        var locked = false;
        var speed = 400;


        if (links.size() <= 1) {
        	current = 0;
        }
        
        links.eq(current).addClass('taho_current');
        texts.eq(current).show();

        links.each(function() {
            var me = $(this);
            var myNr = me.prevAll().length;
            $(this).click(function() {
                if(me.hasClass('taho_current') || locked)
                    return;

                locked = true;
                links.eq(current).removeClass('taho_current');
                me.addClass('taho_current');
                texts.eq(current).stop(true,true).fadeOut(speed, function() {
                    texts.eq(myNr).stop(true,true).fadeIn(speed);
                    locked=false;
                });
                current = myNr;
            
            });
        });


    };

})(jQuery);

