/**
* Configure Universal Feed javascript controls for BON JOVI
*/

function ir_resizeUfEmbeds()
{
	var w = 305;
	var h = 251;

    function resizeMe()
    {
        if ((this.src && this.src.match(/youtube|myspace/))
            || (this.innerHTML.match(/youtube|myspace/)))
        {
            this.width = w;
            this.height = h;
        }
    }
    var objects = $('div.uf_item object, div.uf_item 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 = 'images/ajax_working.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="uf_ajax_spinner" src="'+ir_ajax_spinner.src+'" style="position:absolute; top:67px; left:45px;" />');


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 div.uf_nav_item 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') {
            if ($.browser.safari) {
				target_element.hide();
			} else {
				target_element.fadeTo(1, 0.2);
			}

			//Attach ajax loading gif to parent element -- so image is opaque
			// while target element is faded.
			//Works ok in IE if parent element hasLayout is OFF
			// (if parent element hasLayout, you may want to just create an
			// extra generic div to supplant the parent.)
            var spinner_parent = //$.browser.msie ?
                //target_element :
				target_element.parent();
            spinner_parent.css('position','relative');
            spinner_parent.append(ir_ajax_spinner);
        } else {
			if ($.browser.safari) {
				target_element.html(html).show();
			} 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();
        }
    },

	form_loading_html: '<div id="addcomment_form">Loading...</div>',
	stf_sending_html: '<div id="sendtofriend_form">Sending...</div>',

    //list view paginator page select input (if it exists)
    paginate_select: '#does_not_exist',
    //list view paginator previous and next links (or any page-specific links)
    paginate_prev_next: '#uf_pagination a',

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

    //scroll to position on comment pagination
    scroll_to_comments_page: 289,
    //scroll to on detail load
    scroll_to_detail: 229,
    //scroll to on list load
    scroll_to_list: 0,

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

    detail_page: 'blog.php',

    list_view: '_uf_list.php',
    detail_view: '_uf_detail.php',
    list_view_area: '#uf_list_area',
    detail_view_area: '#blog_detail_area',

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

    comment_form_area: '#addcomment_form_area',

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

    //comment elements
    // must have id="comment_[id]"
    comment: 'div.comment_item_odd, div.comment_item_even',

    //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.member_links',

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

    //comment edit link
    comment_edit: 'div.member_links a.edit',
    //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: '#uf_stf_link',

    stf_form_area: '#sendtofriend_form_area',
    stf_form_view: '_uf_stf_form.php',

    on_detail_load: [ir_resizeUfEmbeds],
    on_list_load: [ir_resizeUfEmbeds, function()
		{
			//copy nav HTML from loaded area to visible area
			$('#uf_nav').html($('#uf_nav_original').html());

			//close ask form if open
			var ask_form = $('#askquestion_form_area');
			if (ask_form.html()) {
				ask_form.hide('fast');
			}

			// rebind mouseover code
			initRollovers();

			// show/hide ask button
			switch (uf.current_system) {
			//case '0': // all
			//case 0:
			case '3': // Q&A
			case 3:
				$('#uf_ask_btn:hidden').show();
				break;
			default:
				$('#uf_ask_btn:visible').hide();
				break;
			}
		}]
};

/**
* Additions
*/

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

// translation controls
uf.bindTranslationControls = function()
{
	$('#translation_link').bind('click', function()
	{
		if (this.href.match(/langpair=/)) {
			$('#translation_form').toggle('fast');
		} else {
			uf.loadDetail();
		}
		return false;
	});

	$('#translation_languages a').bind('click', function()
	{
		uf.loadDetail(uf_item_id=null, comment_page=null, uf.extractParams(this.href));
		return false;
	});

}
uf.on_detail_load.push(uf.bindTranslationControls);

// next/prev item controls
uf.bindNeighborControls = function()
{
	uf.debug_on && alert('Binding neighbor controls...');
	$('#blog_neighboring a').bind('click', function()
	{
		uf.loadDetail(uf_item_id=this.href.match(/uf_item_id=([-\d]+)/)[1]);
		var page = this.href.match(/page=(\d+)/)[1];
		if (page != uf.current_page) {
			// Loading list immediately seemed to be interfering w/ re-binding
			// of controls in detail view, so I'm delaying it a sec.
			setTimeout('uf.loadList(uf.current_system, '+page+');', 1000);
		}
		return false;
	});
}
uf.on_detail_load.push(uf.bindNeighborControls);

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