$(document).ready(function(){
	var iframes = document.getElementsByTagName("iframe");
	$("a[rel='i']").colorbox({
		opacity:0.7,
		maxHeight:'90%',
		maxWidth:'90%',
		current: 'Screenshot {current} von {total}'
	});
	$("a[rel='i']").bind('cbox_open', function(){
		for (var i=0,iframe;iframe=iframes[i];i++)
		{
			iframe.style.visibility = "hidden";
		}
	});
	$("a[rel='i']").bind('cbox_closed', function(){
		for (var i=0,iframe;iframe=iframes[i];i++)
		{
			iframe.style.visibility = "visible";
		}
	});
});
$(document).ready(function(){
	var iframes = document.getElementsByTagName("iframe");
	$("a[rel='f']").colorbox({
		opacity:0.7,
		maxHeight:'90%',
		maxWidth:'90%',
		current: 'Wallpaper {current} von {total}'
	});
	$("a[rel='f']").bind('cbox_load', function(){
		this.title = '<a href="' + this.href + '" target="_blank">Fullscreen</a>';
		for (var i=0,iframe;iframe=iframes[i];i++)
		{
			iframe.style.visibility = "hidden";
		}
	});
	$("a[rel='f']").bind('cbox_closed', function(){
		this.title = '';
		for (var i=0,iframe;iframe=iframes[i];i++)
		{
			iframe.style.visibility = "visible";
		}
	});
});
$(document).ready(function(){
	var iframes = document.getElementsByTagName("iframe");
	$("a[rel='t']").colorbox({
		iframe:true,
		width:800,
		height:450,
		current: 'Trailer {current} von {total}'
	});
	$("a[rel='t']").bind('cbox_open', function(){
		for (var i=0,iframe;iframe=iframes[i];i++)
		{
			iframe.style.visibility = "hidden";
		}
	});
	$("a[rel='t']").bind('cbox_closed', function(){
		for (var i=0,iframe;iframe=iframes[i];i++)
		{
			iframe.style.visibility = "visible";
		}
	});
});

// SUCHE
qlist = new Array();
qindex = -1;
window.myTimeout = false;
window.myTimeout2 = false;
function StartSearch()
{
	//document.getElementById('qsearch').focus();
	SendSearchString();
	endHide();

	var qs = document.getElementById('qsearch');
    var iframes = document.getElementsByTagName("iframe");
	for (var i=0,iframe;iframe=iframes[i];i++)
	{
		iframe.style.visibility = (qs.value!='') ? "hidden" : "visible";
	}
}
function sendSearch()
{
	if (window.myTimeout) window.clearTimeout(window.myTimeout);
	window.myTimeout = window.setTimeout("StartSearch()", 500);
}
function rebuildResult()
{
    for (var i=0;i<qlist.length;i++)
    {
        var tr = document.getElementById('qselect'+i);
        if (tr) tr.bgColor = (qindex==i) ? "#FFEB77" : ((i%2==0) ? "#FFFCDD" : "#F7F5DC");
    }
}
function showPress(evt)
{
    if (qlist.length>0)
    {
	    evt = (evt) ? evt : ((event) ? event : null);
	    if (evt)
		{
	        if ((evt.keyCode==13) && (qindex>=0))
	        {
	            if (document.suche.rub.selectedIndex==0)
					window.location.href = 'http://anisearch.de/forward.php?id='+qlist[qindex];
	            else if (document.suche.rub.selectedIndex==2)
					window.location.href = 'http://anisearch.de/?page=chara&id='+qlist[qindex];
	            else if (document.suche.rub.selectedIndex==3)
					window.location.href = 'http://anisearch.de/?page=wallpapers&id='+qlist[qindex];
	            else if (document.suche.rub.selectedIndex==4)
					window.location.href = 'http://anisearch.de/?page=person&id='+qlist[qindex];
	            else if (document.suche.rub.selectedIndex==5)
					window.location.href = 'http://anisearch.de/?page=firma&id='+qlist[qindex];
	            else if (document.suche.rub.selectedIndex==1)
					window.location.href = 'http://anisearch.de/?page=manga&id='+qlist[qindex];
	        }
	        else if (evt.keyCode==38)
	        {
	            qindex--;
	            if (qindex<-1) qindex = qlist.length-1;
	        }
	        else if (evt.keyCode==40)
	        {
	            qindex++;
	            if (qindex>=qlist.length) qindex = -1;
	        }
	        else
	        {
				sendSearch();
			}
			rebuildResult();
	    }
	}
	else
	{
	    sendSearch();
	}
}
function mouseOver(i)
{
    qindex = i;
    rebuildResult();
}
function mouseOut()
{
    qindex = -1;
    rebuildResult();
}
function HideResult()
{
	document.getElementById('result').style.display = 'none';
   
    var iframes = document.getElementsByTagName("iframe");
	for (var i=0,iframe;iframe=iframes[i];i++)
	{
		iframe.style.visibility = "visible";
	}
}
function checksubmit()
{
	if (qindex==-1) return true;
	return false;
}
function showAll()
{
    qindex=-1;
	document.suche.submit();
}
function startHide()
{
	window.myTimeout2 = window.setTimeout("HideResult()", 1500);
}
function endHide()
{
	if (window.myTimeout2) window.clearTimeout(window.myTimeout2);
}

function isParent(childNode, parentNode)
{
	if (childNode.tagName == 'HTML' || childNode.parentNode === null) return false
	else if (parentNode == childNode.parentNode) return true;  
	else return isParent(childNode.parentNode, parentNode);
}
function isParentOrSelf(childNode, parentNode)
{
	return ((childNode == parentNode) || isParent(childNode, parentNode));
}
function bodyClickHandler(e)
{
	var target = e.target || e.srcElement;
	isVisibleToHide(target,'result');
	isVisibleToHide(target,'dkv');
}
function isVisibleToHide(target,node)
{
	var node = document.getElementById(node);
	
	if ((target == null) || (node == null)) return ;
	
	if ((node.style.display!='none') && (!isParentOrSelf(target,node)))
	{
		node.style.display = 'none';
	}

    if (node=='result')
    {
	    var iframes = document.getElementsByTagName("iframe");
		for (var i=0,iframe;iframe=iframes[i];i++)
		{
			iframe.style.visibility = "visible";
		}
	}
}

// NAV POPUP
var headpic = new Array();
headpic[0] = new Image(); headpic[0].src = "images/top.gif";
headpic[1] = new Image(); headpic[1].src = "images/bottom.gif";

function nav_popup()
{
	if (document.getElementById("nav1").style.display=="none")
	{
		document.getElementById("nav1").style.display = "block";
		document.getElementById("nav2").style.display = "none";
		document.getElementById("img_filter").src = headpic[1].src;
		document.getElementById("img_filter").title = "Box aufklappen";
	}
	else if (document.getElementById("nav1").style.display=="block")
	{
		document.getElementById("nav1").style.display = "none";
		document.getElementById("nav2").style.display = "block";
		document.getElementById("img_filter").src = headpic[0].src;
		document.getElementById("img_filter").title = "Box zuklappen";
	}
	return false;
}

function nav_popup2(id)
{
	if (document.getElementById(id).style.display=="none")
	{
		document.getElementById(id).style.display = "block";
		document.getElementById("img_filter_"+id).src = headpic[0].src;
		document.getElementById("img_filter_"+id).title = "Box zuklappen";
	}
	else if (document.getElementById(id).style.display=="block")
	{
		document.getElementById(id).style.display = "none";
		document.getElementById("img_filter_"+id).src = headpic[1].src;
		document.getElementById("img_filter_"+id).title = "Box aufklappen";
	}
	return false;
}
