var heightarr = new Array();
var cyposarr = new Array();
var articles = new Array();

browser = ""; 
/* FIND BROWSER */
var OPB = false;
var IE = false;
var MOZ = false;
uagent = window.navigator.userAgent.toLowerCase();

if ((document.all)&&(browser!="op")) 
	browser = "ie";	

else if (uagent.indexOf('opera') != -1)
	browser = "op";	
	
else if (navigator.platform != "Win32" && getExplorerVersion() == 5)
	browser = "mie5";
else 
	browser = "moz";


var uzunobj=null;
var uzuntop=0;
var uzuntop1=0;
var toplay=0;
var innertxt = "";
var cont; //container 1
var cont1; //container 2

var scrollSpeed = 50; //the default speed of the scroller.
var gapSize = 15; //gap size (px) between articles

var mc=0; //number of articles

var size=0; //the total height in px of a div

//parent div
var newsarea;

var inoout=false; //scroll flag

//width and height of div
var tmpv = 0;
var divH = 0;

// ARTICLE DIV 
divtextb ="<div id=d";
divtev1=" onmouseover=\"mdivmo(";
divtev2=")\" onmouseout =\"restime(";
divtev3=")\" onclick=\"butclick(";
divtev4=")\"";
divtexts = " style=\"position:absolute;visibility:hidden;width:";
divtexts1 = "; background-color:transparent; COLOR: #000000; left:0; top:0; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; FONT-SIZE: 11px; FONT-STYLE: normal; FONT-WEIGHT: normal; TEXT-DECORATION: none; margin:0; margin-bottom:";
divtexts2 = "px;  LINE-HEIGHT: 12px; text-align:left;padding:0; cursor:'default';\">";
span = " style=\"position:relative;background-color: transparent; COLOR: #a40234; width:"
span1 = "; FONT-FAMILY: Verdana, Geneva, Arial, Helvetica, sans-serif; FONT-SIZE: 11px; FONT-STYLE: normal; FONT-WEIGHT: normal; TEXT-DECORATION: none; LINE-HEIGHT: 12px; text-align:left;padding:0px;\"";

//ARTICLE CONTAINER DIVS
uzun="<div id=\"enuzun\" style=\"position:absolute;background-color: transparent;left:0;top:0;\">"; //container 1
uzun1="<div id=\"enuzun1\" style=\"position:absolute;background-color: transparent;left:0;top:0;\">"; //container 2
// ==================================================================
function getExplorerVersion() {//borrowed from fireworks menu script
	var ieVers = parseFloat(navigator.appVersion);
	if( navigator.appName != 'Microsoft Internet Explorer' ) return ieVers;
	var tempVers = navigator.appVersion;
	var i = tempVers.indexOf( 'MSIE ' );
	if( i >= 0 ) {
		tempVers = tempVers.substring( i+5 );
		ieVers = parseFloat( tempVers ); 
	}
	return ieVers;
}
// ==================================================================
function mdivmo(gnum) //pause scroll
{
	inoout=true;
	id=gnum;
	gnum = gnum>(mc-1)?gnum-mc:gnum;
	if((articles[gnum]["link"].length)>2) {
		objd=document.getElementById('d'+id);
		objd2=document.getElementById('hgd'+id);
	
		objd.style.color="#000000";
		objd2.style.color="#a40234";
		switch (browser) {
			
			case "op":
			case "ie":	
				objd.style.cursor='hand';
				objd2.style.cursor='hand';
				break;
			default:
				objd.style.cursor='pointer';
				objd2.style.cursor='pointer';
				
		}
		
	}
	window.status=""+articles[gnum]["link"];

}
// ==================================================================
function restime(gnum2) // resume scrolling
{
	inoout=false;
	objd=document.getElementById('d'+gnum2);
	objd2=document.getElementById('hgd'+gnum2);

	objd.style.color="#000000";
	objd2.style.color="#a40234";

	window.status="";

}
// ==================================================================
function butclick(gnum3){//click on article
	gnum3 = gnum3>(mc-1)?gnum3-mc:gnum3;
	if(articles[gnum3]["link"].substring(0,11)=="javascript:"){
		eval(""+articles[gnum3]["link"]);
	}
	else {
		if((articles[gnum3]["link"].length)>3){
			if((articles[gnum3]["target"].indexOf("_parent")>-1)){
			eval("parent.window.location='"+articles[gnum3]["link"]+"'");
			}
			else if((articles[gnum3]["target"].indexOf("_top")>-1)){
				eval("top.window.location='"+articles[gnum3]["link"]+"'");
			}
			else{
				window.open(''+articles[gnum3]["link"],''+articles[gnum3]["target"]);
			}
		}
	}
}
// ==================================================================
function dotrans() { //scroll text up at a certain speed
	
	if(inoout==false){
		//move top by 1 each time
		uzuntop--;
		uzuntop1--;
		if(uzuntop<(-1*toplay)) { //reset position of first set
			uzuntop=uzuntop1+size;
		}
		if(uzuntop1<(-1*toplay)) {//reset position of second set
			uzuntop1=uzuntop+size;
		}
		switch(browser) {		
			case "ie":
				cont.style.pixelTop=uzuntop;
				cont1.style.pixelTop=uzuntop1;
				break;
			default:
				cont.style.top=uzuntop+"px"; 
				cont1.style.top=uzuntop1+"px";
		}
		
	}
	setTimeout('dotrans()',scrollSpeed);
}
// ==================================================================
function initte2() // set initial position and properties of articles
{
	i=0;//first set of articles
	for(i=0;i<cont.childNodes.length;i++)
	{
		heightarr[i]=cont.childNodes[i].offsetHeight;
		size+=heightarr[i];
		size+=gapSize;			
	
	}
	
	toplay=4;
	for(i=0;i<cont.childNodes.length;i++)
	{
		
		cont.childNodes[i].style.visibility="visible";
		switch (browser) {
			case "ie":
				cont.childNodes[i].style.pixelTop=toplay;
				break;
			default:
				cont.childNodes[i].style.top=toplay+"px";
		}
		
		toplay=toplay+heightarr[i]+gapSize; //height of total div
	}
	var enuzun =  document.getElementById("enuzun");
	//enuzun.style.left=8+"px";
	enuzun.style.height=toplay+"px";	
	enuzun.style.width=tmpv+"px";
	//the top location of the first div will be the bottom(height) of the parent div
	switch (browser) {
		case "mie5":
			divH -= 15;
			break;			
	}
	uzuntop=divH;
	

	// INIT SECOND CONTAINER
	
	for(i=0;i<cont1.childNodes.length;i++)		
		heightarr[i]=cont1.childNodes[i].offsetHeight;	

	toplay=4;
	for(i=0;i<cont1.childNodes.length;i++)
	{
		
		cont1.childNodes[i].style.visibility="visible";
		switch (browser) {
			case "ie":
				cont1.childNodes[i].style.pixelTop=toplay;
				break;
			default:
				cont1.childNodes[i].style.top=toplay+"px";
		}
		toplay=toplay+heightarr[i]+gapSize; //height of total div
	}
	var enuzun1 =  document.getElementById("enuzun1");
	//enuzun1.style.left=8+"px";
	enuzun1.style.height=toplay+"px";
	enuzun1.style.width=tmpv+"px";	
	//the top of the second div will be the height of the first div + the height of the parent div
	//this way it will be right under the first div	
	uzuntop1=uzuntop+size;
	dotrans();

}
// ==================================================================
function StartScroller() //populate divs with article data
{
	var i=0;

	newsarea = document.getElementById("newsarea");	
	tmpv = parseInt(newsarea.style.width);
	divH = parseInt(newsarea.style.height);	
	SetParentHW(newsarea);
	SetArticleH();
	
	innertxt=""+uzun;
	for(i=0;i<mc;i++)	
		innertxt=innertxt+""+divtextb+""+i+""+divtev1+i+divtev2+i+divtev3+i+divtev4+divtexts+tmpv+divtexts1+tmpv+divtexts2+"<span id=\"hgd"+i+"\""+span+tmpv+span1+">"+articles[i]["title"]+"</span><br/>"+articles[i]["text"]+"</div>";		
	
	innertxt=innertxt+"</div>";
	
	innertxt+=uzun1;
	for(i,x=0;x<mc;i++,x++)			
		innertxt=innertxt+""+divtextb+""+i+""+divtev1+i+divtev2+i+divtev3+i+divtev4+divtexts+tmpv+divtexts1+tmpv+divtexts2+"<span id=\"hgd"+i+"\""+span+tmpv+span1+">"+articles[x]["title"]+"</span><br/>"+articles[x]["text"]+"</div>";				
	
	innertxt=innertxt+"</div>";	

	newsarea.innerHTML=""+innertxt;	
	cont = document.getElementById("enuzun");	
	cont1 = document.getElementById("enuzun1");	
	
	setTimeout('initte2()',700);
	
}
// ==================================================================
//set width of the article divs on different browsers
function SetArticleH() {
	switch (browser) {
		case "ie":
			tmpv = tmpv-8-8-1;
			break;
		case "moz":
			tmpv = tmpv-8-8-2;
			divH -= 2;
			break;
		case "op":
			tmpv = tmpv-8-8-2;		
			break;
	}
}
// ==================================================================
//set the width and height of the parent div depending on browser
function SetParentHW(elem) {
	switch (browser) {
		case "ie":
			break;
		case "moz":
			elem.style.width = parseInt(newsarea.style.width) + 8;
			elem.style.height = parseInt(newsarea.style.height) - 2;
			break;
		case "op":
			elem.style.width = parseInt(newsarea.style.width) + 10;	
			break;
	}	
}
// ==================================================================
//add articles/populate articles array
function AddArticle(title,link,text,target) {
	articles[mc] = new Array();
	articles[mc]["title"] = title;
	articles[mc]["link"] = link;
	articles[mc]["text"] = text;
	articles[mc]["target"] = target;
	mc++;
}
