﻿function openWindow(url) {
  popupWin = window.open(url, 'preview', 'noresize,dependent,width=475,height=475,left=50,top=50,scrollbars=yes')
}

    function NewsArticle(name, url) {
         this.Name = name;
         this.Url = url; 
    } 
   
   function NewsArticles(hlnkID, dotLinkIDs) {
        this._currentIndex = 0;
        this._articles = new Array();        
        this._hlnk = document.getElementById(hlnkID);
        this._dots = eval(dotLinkIDs);        
   }
   
   NewsArticles.prototype = {
        
        Add : function(article) {
            this._articles[this._articles.length] = article;
        }        
        
        , SetupOutputLink : function() {
            var article = this._articles[this._currentIndex];
            this._hlnk.href = article.Url;
            this._hlnk.innerHTML = article.Name;       
            this._hlnk.title = article.Name;
            this.SetupDotLink();
        }
        
        , SetupDotLink : function() {            
            for( var x = 0; x < this._dots.length; ++x ) {
                var img = document.getElementById(this._dots[x]);
                img.src = "images/news_dot_empty.gif"
            } 
            
            var img = document.getElementById(this._dots[this._currentIndex]);
            img.src = "images/news_dot_filled.gif"
            
        }
        
        , SetCurrent : function(index) {
            if( index >= 0 && index < this._articles.length ) {
                this._currentIndex = index
            }        
            this.SetupOutputLink()    
        }
                
        , ShowNext : function() {
            if( this._currentIndex + 1 >= this._articles.length )
            {
                this._currentIndex = 0;
            } else {
                this._currentIndex += 1;
            }
            this.SetupOutputLink()    
        }
        
        , ShowPrevious : function() {
            if( this._currentIndex == 0 ) {
                this._currentIndex = this._articles.length - 1;
            } else {
                this._currentIndex -= 1;
            }           
            this.SetupOutputLink()     
        }  
   } 