/**
 * @package Archaic_Horizon
 * @copyright Copyright (c) 2009, Dan Bettles 
 * @author Dan Bettles <danbettles@yahoo.co.uk>
 */

archaichorizon.releasesShow = {

    /**
     * Returns a reference to the container of the featured item on this page
     * 
     * @return {jQuery}
     */
    getFeature: function () {
        return jQuery('div#feature');
    },

    /**
     * Positions the "return" button to the left of the release
     */
    positionReturnButton: function () {
        archaichorizon.alignTo(this.getFeature().find('p.pagecontrols a.return'), this.getFeature(), 'lt');
    },

    hijaxCoverBrowser: function () {
        jQuery('div.coverbrowser p.cover-current a').click(function () {
            var aMatch = jQuery('div.coverbrowser ul.pagination a.pagination-current')
                    .attr('href').match(/\/releases\/show\/([^\?]+)\?(.*)/);
        
            if (aMatch !== null) {
                jQuery.fancybox({
                    padding: 12,
                    width: 600,
                    height: 621,  /*= 600 + 6 + 15*/
                    autoScale: false,
                    href: '/coverbrowser-index.php?label_release_id=' + aMatch[1] + '&' + aMatch[2],
                    type: 'iframe'
                });
            }
        
            return false;
        });
    }
};

jQuery(function () {
    archaichorizon.releasesShow.positionReturnButton();

    archaichorizon.releasesShow.hijaxCoverBrowser();

    jQuery(window).resize(function () {
        archaichorizon.releasesShow.positionReturnButton();
    });
});
