/**
*
* @require MooTools version 1.2.2
*/

window.addEvents({
    'domready': function() {
        initDiscography();
    },
    'load': function() {
		openEcardDetection();
    }
});

function initDiscography() {
    
    var discoGraphy = $$('div.disco')[0];
    if (!discoGraphy) return false;

    var discoList = discoGraphy.getElements('ul.releases>li');
    var minH = 30;
    
    discoList.each(function(album) {

        album.orgh = album.getScrollSize().y;
       
        album.addEvents({
            'mouseenter': function() {
                this.tween('height', this.orgh);
            },
            'mouseleave': function() {
                this.tween('height', minH);
            }
        });

    });
}



/**
* openEcardDetection
* Opens a lightbox if a matching id of a link is detected in the page url.
*
* @author Ralph Meeuws <ralph.meeuws@efocus.nl>
*/
function openEcardDetection() {
	if (!document.getElement('.media')) return;
	
	var elMediaContainer = document.getElement('.media');
	var arrMediaLinks = elMediaContainer.getElements('a');
	var blnMediaLinkMatchFound = false;
	
	arrMediaLinks.each(function(elMediaLink){
		if ((elMediaLink.getElement('img') != null) && (blnMediaLinkMatchFound == false)) {
			var strMediaLinkId = elMediaLink.getProperty('id');
			var strMediaLinkHref = elMediaLink.getProperty('href');
			if (document.location.href.contains(strMediaLinkId)) {
				blnMediaLinkMatchFound = true;
				
				if (Shadowbox != undefined) {
					Shadowbox.open({
						player: 'img',
						content: strMediaLinkHref
					});
				}
			}
		}
	});
}


/**
* lightboxChanged
* Execute this when the lightbox starts changing.
*
* @author Ralph Meeuws <ralph.meeuws@efocus.nl>
*/
function lightboxChanged() {
	$('sb-info').setStyle('margin', 0);
}


/**
* lightboxLoadingFinished
* Execute this when the lightbox finished the transition.
*
* @author Ralph Meeuws <ralph.meeuws@efocus.nl>
*/
function lightboxLoadingFinished() {
	if (!document.getElement('.media')) return;

	var intLightboxBodyWidth = $('sb-body').getWidth();

	if (intLightboxBodyWidth < 142) {
		$('sb-info').setStyle('margin', '0 -20px');
	} else {
		$('sb-info').setStyle('margin', 0);
	}
}
