jQuery.noConflict();
var j$ = jQuery;

function teaser(id){
    var el = j$('div.teaser#teaser_' + id);
    
    var teaser_list = el.find('.teaser-entry');
    var first = el.find('.teaser-entry[rel=1]')
    var cur = el.find('.teaser-entry.active');
    
    var speed = 1500;
    
    cur.fadeOut(speed);
    
    if (cur.attr('rel') == teaser_list.length) {
        first.fadeIn(speed).addClass('active');
    } else {
        var next = el.find('.teaser-entry.active').next();
        next.fadeIn(speed).addClass('active');
    }
    cur.removeClass('active');
}

j$(document).ready(function(){
    //==========================================================================
    // Teaser
    //==========================================================================
    j$('div.teaser').each(function(){
        var id = Math.floor(Math.random()*(999999-0+1))+0;
        j$(this).attr({ 'id' : 'teaser_' + id });
        setInterval("teaser(" + id + ")", 5000);
    });
    //==========================================================================
    // Teaser
    //==========================================================================
    
    
    
    //==========================================================================
    // Fancybox Initialization (ajax content accepted)
    //==========================================================================
    j$('.jqfancybox').live('mouseover', function(){
        j$(this).fancybox({
            "padding": 0,
            "speedIn": 300,
            "speedOut": 300,
            "changeSpeed": 300,
            "transitionIn": "elastic",
            "transitionOut": "elastic",
            "titlePosition": "over",
            "titleShow": true,
            "easingIn": "swing",
            "easingOut": "swing",
            "showCloseButton": true,
            "showNavArrows": true,
            "enableEscapeButton": true,
            "overlayShow": true,
            "overlayOpacity": 0.7,
            "overlayColor": "#FFFFFF",
            "centerOnScroll": false,
            "hideOnContentClick": true,
            "onComplete": function() {
                j$("#fancybox-wrap").hover(function() {
                    j$("#fancybox-title").show();
                }, function() {
                    j$("#fancybox-title").hide();
                });
            },
            "titleFormat": function(title, currentArray, currentIndex, currentOpts) {
                return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' of ' + currentArray.length + (title.length ? ' : &nbsp; ' + title : '') + '</span>';
            }
        });
    });
    //==========================================================================
    // Fancybox Initialization
    //==========================================================================
});
