/// <reference path="jquery-1.2.6-vsdoc.js" />

$(document).ready(function() {
	$("h6.jqopen").click(function(event){
	
	if ($("div#div" + this.id + ":first").is(":hidden"))
		$("div#div" + this.id).show("1000");
	else
		$("div#div" + this.id).hide("100");
		
	});
	
	
	if ($("#applikationprogress").length>0)
	{
	    $("#applikationprogress").bind("click",app_start);
	    app_total = app_toload = $("img.image").length;
	    $("img.image").each
	    (
	        function()
	            {
	                $(this).bind("load",app_imageloaded);
	                $(this).bind("error",app_imageloaded);
	            }
        )	    
	    
	}
	
});	

var app_toload=0,app_total=0;
function app_imageloaded()
{
        
    app_toload--;
    if (app_toload==0)
    {    
        app_start();
    }
    else
        $("#todo").text("noch " + app_toload + " von " + app_total);// + " " + $(this).attr("src"));

    if ($(this).attr("main") == "true")
        $("#applikation").show();

}

function app_start()
{
    $("#applikationprogress").hide();
    $("#applikation").show();
}



function showWindow(strURL,strTitle,iWidth,iHeight) {
	var sw = window.screen.availWidth;
	var sh = window.screen.availHeight;
    var xsize = screen.width
    var ysize = screen.height
    var xpos=(xsize-iWidth)/2
    var ypos=(ysize-iHeight)/2
    var win =window.open(strURL,null,"height=" + iHeight + ",width=" + iWidth + ",status=no,toolbar=no,menubar=no,location=no,screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos);
    }


sfHover = function() {
    if (!document.getElementById("nav")) return;
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
	var sfEls2 = document.getElementById("navtop").getElementsByTagName("LI");
	for (var i=0; i<sfEls2.length; i++) {
		sfEls2[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls2[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

var specialcase = ((navigator.userAgent.indexOf('Mac') != -1) || document.all)
var flag = 0;
var msg ;


var x,y,x1,y1,copyAttempt;

function init_noright(lang)
{
	if (lang=="de")
		msg = 'Sämtliche Inhalte unterliegen dem Urheberschutz.';
	else
		msg = "All content is protected by copyright law.";
		
		
	if (!(document.getElementById || document.all || document.layers)) return;
	if (specialcase && document.layers)
	{
		document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = special;
	}
	for (i=0;i<document.images.length;i++)
	{
	    if (document.images[i].getAttribute("popup")!="true")
	        {
		    document.images[i].onmousedown = checkIt;
		    document.images[i].onmouseup = function() {return false};
		    if (specialcase)
		    {
			    document.images[i].onmousemove = special;
			    document.images[i].onclick = clearIt;
		    }
		    }
	}
}

function checkIt(e)
{
	copyAttempt = 0;
	if (window.Event)
	{
		x = e.screenX;
		y = e.screenY;
		theButt = (e.which == 3);
	}
	else
	{
		x = window.event.clientX;
		y = window.event.clientY;
		theButt = (window.event.button == 2);
	}
	if (theButt)
	{
		copyAttempt = 1;
		flag = 0;
		alert(msg);
		return false; // NN4 only
	}
	if (specialcase) flag = 1;
	return false;
}

function special(e)
{
	theObj = '';
	if (window.Event)
	{
		x1 = e.screenX;
		y1 = e.screenY;
		if (e.target.parentNode) theObj = e.target.parentNode.tagName;
	}
	else
	{
		x1 = window.event.clientX;
		y1 = window.event.clientY;
		theObj = window.event.srcElement.parentElement.tagName;
	}
	var isLink = (theObj == 'A');
	if (flag && (!isLink || ((Math.abs(x-x1) > 10) || (Math.abs(y-y1) > 10))))
	{
		copyAttempt = 1;
		flag = 0;
		alert(msg);
		return false;
	}
}

function clearIt()
{
	flag = 0;
	if (copyAttempt)
	{
		copyAttempt = 0;
		return false;
	}
}

var app_last="";


function viewport() {
	return {
		x: $(window).scrollLeft(),
		y: $(window).scrollTop(),
		cx: $(window).width(),
		cy: $(window).height()
	};
}



function app_over()
{
    if (timeoutid!=null)
        clearTimeout(timeoutid);
}

function app_view(id)
{

        
    timeoutid = null;

    app_hidelast();
    
    var el = $("#description_" + id);    
    var left = parseInt(el.css("left").substr(0,el.css("left").length-2));
    var top = parseInt(el.css("top").substr(0,el.css("top").length-2));        
    
    //var v = viewport();
    //$("#debug").html("Element:" + id + " Left:" + left + " Top:" + top + " Height:" + el.height() + "--|||" + (top+el.height()) + "!" + v.cy);
    
    app_setPostion(el,left,top);
    el.show();//fadeIn("slow");
    app_last=id;    
    return false;
}

function app_setPostion(el,left,top)
{
    var v = viewport();
    
    
    
    pos1 = (v.cx-el.width())-30;
    if (left+el.width()+30 > v.cx)
        el.css("left",pos1);
    else
        el.css("left",left);
        
    pos2 = (v.cy-el.height())-30;
    if (top+el.height()+30 > v.cy)
        el.css("top",pos2);
    else
        el.css("top",top);

}


var application;

function app_viewapplication(id)
{
    if (application!=null)
        app_hideapplication();
    
    if (app_last!="")
        app_hide(app_last);
        
    var el = $("#"+ id);   

    

    application = el;

    app_setPostion(el,150,10);
    el.fadeIn("slow"); 
    //$("#appback").fadeIn("slow");
    
	$("#appback").css({
		opacity:			0.8
	}).fadeIn();
	
	$("#appback").click(function() {app_hideapplication();});
    
    return false;
}

function app_hideapplication()
{
    if (application!=null)
    {    
    $("#appback").hide();
    application.fadeOut("slow"); 
    application = null;        
    return false;
    }
}


function app_hidelast()
{
    if (app_last!="")
        app_hide(app_last);
    
}

var timeoutid=null;

function app_hideme(el,id)
{
    if (id!="")     
        timeoutid = setTimeout("app_hide('" + id + "')",1000);    
}


function app_hide(id)
{
    $("#description_" + id).fadeOut("fast");
}

function isMouseLeaveOrEnter(e, handler) { if (e.type != 'mouseout' && e.type != 'mouseover') return false; var reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement; while (reltg && reltg != handler) reltg = reltg.parentNode; return (reltg != handler); }

