$(document).ready(function(){

    // Artist box setup
    $('div.artistname').hide();
    $('div.artistindex.home p').hide();

    // Artist box hover
    $('div.artistbox').hover(function(){
        $(this).children('div.artistname').show();
        $(this).children('p').show();
        $(this).children('p').children('a').addClass('hovered');
    }, function(){
        $(this).children('div.artistname').hide();
        $(this).children('div.artistindex.home p.homename').hide();
        $(this).children('p').children('a').removeClass('hovered');
    });

    // Artist box click
    $('div.artistbox').click(function(){
        var linkto = $(this).children('p').children('a').attr('href');

        window.location = linkto;
    });


    // Homepage tours
    $('div.bluepanel.tours div.tour').hide();
    $('div.bluepanel.tours div.tour:first').show();
    $('div.bluepanel.tours div.tourjump:first').addClass('active');

    $('div.bluepanel.tours div.tourjump').click(function(){
        $('div.bluepanel.tours div.tourjump').removeClass('active');
        $(this).addClass('active');
        $('div.bluepanel.tours div.tour').fadeOut();
        $('div.bluepanel.tours div#dwc-' + $(this).attr('id')).fadeIn();
    });


    // Homepage news
    $('div.bluepanel.news div.news').hide();
    $('div.bluepanel.news div.news:first').show();
    $('div.bluepanel.news div.newsjump:first').addClass('active');

    $('div.bluepanel.news div.newsjump').click(function(){
        $('div.bluepanel.news div.newsjump').removeClass('active');
        $(this).addClass('active');
        $('div.bluepanel.news div.news').fadeOut();
        $('div.bluepanel.news div#dwc-' + $(this).attr('id')).fadeIn();
    });



    // Homepage Carousel
    var width = Math.floor(950 / jQuery('div.artists div.artist').size());

    jQuery('div.artists div.artist:last').addClass('right');

    jQuery('div.artists div.artist').attr('width', width);
    jQuery('div.artists div.artist img').attr('width', width - 2);


    jQuery('div.artists div.artist').hover(function(){

        var artistheight = 140;

        if(jQuery('div.artistindex').hasClass('large'))
        {
            artistheight = 350;
        }

        var position   = jQuery(this).position();
        var artistleft = 186 - width;
        var artisttop  = artistheight - jQuery(this).height();
        var leftalign  = Math.floor(position.left - artistleft / 2);
        var topalign   = Math.floor(0 - artisttop / 2);

        var image  = jQuery(this).children('a').children('img').attr('src');
        var link = jQuery(this).children('a').attr('href');
        var name   = jQuery(this).children('a').children('img').attr('alt');

        jQuery('div.artists').append('<div class="artistpopup" style="top:' + topalign + 'px; left:' + leftalign + 'px;"><a href="' + link + '"><img src="' + image + '" alt="" /><div class="frame"></div></a><p>' + name + '</p></div>');

    }, function(){
        jQuery('div.artists').remove('div.artistpopup');
    });

    jQuery('div.artistpopup').live('mouseout', function(){
        jQuery('div.artistpopup').remove();
    });
    
});

