/**
* Configure Universal Feed javascript controls for ISLAND URBAN MUSIC
*/

function ir_resizeUfEmbeds()
{
    function resizeMe()
    {
        if ((this.src && this.src.match(/youtube|myspace/))
            || (this.innerHTML.match(/youtube|myspace/)))
        {
            this.width = '310';
            this.height = '255';
        }
    }
    var objects = $(
        'td.module_center_big object, td.module_center_big embed, \
        td.uftd object, td.uftd embed');
    objects.each(resizeMe);
    if ($.browser.msie && navigator.appVersion.match(/MSIE 7/)) {
        //IE 7 doesn't take w/o a delay...
        setTimeout(ir_resizeUfEmbeds, 100);
    }
}


/**
* define & preload ajax spinner
*/
var ir_ajax_spinner = new Image();
//ir_ajax_spinner.src = 'artist_assets/_default/skin/images/ajax-loader.gif';
ir_ajax_spinner.src = 'images/ium/ajax.gif';

//this first line is fatal in safari...
//ir_ajax_spinner = $(ir_ajax_spinner);
//ir_ajax_spinner.css({
//    'position': 'absolute',
//    'top': '70px',
//    'left': '45%'
//});
//...replaced with...
ir_ajax_spinner = $('<img id="ir_uf_ajax_spinner" src="'+ir_ajax_spinner.src+'" style="position:absolute; top:70px; left:169px;" />');


var uf = {
    //default system: 0/all, 1/news, 2/q&a, 3/journal
    default_system: 0,

    //links for changing system; they must have hrefs with 'uf_system_id=[id]'
    system_links: 'a.uf_system_link',

    //this can be HTML string or a function; if it is a function, it will
    // be called once with the target element when the load starts, and
    // again when it finishes, with a second parameter of the html content.
    ajax_loading_html: function(target_element, html)
    {
        if (typeof html == 'undefined') {
            target_element.fadeTo(1, 0.5);

            var spinner_parent = //$.browser.msie ?
                target_element //: target_element.parent();
            spinner_parent.css('position','relative');
            spinner_parent.append(ir_ajax_spinner);
        } else {
            // If fadeTo opacity is 1 in safari, it doesn't render the element!
            target_element.fadeTo(1, .999).html(html);

            // not needed when spinner is in target element instead of parent
            //uf.debug_on && alert('content loaded; removing spinner...');
            //$.browser.msie || ir_ajax_spinner.remove();
        }
    },

    //list view paginator page select input (if it exists)
    paginate_select: '#does_not_exist',
    //list view paginator previous and next links
    paginate_prev_next: 'td.ium_uf_list_paginator a',

    //comment paginator page select input (if it exists)
    comment_paginate_select: 'td.comment_pagination select',
    //comment paginator previous and next links
    comment_paginate_prev_next: 'td.comment_pagination a',

    //scroll to position on comment pagination
    scroll_to_comments_page: 126,
    //scroll to on detail load
    scroll_to_detail: 126,
    //scroll to on list load
    scroll_to_list: false,

    //list view item container - will be made clickable
    //elements MUST have attribute id="uf_list_[item id]"
    list_item: 'td.uf_list_item',
    //css class to add to list item that matches current detail item
    list_item_selected_class: 'selected',

    detail_page: 'islandsosodef_detail.php',

    list_view: location.pathname.match(/_detail/) ? '_ium_uf_list_dp.php' : '_ium_uf_list.php',
    detail_view: '_ium_uf_detail.php',
    list_view_area: '#uf_list_area',
    detail_view_area: '#uf_detail_area',

    //the link to the comment form; must have href containing "uf_item_id=[id]"
    comment_form_link: '#add_comment_link',

    comment_form_area: '#comment_form_area',

    //<form> element in comment form view must have an action attribute that
    // contains "uf_item_id=[uf item id]
    comment_form_view: '_sap_comment_form.php',

    //comment elements
    // must have id="comment_[id]"
    comment: 'td.comment',

    //comment moderation container elements
    // must have classname "user_[user id]"
    // should have css "display: none" by default
    // they will be revealed according to user's permissions
    comment_moderation_areas: 'div.comment_remove, div.comment_edit',

    //comment remove link
    comment_remove: 'div.comment_remove a',
    //Expression leading to the comment element from the remove link
    comment_remove_to_comment: '../../../../../..',

    //comment edit link
    comment_edit: 'div.comment_edit a',
    //Expression leading to the comment element from the edit link
    comment_edit_to_comment: '../../../../../..',

    //the link to the "Send To A Friend" form; must have href containing "uf_item_id=[id]"
    stf_form_link: '#stf_link',

    stf_form_area: '#send_to_friend_form_container',
    stf_form_view: '_sap_uf_stf_form.php',

    on_detail_load: [ir_resizeUfEmbeds],
    on_list_load: [
        ir_resizeUfEmbeds,
        function()
        {
            //fix layout refresh issues
            //$('table.module_big').hide().show();
        }
    ]
};

/**
* Additions
*/

// artist select list ajaxification
uf.artist_select = '#artist_list';
uf.bindArtistSelect = function()
{
    $(uf.artist_select).get(0).disabled = false;
    $(uf.artist_select).change(function()
    {
        uf.debug_on && alert(uf.current_system);
        uf.loadList(uf.current_system, page=1, this.value);
    });
}
uf.on_list_load.push(uf.bindArtistSelect);

// print link
uf.bindPrintLink = function() {
    $('#print_link').bind('click', function()
    {
        window.open(this.href, 'printView', 'width=750,height=500,scrollbars=yes').focus();
        return false;
    });
};
uf.on_detail_load.push(uf.bindPrintLink);

//fix IE layout reset problems...
/*
$.browser.msie && uf.on_list_load.push(function()
    {
        $('div.footer').hide().show();
    });
*/

document.write('<script type="text/javascript" src="/www2/lib/controllers/js/ufeed.js"></script>');

