﻿$(document).ready(function() {
    /* Work-a-round for the missing of :first-child CSS in IE6 */
    $('.frontpage_row1 .item:first').addClass('first-child');
    $('.frontpage_row2 .item:first').addClass('first-child');
    $('ul.AspNet-Menu li:first').addClass('first-child');

    $('.readmore').click(function() { $('.event_text .textpreview').hide(); $('.event_text .textfull').show(); });

    $('.contentoffer .offers > div a').click(function(event) { event.preventDefault(); });

    $('.contentoffer .offers > div').click(function() {

        var offerLink = $(this).find('a');

        if (offerLink.attr('target') == '') { document.location = offerLink.attr('href'); } else { window.open(offerLink.attr('href'), offerLink.attr('target')); }

    });

    var divCount = 0;

    $('#top5events > div').each(function() { divCount++; });

    if (divCount > 1) { setInterval('eventSwitch()', 5000); }


    divCount = 0;

    $('.offers > div').each(function() { divCount++; });

    if (divCount > 1) { setInterval('currentofferSwitch()', 5000); }
});

/* Replacing headlines with dynamic fonts (images) */
/*Cufon.replace('#menutop a.AspNet-Menu-Link');
Cufon.replace('#menusub a.AspNet-Menu-Link');
Cufon.replace('h1');
Cufon.replace('h2');
Cufon.replace('h3');
Cufon.replace('h4', {
    hover: {
    color: '#565656'
    }
});
Cufon.replace('h5');*/

function eventSwitch() {

    var $old = null;
    var $next = null;

    $('#top5events > div').each(function() {

        if ($old != null && $next == null) {

            $next = $(this);
        }

        if ($(this).attr('class') == 'top5image') {

            $old = $(this);
        }
    });

    if ($next == null) {

        $next = $('#top5events > div:first');
    }

    if ($old == null || $next == null) {
        return;
    }

    $next.fadeIn(1500, function() { $next.removeClass('top5image_in').addClass('top5image'); });
    $old.fadeOut(1500, function() { $old.removeClass('top5image').addClass('top5image_in'); });
}

function currentofferSwitch() {

    var $old = null;
    var $next = null;

    $('.offers > div').each(function() {

        if ($old != null && $next == null) {

            $next = $(this);
        }

        if ($(this).attr('class') == 'active') {

            $old = $(this);
        }
    });

    if ($next == null) {

        $next = $('.offers > div:first');
    }

    if ($old == null || $next == null) {
        return;
    }

    $next.fadeIn(1500, function() { $next.removeClass('inactive').addClass('active'); });
    $old.fadeOut(1500, function() { $old.removeClass('active').addClass('inactive'); });
}