
/*
*********************************************************************************
*   comments.js
*********************************************************************************
*/
function switchShowComments ( commentID )
{
	Effect.toggle('Commentarys_'+commentID, 'slide');
}

function switchShowInput ( commentID )
{
	Effect.toggle('CommentaryEditField_'+commentID,'slide');
}

function growInputField ( e , commentID )
{	
	element = document.getElementById('CommentInput_'+commentID);	
	
	limit = 2;
	if (!limit) limit = 5;

	if (!e) e = window.event;
	var code = e.keyCode ? e.keyCode : 0;

	if (code === 8 || code === 46) {
		// Deletion
		while (element.scrollHeight <= element.clientHeight && element.rows > limit) {
			element.rows -= 1;
		}
	}
	while (element.scrollHeight > element.clientHeight) {
		element.rows += 1;
	}
}

/*
*********************************************************************************
*   functions.js
*********************************************************************************
*/
function countDown ()
{
	var content = document.getElementById('CountDownBox');
	
	var now = new Date ();
	var end = new Date (2009,6,31,11,0,0);

	now = now.getTime ();
	end = end.getTime ();
	
	diff = end/1000-now/1000;

	var Tage = Math.floor(diff/60/60/24);
	diff = diff - Tage*24*60*60;
	
	var Stunden = Math.floor(diff/60/60);
	diff = diff - Stunden*60*60;
	
	var Minuten = Math.floor(diff/60);
	diff = diff - Minuten*60;
	
	var Sekunden = Math.floor(diff);
	
	content.innerHTML = Tage+' Tage,'+Stunden+' Stunden<br/>'+Minuten+' Minuten,'+Sekunden+' Sekunden<br/>';
	
	setTimeout('countDown()',1000);
}

/*
 * Loads a page on JS request
 */
function load_page ( destination)
{
	self.location = destination;
}

/*
*********************************************************************************
*   gallery.js
*********************************************************************************
*/
function switchText ( id )
{
	element = document.getElementById('GalleryText'+id);
	
	if (element.className == "GalleryTextClosed")
	{
		element.className = "GalleryTextOpen";
		element.style.display = 'none';
		document.getElementById('GalleryTextTeaser'+id).style.display = 'none';
		document.getElementById('GalleryText'+id+'a').innerHTML = "weniger";
		Effect.Appear ('GalleryText'+id, {to:0.8});
	}
	else
	{
		element.className = "GalleryTextClosed";
		element.style.opacity = 1.0;
		document.getElementById('GalleryTextTeaser'+id).style.display = '';
		document.getElementById('GalleryText'+id+'a').innerHTML = "mehr";
	}
}

function showHoverPicture ( e , path )
{
	pic = document.getElementById('PicturePreview');
	
	pic.innerHTML = "<img src = "+path+"></img>";
	
	pic.style.left = (e.clientX+10)+'px';
	pic.style.top = (e.clientY+10)+'px';	
	pic.style.zIndex = 1;
	pic.style.position = "fixed";
}

function hideHoverPicture ()
{
	pic = document.getElementById('PicturePreview');
	pic.innerHTML = "";
}

/*
*********************************************************************************
*   ImageHeader.js
*********************************************************************************
*/
var pause = false;

var countElements = 16;
var pos = Math.round ( (countElements-1) * Math.random() );
var auto;
var lastImg = 0;

images = new Array();
for (var i = 0; i < countElements ; i++ )
    images.push ( "images/headers/"+i+".JPG" );
        
function processImageHeader ( skippause )
{ 
    /*
    var r = (images.length-1) * Math.random();
    r = Math.round ( r );
    */
   
   if ( pause == false || skippause == true )
   {    
        if ( pos >= countElements )
            pos = 0;
        else if ( pos < 0 )
            pos = countElements-1;
            
        var path = '<img id="HeaderImageLast" src="'+images[lastImg]+'"></img><img id="HeaderImage" style="display:none;position:absolute;left:0px;" src="'+images[pos]+'"></img>';
        document.getElementById ("header").innerHTML = path;
        
        lastImg = pos;
        pos++;
        
        Effect.Appear ('HeaderImage', {duration:2.0 } );
        Effect.Fade ( 'HeaderImageLast', {duration:2.0 } );
    }
    
    auto = setTimeout ( 'processImageHeader()', 10000);
}

function processPlayer ( action )
{    
    if ( action == 0 )
    {
        pos = pos - 2;
    }
    else if ( action == 1)
    {}
    else if ( action == 2 )
        pause = false;
    else if ( action == 3 )
        pause = true;
    
    var content = '<span id="NavigationElement" onmouseover="showPlayer();" onmouseout="hidePlayer();"><a  onclick="processPlayer(0)"><img src="images/navigation/back.jpg"></img></a></span>';
    
    if ( pause == true )
        content = content +'<span id="NavigationElement" onmouseover="showPlayer();" onmouseout="hidePlayer();"><a  onclick="processPlayer(2)"><img src="images/navigation/play.jpg"></img></a></span>';
    else
        content = content +'<span id="NavigationElement" onmouseover="showPlayer();" onmouseout="hidePlayer();"><a  onclick="processPlayer(3)"><img src="images/navigation/pause.jpg"></img></a></span>';
    
    content = content +'<span id="NavigationElement" onmouseover="showPlayer();" onmouseout="hidePlayer();"><a  onclick="processPlayer(1)"><img src="images/navigation/forward.jpg"></img></a></span>';
    
    document.getElementById ("NavigationBar").innerHTML = content;
    
    if ( action == 0 || action == 1 )
    {
        clearTimeout ( auto );
        processImageHeader ( true );
    }
}

function showPlayer ()
{
	//Effect.Appear ('NavigationBar', {duration:0.5 } );
	document.getElementById ("NavigationBar").style.display = '';
}

function hidePlayer ()
{
	//Effect.Fade ( 'NavigationBar', {duration:0.5 } );
	document.getElementById("NavigationBar").style.display = 'none';
}

/*
*********************************************************************************
*   ajax_likening.js
*********************************************************************************
*/
var xmlHttp = createXmlHttpRequestObject();

function createXmlHttpRequestObject ()
{
    var xmlHttp;
    if (window.ActiveXObject)
    {
        try
        {
            xmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");
        }
        catch ( e )
        {
            xmlHttp = false
        }
    }
    else
    {
        try
        {
            xmlHttp = new XMLHttpRequest();
        }
        catch ( e )
        {
            xmlHttp = false
        }
    }
    if ( !xmlHttp )
        alert ("Error createing the XMLHttpRequest object.");
    else
        return xmlHttp;
}

var last_liked_id = -1;

function do_like ( id )
{
    if ( xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
    {
    	last_liked_id = id;
        xmlHttp.open ("GET","src/do_like.php?which="+id, true);
        xmlHttp.onreadystatechange = handleServerResponse_like;
        xmlHttp.send(null);
    }
    else
        setTimeout ('do_like('+id+')',100);
}

function handleServerResponse_like ()
{
    if (xmlHttp.readyState == 4)
    {
        if (xmlHttp.status == 200)
        {               
        	xmlResponse = xmlHttp.responseText;
        	
            document.getElementById('Comment'+last_liked_id).innerHTML = "Du magst den Artikel!";
            document.getElementById('LikeningStatus'+last_liked_id).innerHTML = xmlResponse;
        }
        else
            alert ("There was a problem accessing the server: " + xmlHttp.statusText);
    }
}

/*
*********************************************************************************
*   select.js
*********************************************************************************
*/
function doInput ()
{
	for (i = 0; i < document.Editorform.links.length; ++i)
		if (document.Editorform.links.options[i].selected == true)
			document.Editorform.ClientID.value = document.Editorform.links.options[i].value;
}

function doSelect (which)
{	
	which--;
	
	with (document.deleteForm["marks[]"][which])
	{
		if (checked)
			checked = false;
		else
			checked = true;
	}
}

/*
*********************************************************************************
*   livepreview.js
*********************************************************************************
*/
var xmlHttp = createXmlHttpRequestObject();

function createXmlHttpRequestObject ()
{
    var xmlHttp;
    if (window.ActiveXObject)
    {
        try
        {
            xmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");
        }
        catch ( e )
        {
            xmlHttp = false
        }
    }
    else
    {
        try
        {
            xmlHttp = new XMLHttpRequest();
        }
        catch ( e )
        {
            xmlHttp = false
        }
    }
    if ( !xmlHttp )
        alert ("Error createing the XMLHttpRequest object.");
    else
        return xmlHttp;
}

function process ()
{
    if ( xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
    {
        title = encodeURIComponent (document.getElementById ("BlogTitle").value);
        content = encodeURIComponent (document.getElementById ("BlogContent").value);
        xmlHttp.open ("GET","preview.php?title="+title+"&content="+content, true);
        xmlHttp.onreadystatechange = handleServerResponse;	
        xmlHttp.send(null);
    }
    else
        setTimeout ('process()',100);
}

function handleServerResponse ()
{
    if (xmlHttp.readyState == 4)
    {
        if (xmlHttp.status == 200)
        {
            xmlResponse = xmlHttp.responseText;                    
                        
            document.getElementById("preview").innerHTML = xmlResponse;
            setTimeout ('process()',100);
        }
        else
            alert ("There was a problem accessing the server: " + xmlHttp.statusText);
    }
}
