ns4Text = "No Newsticker on Netscape 4";  // Alternative text to display in Netscape 4.
ns4URL = "#";            // URL of link in NS4.
ns4Target = "_top";     

//Don't forget to use String and "px" for all coordinates to make it work on xhtml strict page
//Browser Sniffer
var dmnt_isIE = (document.getElementById && document.all) ? true : false;
var dmnt_isNS4 = (document.layers) ? true : false;
var dmnt_isNS6 = (document.getElementById && !document.all) ? true : false;
var dmnt_isLoaded = false;
var timer;

// Build the objScroll and place it on the page
function buildScroller() {
	//Create element in which the Ticker is placed
	tickerspace = '<div name="tickerspace" id="tickerspace" style="position:relative"></div>';
	document.writeln(tickerspace);
}

function loadScroller(){
	if(dmnt_isNS4){
		//Only show Message that it does not work on NS 4
		objScroll = '<table border="0" cellpadding="0" cellspacing="0" width="' + objScrollWidth + '" bgcolor="' + borderColour + '"><tr><td>'
		objScroll += '<table border="0" cellpadding="3" cellspacing="1" width="100%" height="' + objScrollHeight + '" bgcolor="' + backColour + '"><tr><td align="center" nowrap><p class="dmnt_par" style="text-align:' + textAlignment + ';">';
		
		if(ns4URL.toLowerCase() != "none"){
			objScroll += '<a href="' + ns4URL + '" class="' + link_cssClass + '" target="' + ns4Target + '">' + ns4Text + '</a>';
		}
		else{
			objScroll += ns4Text;
		} 
		objScroll += '</p></td></tr></table></td></tr></table>'   
	}
	else{
		//Works if Browser detected is not NS 4
		objScroll = '<table border="0" cellpadding="0" cellspacing="0" style="width:' + objScrollWidth + 'px;height:' + objScrollHeight + 'px;border:' + borderWidth + 'px solid ' + borderColour + ';background-color:' + backColour + '; background-image:url(' + bg_image + ')">';
		objScroll += '<tr valign="middle"><td><div id="tickerdiv" style="';
		
		if(orientation.toLowerCase() == "vertical"){
			objScroll += 'height:' + objScrollHeight + 'px;';
		}
	
		objScroll += 'width:' + objScrollWidth + 'px; position:relative; background-color:' + backColour + '; background-image:url(' + bg_image + '); overflow:hidden">';
		objScroll += '<div id="div1" style="position:relative; left:0px; z-index:1">';
		objScroll += '<table border="0" name="table" id="ticker_table"';
		
		if(orientation.toLowerCase() == "vertical"){
			objScroll += 'style="width:' + objScrollWidth + 'px"';
		}
	
		objScroll += '><tr>';
		y = 0;
		
		while (y < 4){
			//joins 3 News into one object
			for (x = 0; x < (Article.length); x++){
				if(orientation.toLowerCase() == "vertical"){
					//Only for vertical setting a new line for each news.
					objScroll += '<tr>';
				}
				
				objScroll += '<td ';
			   
				if(orientation.toLowerCase() == "horizontal"){
					objScroll += 'nowrap';
				}
				
				if(stopScroll == 1){
					objScroll += ' onMouseOver="stopscroller();" onMouseOut="setWidth()"';
				}
				
				//Close table cell and start Paragraph
				objScroll += '><p class="dmnt_par" style="text-align:' + textAlignment + ';">';
				
				if(Article[x][1].toLowerCase() != "none"){
					//If a link is applied (which is always the case by now in Typo3)
					objScroll += '<a class="' + link_cssClass + '" href="' + Article[x][1] + '" target="' + Article[x][2] + '" >' + Article[x][0] + '<\/a>';
				}
				else{
					objScroll += Article[x][0];
				}
				
				//End paragraph and table cell
				objScroll += '</p><\/td>';
				
				if(orientation.toLowerCase() == "vertical"){
					//If vertical also close table line
					objScroll += '<\/tr>';
				}
					  
				if(objScrollDivider.toLowerCase() != "none"){
					//Insert divider if set in config
					objScroll += '<td nowrap><p class="dmnt_par" style="text-align:' + textAlignment + ';">' + objScrollDivider + '<\/p><\/td>';
				}
			} //End For each article
			
			y++
		} //End While
		
		objScroll += '<\/tr><\/table><\/div><\/div><\/td><\/tr><\/table>';  
	} // End is not NS4
	
	



        /*==================================================================================================== */
        /* 2.10.2009 Aleksander Vreze */
	/* dodana koda, ki omogoca vklucevanje iframe-a.
	 najprej se generira koda za vkljutitev iframe-a, nato pa se samo telo iframa, ki je sestavljeno 
         iz glave, telesa in noge. Glavo in nogo sem dodal ja, telo (tabela) pa generira orignalni vticnik
         S pomocjo funkcije writeToIfrema vse skupaj zapisem v iframe.

	 */
	
        objScroll_if = '<div><iframe id="newsFrame" name="newsFrame" frameborder="0" vspace="0"'; 
	objScroll_if +=' hspace="0" marginwidth="0" marginheight="0" width="770px" ';
	objScroll_if +=' scrolling=no height="25px" ';
	objScroll_if +=' >';
	objScroll_if += '<\/iframe> <\/div>';
   
	document.getElementById("tickerspace").innerHTML = objScroll_if;
        

	var htmlheader = '<html>';
	htmlheader += '<head>';
	htmlheader += '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
	htmlheader += ' <base href="http://www.ssgt.si/">';   
	htmlheader += '<link rel="stylesheet" type="text/css" href="../../../../fileadmin/templates/ssgt-nova/newsbar.css" />';
	htmlheader += '</script>';
	//htmlheader += '<script language="javascript" type="text/javascript" src="typo3conf/ext/datamints_newsticker/res/dm_scroller_iframe.js">';
	//htmlheader += '</script>';
	htmlheader += '</head>';
	htmlheader += '<body onload="setWidth();">';

        var htmlfooter = '<script language="javascript" type="text/javascript" src="typo3conf/ext/datamints_newsticker/res/dm_scroller_iframe.js">';
        htmlfooter += '</script>';
	htmlfooter += '</body> </html>';
          
        var html_iframe =  htmlheader +  objScroll + htmlfooter;
        /*==================================================================================================== */
 
        document.getElementById("tickerspace").innerHTML = objScroll_if;
	writeToIframe(html_iframe);

} //End function loadScroller

/* Aleksander  - dodana funkcija za vpis v iframe */

function writeToIframe(data){
   var ifrm = document.getElementById("newsFrame");
   ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;    
   ifrm.document.open();
   ifrm.document.write(data);
   ifrm.document.close();
}



// Moving is more smooth if width / height (on vertical) is dividable by 2.
function setWidth() { 
	tableObj = (dmnt_isIE) ? document.all("ticker_table") : document.getElementById("ticker_table"); 
	obj = (dmnt_isIE) ? document.all.div1 : document.getElementById("div1");   
	objWidth = (orientation.toLowerCase() == "horizontal") ? getOffset(tableObj, "width") : getOffset(tableObj, "height");


	HalfWidth = Math.floor(objWidth / 2);
	
	if (orientation.toLowerCase() == "horizontal") {
		newWidth = (HalfWidth * 2) + 2;
	}
	else {
		//Bei vertikaler Anordnung nicht durch 2 teilen, damit es an jeder Stelle halten kann.
		newWidth = (HalfWidth) + 4;
	}
	
	//alert (objWidth);
	//alert (newWidth);
        // newWidth = 2000; 
        obj.style.width = newWidth + "px";
	//moveObject(obj, newWidth);  
}


function moveObject(obj, width) {  
    var maxLeft;
    var timeoutDelay =  230 - speed;
    var scrollingOrientation = orientation.toLowerCase();
    var flagHorizontalOrientation = 0;
    if(scrollingOrientation == "horizontal"){
	flagHorizontalOrientation = 1;
    }
    maxLeft = (0 - (width / 2) + 2) / 2;
    function newMove(shiftFunction) {
	//maxLeft = (0 - (width / 2) + 2) / 2;
	( function () {
	    var styleLeft = parseInt(obj.style.left);
	    var styleTop = parseInt(obj.style.top);
	    //klic novo dodane funkcije
	    shiftFunction(obj, (styleLeft - 1), styleTop,  maxLeft, flagHorizontalOrientation);
	    if ( obj.style.left == "-1px" || obj.style.top == "-1px") {
		//Am Beginn jeder News die definierte Pause  
		timer = setTimeout (arguments.callee, ticker_pause);
	    } else {
		//Normaler move ohne große Pause 
		timer = setTimeout (arguments.callee, timeoutDelay);
	    }

	})();
	
    }
    
    newMove(
	   function (obj, styleLeft, styleTop, maxLeft, horizontalOrientation){
	       if(horizontalOrientation) {
		   if (styleLeft <= maxLeft) {
		       obj.style.left =  "0px";
		   }
		   else {
		       obj.style.left = (styleLeft - 1) + "px";	
		   }
	       }else {
		   if(obj.style.top == ""){
		       obj.style.top = 0 + "px";
		   }
		   
		   if (styleTop < (0 - (width / 2) + 6)){
		       obj.style.top = 0 + "px";
		   }
		   else{
		       obj.style.top = (styleTop - 1) + "px";
		   }
	       }
	       
	   }
	
	   ); // konec definicije funkcije
}




// Get width and height of layer
function getOffset(obj, dim) {
	if(dim == "width"){
		oWidth = obj.offsetWidth;
		return oWidth;
	}  
	else if(dim == "height"){
		oHeight = obj.offsetHeight;
		return oHeight;
	}    
}


function stopscroller() {
	clearTimeout(timer);
}
