function comicLink(el, uid, name, storeUrl, strips, subd, admin)
{
	// Must have elements
	var comic_link = document.getElementById('comic_link');
	var comic_link_head = document.getElementById('comic_link_head');
	if (comic_link == null || comic_link_head == null)
		return true;

	if (!document.body)
		document.body = document.getElementsByTagName("body")[0];
	if (document.body.onclick == hideComicLink)
		document.body.onclick = null;
	
	// Get image element
	var chlds = getElementsByClassName('comic_img', el, 'img');
	if (chlds.length == 0)
		return true;
	var img_el = chlds[0];
	img_el.ComicUid = uid;

	// Hide if showing
	if (comic_link.style.display != 'none')
	{
		hideComicLink();
		
		// If same comic, don't do anything else
		if (el == comic_link.curComic)
			return false;
	}
	
	// Need to be invisible but not 'none' so can get size
	setElementOpacity(comic_link, 0);
	comic_link.style.display = 'block';
	
	// Comic title
	comic_link_head.innerHTML = '<div id="comic_link_head_inner">' + img_el.title + '</div>';
	comic_link_head.title = img_el.title;
	var comic_link_head_inner = document.getElementById('comic_link_head_inner');
	
	// Title must at least fill box
	if (comic_link_head_inner.offsetWidth > comic_link.offsetWidth)
	{
		// If too big, activate scrolling
		comic_link_head_inner.scroll = 'yes';
		setTimeout(function() { _scrollTitle(comic_link_head_inner); }, 250);
	}
	else
	{
		comic_link_head_inner.scroll = 'no';
		comic_link_head_inner.style.left = '0px';
		comic_link_head_inner.style.margin = '0px auto';
	}
	
	// Comic Info link
	var link = changeLink('comic_link_Info', base_url + 'comic/?' + name + '/');
	link.style.fontWeight = (el.href.indexOf('/comic/') > 0 || strips == 0 ? 'bold' : '');
	
	// Read Strips row
	var stripsRow = document.getElementById('comic_link_rowStrips');
	if (strips == 1)
	{
		stripsRow.style.display = '';
		link = changeLink('comic_link_Read', base_url + 'strips/?' + name + '/');
		link.style.fontWeight = (el.href.indexOf('/strips/') > 0 ? 'bold' : '');
	}
	else
	{
		stripsRow.style.display = 'none';
	}
	
	// Store link
	var storeRow = document.getElementById('comic_link_rowStore');
	if (storeUrl.length > 0)
	{
		storeRow.style.display = '';
		changeLink('comic_link_Store', storeUrl);
	}
	else
	{
		storeRow.style.display = 'none';
	}
	
	// Discuss link
	changeLink('comic_link_Disc', base_url + 'discuss/?comic=' + uid);
	
	// Subscribe/Unsubscribe/Hide links
	var subRow = document.getElementById('comic_link_rowSub');
	var unsubRow = document.getElementById('comic_link_rowUnsub');
	var blstRow = document.getElementById('comic_link_rowBLst');
	var unblstRow = document.getElementById('comic_link_rowUnBLst');
	subRow.style.display = 'none';
	unsubRow.style.display = 'none';
	blstRow.style.display = 'none';
	unblstRow.style.display = 'none';
	if (typeof subd != 'undefined')
	{
		if (subd == '2')
		{
			unblstRow.style.display = '';
			changeLink('comic_link_UnBLst', base_url + 'comic/?' + name + '/unsubscribe/');
		}
		else if (subd == '1')
		{
			unsubRow.style.display = '';
			changeLink('comic_link_Unsub', base_url + 'comic/?' + name + '/unsubscribe/');
		}
		else
		{
			subRow.style.display = '';
			changeLink('comic_link_Sub', base_url + 'comic/?' + name + '/subscribe/');
			blstRow.style.display = '';
			changeLink('comic_link_BLst', base_url + 'comic/?' + name + '/hide/');
		}
	}
	
	// Admin edit row
	var adminRow = document.getElementById('comic_link_rowAdmin');
	if (adminRow != null)
	{
		if (typeof admin != 'undefined' && admin == '1')
		{
			// Show
			adminRow.style.display = '';
			changeLink('comic_link_Admin', base_url + 'admin/?tab=comics&do=edit&comic=' + uid);
		}
		else
		{
			// Hide row
			adminRow.style.display = 'none';
		}
	}
	
	// Get image's real position
	var pos = offsetPos(img_el);
	
	// Center box around image
	comic_link.style.left = pos.X - (comic_link.offsetWidth / 2) + (img_el.offsetWidth / 2);
	comic_link.style.top = pos.Y - comic_link_head.offsetHeight - 7;
	
	// Show image in box
	var imgCpy = document.getElementById('comicImg');
	if (imgCpy != null)
	{
		imgCpy.src = img_el.src;
		imgCpy.className = img_el.className;
		imgCpy.alt = img_el.alt;
		imgCpy.title = img_el.title;
		imgCpy.style.display = 'block';
		imgCpy.style.left = pos.X + 'px';
		imgCpy.style.top = pos.Y + 'px';
		imgCpy.tgtUrl = el.href;
		imgCpy.onclick = function() { document.location = this.tgtUrl; };
	}
	
	// Fade box in
	comic_link.curComic = img_el;
	fadeElement(comic_link, 100, 250, bindBodyClick);

	return false;
}

function changeLink(id, href)
{
	var link = document.getElementById(id + '1');
	if (link != null)
		link.href = href;
	link = document.getElementById(id + '2');
	if (link != null)
		link.href = href;
	return link;
}

function bindBodyClick()
{
	if (!document.body.onclick)
		document.body.onclick = hideComicLink;
}

function _scrollTitle(titleEl)
{
	if (titleEl.scroll == 'no' || titleEl.parentNode == null)
		return;
	if (titleEl.scrollState == 1)
	{
		var step = 2;
		if (titleEl.offsetLeft <= titleEl.parentNode.offsetWidth - titleEl.offsetWidth)
		{
			// Pause at far-right
			titleEl.scrollState = 2;
			setTimeout(function() { _scrollTitle(titleEl); }, 1000);
		}
		else
		{
			titleEl.style.left = (titleEl.offsetLeft - step) + 'px';
			setTimeout(function() { _scrollTitle(titleEl); }, 100);
		}
	}
	else
	{
		// Pause at far-left
		titleEl.scrollState = 1;
		titleEl.style.left = '0px';
		setTimeout(function() { _scrollTitle(titleEl); }, 1000);
	}
}

function hideComicLink()
{
	var comic_link = document.getElementById('comic_link');
	if (comic_link != null)
	{
		comic_link.style.display = 'none';
		comic_link.curComic = null;
	}
	var imgCpy = document.getElementById('comicImg');
	if (imgCpy != null)	
		imgCpy.style.display = 'none';
}

/** Actions **/

function doAction(el, action, oncomplete)
{
	if (oncomplete == null || typeof oncomplete == 'undefined')
		oncomplete = refreshLink;
	
	var comic_link = document.getElementById('comic_link');
	if (comic_link != null && comic_link.curComic != null)
	{
		var comicUid = comic_link.curComic.ComicUid;
		return PerformRemoteAction(oncomplete, static_uri + 'js/ajax.comic_link_action.php', 'comic=' + comicUid + '&action=' + action, null, { lnk : el, curComic : comic_link.curComic });
	}
	return false;
}
function refreshLink(success, data, arg)
{
	var aEl = arg.curComic.parentNode;
	while (aEl != null && aEl.nodeName != 'A')
		aEl = aEl.parentNode;
	if (success && aEl != null)
	{
		eval('aEl.onclick = function(event) { return ' + data + '; }');
		
		var comic_link = document.getElementById('comic_link');
		if (comic_link != null && comic_link.curComic == arg.curComic)
			hideComicLink();
	}
	else
	{
		document.location = arg.lnk.href;
	}
}

function hideComic(success, data, arg)
{
	refreshLink(success, data, arg);
	
	// Hide comic, if search
	if (document.location.toString().indexOf('/search/') > -1)
	{
		var el = arg.curComic.parentNode.parentNode;
		while (el != null && el.nodeName != 'SPAN')
			el = el.parentNode;
		if (el != null)
			hideElement(el, 250, 2);
	}
}