//open new window
function newWindow(file,windowName)
{	
	popup = window.open(file,windowName,'width=800,height=600,scrollbars=yes,status=nolocatio=no,menubar=no,resizable=yes,copyhistory=no');
	popup.focus();
}

function openPopup(file,windowName,size)
{	
	popup = window.open(file,windowName,size);
	popup.focus();
}

function openBackdoor()
{	
	popup = window.open('backdoor/backdoor.html','backdoor','width=780,height=300,scrollbars=no,status=nolocatio=no,menubar=no,resizable=no,copyhistory=no');
	popup.blur();
}

function selectContent(theId,theLang)
{
	var testLink = document.getElementById(theId).value;
	if (testLink != 'noChange') {
		if (theLang =='de') {
		parent.content.location.href =testLink+'/index.php?page=project&lang=de';
		}
		else {
		parent.content.location.href =testLink+'/index.php?page=project&lang=en';
		}
	}
}

//change cursor to hand
function hand(theId) {
	
	if (document.all) {
	
	document.all(theId).style.cursor ='hand';
	}
	else {
	document.getElementById(theId).style.cursor ='pointer';

	}
}


// change background-color of elements
function txtColor(theId,theColor) {

	document.getElementById(theId).style.color = theColor;
}


// turn display of an element on
function displayOn(theId) {
	
	document.getElementById(theId).style.display = 'inline';
}


// turn display of an element off
function displayOff(theId) {
	
	document.getElementById(theId).style.display = 'none';
}

// defining the height of an object according to window height	
function objectHeight(theId,theRest) {

	if (window.innerWidth) {
		var winHeight = window.innerHeight;
		var conHeight = winHeight-theRest;
		document.getElementById(theId).style.height = conHeight + 'px';
		}

	else if (document.body) {
		var winHeight = document.body.offsetHeight;
		var conHeight = winHeight-theRest;
		document.getElementById(theId).style.height = conHeight + 'px';
		}
		
}

// newsticker
var delay=2000;   // Amount of time each headline on screen (in ms)
var chardelay=50; // Delay for each scrolled character (in ms)
var size=80;      // Size of news box (in characters)

// If size is changed above, it will also need to be changed
// in the form definition.

var headlinetext="";
var headlineurl="";
var artnum=0;
var myartnum=0;
var mixer=0;


// official news only
function publicprintarticle()
{
	if (artnum >= article.length)
		artnum = -1; // Loop if all articles done
	if (artnum == -1) {
		headlinetext = article[0].cluster + " - Courtesy of Moreover.com";
		headlineurl = "http://www.moreover.com";
		}
	else {
		headlinetext = article[artnum].headline_text + " - " + article[artnum].source;
		headlineurl = article[artnum].url;
	}
	printheadlinescroll(size);
}



// regular cycle of personal news
function fixprintarticle()
{
	if (mixer > 2)
		mixer = 0;
	if (mixer == 2) {
		if (myartnum >= myarticle.length)
			myartnum = 0;
		headlinetext = myarticle[myartnum].headline_text + " - " + myarticle[myartnum].source;
		headlineurl = myarticle[myartnum].url;
		mixer++;
		printheadlinescroll(size);
	}
	else {
		if (artnum >= article.length)
			artnum = 0;
		headlinetext = article[artnum].headline_text + " - " + article[artnum].source;
		headlineurl = article[artnum].url;
		mixer++;
		printheadlinescroll(size);
	}
	 
}

// randomly mixed messages
function printarticle()
{
	mixer=Math.floor(Math.random()*3)
	if (mixer == 2) {
		if (myartnum >= myarticle.length)
			myartnum = 0;
		headlinetext = myarticle[myartnum].headline_text + " - " + myarticle[myartnum].source;
		headlineurl = myarticle[myartnum].url;
		printheadlinescroll(size);
	}
	else {
		if (artnum >= article.length)
			artnum = 0;
		headlinetext = article[artnum].headline_text + " - " + article[artnum].source;
		headlineurl = article[artnum].url;
		printheadlinescroll(size);
	}
	 
}



function printheadlinescroll(i)
{
 	var tempstring="";
  	for (j=i; j>=0; j--)
  		tempstring += " ";
  		tempstring += headlinetext;
  		document.headlineform.headlinebox.value = tempstring.slice(0,size);
  		if (i > 0)
  			setTimeout("printheadlinescroll(" + (i-1) + ")",chardelay);
  		else
  			setTimeout("unprintheadlinescroll(0)", 3000);
}


function unprintheadlinescroll(i)
{
	var tempstring="";
	tempstring = headlinetext.slice(i,i+size);
	document.headlineform.headlinebox.value = tempstring;
  	if (i < size)
  		setTimeout("unprintheadlinescroll(" + (i+2) + ")",chardelay);
  	else {
  		if (mixer == 2) {
  			myartnum++;
  		}
  		else {
  			artnum++;
  		}
  		setTimeout("printarticle()", chardelay);
	}
}



function gotoarticle()
{
	document.headlineform.headlinebox.blur();
	window.open(headlineurl);
}


// rotate images
function switchImage(theId,currentNumber) {
      
	document.getElementById(theId).src = image[currentNumber].src;
	
}
                
function rotateImages(theId,delay,totalNumber,currentNumber,basePath) {

	image = new Array();
	
	for (i = 0; i < totalNumber; i++) {
		image[i] = new Image (50, 65);
		image[i].src = basePath + (i + 1) + '.jpg';
	}

	switchImage(theId,currentNumber);
	currentNumber++;
	if(currentNumber >= totalNumber) currentNumber = 0;
	string = "'"+theId+"'"+","+delay+","+totalNumber+","+currentNumber+","+"'"+basePath+"'"
	setTimeout("rotateImages("+string+")", delay);
}
