
var tagImage, tagText, tagsList, selectedTag, clickedTag = 0, zIndex = 1;

function initTags()
{
	tagImage = document.getElementById('tag-image');
	tagText = document.getElementById('tag-text');
	tagsListCont = document.getElementById('tags-list');
    selectedTag = tagsListCont.getElementsByTagName('div')[0];
    href = window.location.href;
    if(href.indexOf('#') != -1)
    {
      tagNum = parseInt(href.slice(href.indexOf('#') + 1));
      if(document.getElementById('tag' + tagNum)) 
      {
        tagOver(document.getElementById('tag' + tagNum));
        tagClick(document.getElementById('tag' + tagNum));
      }
    }
}

function tagOver(tag)
{
	if(clickedTag) return;
	if(tag == selectedTag) return;
	selectedTag.style.backgroundPosition = '2200px 2200px';
	tag.style.backgroundPosition = 'left top';
	selectedTag = tag;
	document.getElementById(tag.id + '-img').style.zIndex = ++zIndex;
	document.getElementById(tag.id + '-text').style.zIndex = zIndex;
}

function tagClick(tag)
{
    if(clickedTag == tag) 
    {
        tag.style.backgroundImage = 'url(/images/tags/small-bgr.gif)';
        tag.title = "Click to stick on this item";
        clickedTag = 0;
    }
    else 
    {
        if(clickedTag)
        {
            clickedTag.style.backgroundImage = 'url(/images/tags/small-bgr.gif)';
            clickedTag.style.backgroundPosition = '2200px 2200px';
            clickedTag.title = "Click to stick on this item"
            document.getElementById(tag.id + '-img').style.zIndex = ++zIndex;
	        document.getElementById(tag.id + '-text').style.zIndex = zIndex;
        }
        clickedTag = tag;
        selectedTag = tag;
        tag.style.backgroundPosition = 'left top';
        tag.style.backgroundImage = 'url(/images/tags/small-bgr-selected.gif)';
        tag.title = "Click to release this item";
    }
}