function strip_size(line) {
	line = line || '';
	return line.replace(/\([0-9]+\xD7[0-9]+\)/, '');
}

function make_title() {
	var el = this;
	var show_xxx = window.show_adult_content || false;
	var img_obj = $(el).find("img").eq(0);
	var img_class = img_obj.attr('class') || '';
	var page_title = $("title").html() || '';
	var page_titles = page_title.split('•');
	var caption = (el.title || strip_size(img_obj.attr("title")) || strip_size(img_obj.attr("alt")) || $.trim($(el).text()) || page_titles[page_titles.length - 1]);
	//caption = '<a href="' + el.href + '">' + (caption || '[save image]') + '</a>';
	caption = caption || '[save image]';
	if (!show_xxx && img_class.indexOf('warn-') >= 0) caption = '[image hidden]';
	return caption;
}

function colorbox_src()
{
	var obj = this;
	var show_xxx = window.show_adult_content || false;
	var src = (!show_xxx && $(obj).has("[class*='warn-']").length) ? '/!bin/hidden.png' : ($(obj).attr('src') || $(obj).attr('href'));
	return src;
}

function openImg(obj, w, h)
{
	if (!$("#colorbox").length || $(obj).attr("rel").indexOf("lightbox") < 0)
	{
		$.colorbox.init();
		$(obj).colorbox({open:true, transition:"elastic", maxHeight:'99%', maxWidth:'99%', title:make_title, href:colorbox_src});
	}
	return false;
}

$(document).bind('cbox_open', function(){
	$('iframe[src="javascript:\'\'"]').remove();	// so bottom part of screen will be clickable again
	$('#ie_holder').css('position','static'); 		// so IE will vertical center lightbox
	$('#adUnit').remove();
	$('.flash-area,object').each(function() {
		$(this).data("colorbox", $(this).css('visibility'));
		$(this).css('visibility', 'hidden');
	});
});
$(document).bind('cbox_closed', function(){
	$('.flash-area,object').each(function() {
		$(this).css('visibility', $(this).data("colorbox"));
	});
});

$(document).ready(function(){
	$("a[rel*='lightbox']").colorbox({transition:"elastic", maxHeight:'99%', maxWidth:'99%', title:make_title, href:colorbox_src});
});

$(window).resize(function(){
	$.colorbox.reload()
})
