var document_ready = false;
$(document).ready(function() {
	document_ready = true;
});

function openImg(obj, w, h)
{
	if (!document_ready || $(obj).attr("rel").indexOf("lightbox") < 0)
	{
		var imgSrc = '';
		if(obj.href)
		{
			imgSrc=obj.href;
			imgTitle=(obj.title)?obj.title:((obj.innerHTML)?obj.innerHTML:"");
			var imgs=obj.getElementsByTagName("img");
			if(imgs.length>0) obj=imgs[0];
		}
		if(obj.src) //image object
		{ 
			//if(imgSrc.indexOf("/")<0) imgSrc=obj.src
			if(obj.title) imgTitle=obj.title; 
		}
		imgTitle = (imgTitle=="") ? document.title.replace("Absolute Anime / ","") : imgTitle.replace(/ *\([0-9]+\xD7[0-9]+\)/,"");
		if (imgSrc)
		{
			$.slimbox(imgSrc, imgTitle, {loop: true, hide: '.flash-area'});
		}
	}
	return false;
}

function strip_size(line) 
{
	line = line || '';
	return line.replace(/\([0-9]+\xD7[0-9]+\)/, '');
}
jQuery(function($) {
	$("a[rel^='lightbox']").slimbox({loop: true, hide: '.flash-area,#adUnit'}, function(el) {
		var show_xxx = show_adult_content || false;
		var img_obj = $(el).find("img").eq(0);
		var img_class = img_obj.attr('class') || '';
		var page_title = $("title").text() || '';
		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>'; // + '<br /><a href="' + el.href + '">Download this image<\/a>';
		if (!show_xxx && img_class.indexOf('warn-') >= 0) caption = '[image hidden]';
		return [el.href, caption];
	}, function(el) {
		var show_xxx = show_adult_content || false;
		var img_class = $(el).find("img").eq(0).attr('class') || '';
		if (img_class.indexOf('warn-') >= 0) {
			var slimbox_href = $(el).data('slimbox_href');
			if (!show_xxx) {
				if (!slimbox_href) {$(el).data('slimbox_href', el.href);}
				el.href = '/!bin/hidden.png';
			} else if (slimbox_href) {
				el.href = slimbox_href;
			}
		}
		return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
	});
});
