$(document).ready(function(){   
    /* add hover and links to our artist listing page */
    $(".listing").hover(
        function() {
            $(this).addClass("listing_hover");
            $(this).click(function () {
                document.location = $(this).children("h2").children("a").attr("href");
            });
        },
        function(){
            $(this).removeClass("listing_hover");
        }
    )
      
    /*  Firefox 2 has a text rendering issue involving Apple's CoreText ( http://jonnotie.nl/blog/fix-the-bad-text-rendering-in-safari/ ) 
    when using jQuery animations ( http://allinthehead.com/retro/328/when-bugs-collide-fixing-text-dimming-in-firefox-2 )
    it can be corrected by targeting just that version of Mozilla (1.8.xx) */

        if ($.browser.mozilla && parseFloat($.browser.version) < 1.9 && navigator.appVersion.indexOf('Mac') !== -1) {
            $('p').css('opacity', 0.9999);
        }
        
        if ($.browser.safari) {
            $('*').css('-webkit-opacity', 0.9999);
        }



   
    /* animate spnsor logos */    
	$(function() {
		$('#sponsor_ani').crossSlide({
		  sleep: 5, //in sec
		  fade: 2, //in sec
		  random: true
		}, [
		  { src: '/images/logos/logo1.png', href: 'http://www.newstalkzb.co.nz/' },
		  { src: '/images/logos/logo2.png', href: 'http://www.wcc.govt.nz/' },
		  { src: '/images/logos/logo3.png', href: 'http://www.dompost.co.nz/' },
		  { src: '/images/logos/logo4.png', href: 'http://www.nzfestival.nzpost.co.nz/' },
		  { src: '/images/logos/logo5.png', href: 'http://www.pacificblue.co.nz/' },
		  { src: '/images/logos/logo6.png', href: 'http://www.nzct.org.nz/' },
		  { src: '/images/logos/logo7.png', href: 'http://www.creativenz.govt.nz/' },
		  { src: '/images/logos/logo8.png', href: 'http://www.ghihotels.com/hgc/property.aspx?propertykey=38&citykey=' },
		  { src: '/images/logos/logo9.png', href: 'http://www.mojocoffee.co.nz/' },
		  { src: '/images/logos/logo10.png', href: 'http://www.springload.co.nz/' },
		  { src: '/images/logos/logo11.png', href: 'http://www.adshel.co.nz/' },
		  { src: '/images/logos/logo12.png', href: 'http://www.comtrustwn.co.nz/' },
		  { src: '/images/logos/logo13.png', href: 'http://www.pelorustrust.net.nz/' },
		  { src: '/images/logos/logo14.png', href: 'http://www.villamaria.co.nz/' }
		]);
	});
	

    /* change calendar "flap" colour */
	$("li#has_flap").mouseover(function(event){
        $("div#calendar_flap").addClass("hover_flap");
    });
    $("li#has_flap").mouseout(function(event){
        $("div#calendar_flap").removeClass("hover_flap");
    });
	

});

function closeJukebox() {
    $("#jukebox-wrapper").animate( { height:"165px" } , 900);        
}

function openJukebox() {
    $("#jukebox-wrapper").animate( { height:"322px" } , 900);
}

//jukebox functions
function getMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    } else {
        return document[movieName];
    }
}


function playArtist(guid) {
    if(jukeboxWindow && !jukeboxWindow.closed) {
        jukeboxWindow.playSong(guid);
    } else {      
        getMovie("jukebox").playSong(guid);    
    }
        
    return false;
}


function showTicketBox(e,guid,url) {   
    var event = e || window.event;    
    if (event.stopPropagation) {
        event.stopPropagation();
    } else {
        event.cancelBubble = true;
    } 
    
    $("#ticket-booking-alert").css("top",$("#artist-"+guid).offset().top+10);
    $("#ticket-booking-alert").css("display","block");
    
    $("#booking-link").attr("href",url);
    
    return false;
}

function hideTicketBox() {
    $("#ticket-booking-alert").css("display","none");    
    return false;
}

var jukeboxWindow=false;

function jukeboxPopUp() { 
    getMovie("jukebox").stopSong();
    
    if(!jukeboxWindow || jukeboxWindow.closed) {
        jukeboxWindow=window.open("/jukebox-popup/", "jukeboxWindow","location=0,status=0,resizable=yes,scrollbars=0,width=228,height=330,top=100,left=100");
    }
    
    jukeboxWindow.focus();
        
    return false;
}