//by valentin
function move_banner_after_first_comment(){
    var c2 = document.getElementById("banner_container")

    $("div.comment:first").each(function(){
        var node = $(this.parentNode).append('<div class="comment" id="comment_99999"><div id="banner_container"></div></div>')
        var node = $("div#banner_container", node);
        node.each(function(){
            if(c2){
                this.parentNode.replaceChild(c2, this)
            }
        })
    })
}


/**
* Configure Universal Feed javascript controller for this site's html
*
* These properties, except for filenames, integers, classnames, etc., are
* all jQuery expressions
*
*/

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 = $(
        '#ufeed_detail_content object, #ufeed_detail_content embed, \
        #ufeed_HTML_detail object, #ufeed_HTML_detail embed, \
        #uf_content_container div.uf_list_item object, #uf_content_container div.uf_list_item embed, \
        #sap_uf_detail_area object, #sap_uf_detail_area 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
*/
//get artist asset path (e.g. "artist_assets/_default/") from sample image
var ir_sap_sample_img = $('#uf_nav_table img').slice(0, 1); //lt(1);
var ir_artist_asset_path = ir_sap_sample_img.length
    ? ir_sap_sample_img.attr('src').match(/([^\/]+\/){2,2}/)[0]
    : 'artist_assets/_default/';
var ir_ajax_spinner = new Image();
ir_ajax_spinner.src = ir_artist_asset_path + 'skin/images/ajax-loader.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: '#uf_nav_table a',

    //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);

            //having trouble attaching spinner to parent element in IE...
            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);
            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: 'div.lightbg_container div.pagination a',

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

    //scroll to position on comment pagination
    scroll_to_comments_page: 470,
    //scroll to on detail load
    scroll_to_detail: 470,
    //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: '#uf_content_container div.uf_list_item',
    //css class to add to list item that matches current detail item
    list_item_selected_class: 'selected',

    detail_page: 'artist_newsinfo.php',

    list_view: '_sap_uf_list.php',
    detail_view: '_sap_uf_detail.php',
    list_view_area: '#sap_uf_list_area',
    detail_view_area: '#sap_uf_detail_area',

    //the link to the comment form; must have href containing "uf_item_id=[id]"
    comment_form_link: 'div.user_tools a.add_comment',

    comment_form_area: 'div.comment_form_container',

    //<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: 'div.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 div.comment_remove, div.comment 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: 'div.user_tools a.send',

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

    on_detail_load: [ir_resizeUfEmbeds],

    list_load_called: false, // custom property -- only bind rollovers after page load
    on_list_load: [ir_resizeUfEmbeds, function()
    {
        if (!uf.list_load_called) {
            uf.list_load_called = true;
            return;
        }
        ir_bind_rollovers($(uf.list_view_area));
    }]
};

/**
* Override settings for LABEL ufeed pages (home, newsinfo)
*/
if (location.href.match(/\/newsinfo|\/home/)) {
    uf.system_links = '#ufeed_menu a';
    uf.paginate_prev_next = '#paginator_base a';
    uf.comment_paginate_select = 'div.comment_pagination select';
    uf.comment_paginate_prev_next = 'div.comment_pagination a';
    uf.scroll_to_comments_page = 150;
    uf.scroll_to_detail = 150;
    uf.list_item = '#ufeed_detail_content div.newsinfo_item';
    uf.detail_page = 'newsinfo.php';
    //can be removed after development
    location.href.match(/_dev/) && (uf.detail_page = 'newsinfo_dev.php');
    uf.list_view = '_uf_list.php';
    uf.detail_view = '_uf_detail.php';
    uf.list_view_area = '#all';
    uf.detail_view_area = 'div.content div.newsinfo_detail';
    uf.comment_form_link = '#add_comment_link';
    uf.comment_form_area = '#comment_form_area';
    uf.comment = '#comments_area div.comment_item';
    uf.comment_moderation_areas = '#comments_area div.comment_remove, #comments_area div.comment_edit';
    uf.comment_remove = '#comments_area div.comment_remove a';
    uf.comment_edit = '#comments_area div.comment_edit a';
    uf.stf_form_link = '#send_to_friend_link';
    uf.stf_form_area = '#send_to_friend_form_container';
    uf.stf_form_view = '_sap_uf_stf_form.php';

    //additional functionality: artist select list ajaxification
    uf.artist_select = '#artist_list';
    uf.bindArtistSelect = function()
    {
        $(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[1] = uf.bindArtistSelect; // (also removes ir_bind_rollovers, which is unused for label UF)

    // 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();
        });

    // Keep artist id for Q&A Ask Form Controls updated
    uf.on_detail_load.push(function()
        {
            if (window.ask && ask.form_view) {
                ask.form_view = ask.form_view.replace(
                    /artist_id=\d+/,
                    'artist_id=' + $('#ufeed_detail_artist_id').html());
            }
        });

}

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

