$(function(){

	// Accordion
	$("#accordion").accordion({ header: "h3" });

	//hover states on the static widgets
	$('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); },
		function() { $(this).removeClass('ui-state-hover'); }
	);

	$(".program_artist_info").draggable({handle:'p.movehandle'});
});



Cufon.replace('.cufon');
Cufon.replace('#col_right h1');
Cufon.replace('#col_right h3');
Cufon.replace('#program h1');
Cufon.replace('#program h3');
Cufon.replace('.fotoheader');

var artistBox = {
    cache               : [],
    artistblock         : '.artist_info',
    artistname          : '.artist_info h3',
    artistdescription   : '.artist_info .artistdescription',
    artistimage         : '.artist_picture',
    artistinfolinks     : 'a.artistinfo',
    artistreadmore      : '.artist_info a.readmore',

    loadinfo : function( id, hideimage ) {
        hideimage = hideimage != 'undefined' ? hideimage : false;

        if (typeof this.cache[id] == 'undefined') {
            $.ajax({
                url: '/dconn/json/entity.get.php',
                dataType: 'json',
                data: {'id' : id, 'ent' : 'PP_ArtistInfo'},
                success: function(data, state) {
                    if (state == 'success') {
                        artistBox.cache[ data.objects[0]['id'] ] = data.objects[0];
                        artistBox.loadinfo( data.objects[0]['id'], hideimage );
                    }
                }
            });
        } else {
            if (data = this.cache[id]) {

                if (data.contentsmall && data.contentsmall.substring(0,3) != '<p>')
                    data.contentsmall = '<p>' + data.contentsmall + '</p>';

                $(this.artistdescription).html((data.contentsmall ? data.contentsmall : ''));
                $(this.artistname).html(data.title);
                if (data.url) {
                    $(this.artistreadmore).css('display', 'block');
                    $(this.artistreadmore).attr('href', data.url);
                } else
                    $(this.artistreadmore).css('display', 'none');

                if (data.goticon  == true)
                    $(this.artistimage).css({
                        'background-image'  : 'url(' + data.icon_url + ')',
                        'background-position' : 'center center',
                        'display'           : 'block'
                    });
                else
                    $(this.artistimage).css({
                        'background-image'  : 'none',
                        'background-color'  : '#000',
                        'display'           : (hideimage == true ? 'none' : 'block')
                    });
            }
        }
    },

    init    : function()
    {
        $(this.artistinfolinks).click(function() {
            if ($(this).hasClass('mustdisplayblock'))
                $(artistBox.artistblock).css('display', 'block');

            artistBox.loadinfo(this.rel, $(this).hasClass('hideimagewhennotfound'));
            return false;
        });
    }
}
$(document).ready(function() {
    artistBox.init();
});

$(window).load(function() {
	$("img").each(function () {
		if ($(this).attr("align")=='left')
			$(this).css({
				'margin' : '0 10px 0 0'
			});
		else if ($(this).attr("align")=='right')
			$(this).css({
				'margin' : '0 0 0 10px'
			});
	});
});

