// preload loading images and initial article
	
	  if (document.images) {
      preload_image_object = new Image();
      // set image url
      image_url = new Array();
      image_url[0] = "image/loadarticle.gif";
  	  image_url[1] = "image/" + initialImg;

       var i = 0;
       for(i=0; i<=1; i++) 
         preload_image_object.src = image_url[i];
 }
	

// initialize layers
	
window.addEvent('domready', function() { 
	
	$('newsarticletext').setStyle('display', 'block');
	$('newsarticletext').setStyle('opacity', '0');
	$('news-article-close').setStyle('display', 'block');
	$('news-article-close').setStyle('opacity', '0');
	$('scroll_links').setStyle('display', 'block');
	$('wn').setStyle('overflow', 'hidden');
	
	/* reduce thumbs layer by 5px to prevent slow 5px scroll at end
	
	offsetHeight not working for some reason, so calculating it based on the number of thumbs, plus their bottom margin
	
	*/
	
	var thumbHeight = $('thumb-holder-1').offsetHeight;
	var thumbMargin = $('thumb-holder-1').getStyle('margin-bottom');
	thumbMargin = thumbMargin.substring(0, thumbMargin.length-2);
	var combinedHeight = numberOfThumbRows*(thumbHeight + parseInt(thumbMargin))-parseInt(thumbMargin);
	$('news-thumbs').setStyle('height', combinedHeight+'px');
	$('news-thumbs').setStyle('overflow', 'hidden');
	
});		
	
// attaches javascript function to Read Article link
	function initReadLink() {
	if(document.getElementById('news-read-link')) {
	 $('news-read-link').addEvent('click', function(event){ 
        //prevent the page from changing  
        event.stop();
        displayArticle(this.href);
      });
      }
	}
	
// gets article	
	
	function displayArticle(linkValue) {
		
	 // separate the link from the querystring
        var linkArray = linkValue.split("?");
        
        // isolate querystring pairs
        var queryArray = linkArray[1];
          
        //make the ajax call, replace content 
        var req = new Request.HTML({  
            method: 'get',  
            url: requestPage,  
            data: { 'do' : '1' },
            onRequest: function() { showArticleLoader('loading-div') },  
            update: $('lyr2'),
            onComplete: function() { displayArticleLayers();  
            }
      }).send(queryArray + '&type=articletext&ajax=yes');
	
	}
	
// displays the layers the article is on	
	
	function displayArticleLayers() {
	
	// hide the loading div
	$('loading-div').setStyle('display', 'none');
	
	// this updates the scroll window for the dw_scroll function
	dw_scrollObj.loadLayer('newsarticletext','lyr2');
	
	// set the scroll buttons to visible if the content is longer than the scroll window
	
	var contentHeight = $('lyr2').offsetHeight;
	var containerHeight = $('newsarticletext').offsetHeight;
	if (contentHeight > containerHeight) {
	$('scrollLinks').setStyle('display', 'block');
	}
	
	// move in the transparent bg
	$('news-article-bg').tween('left', '0px');
	
	// fade in the text
	$('newsarticletext').fade('in');
	
	// fade in the close x
	$('news-article-close').fade('in');
	
	// make the read link disappear so the user doesn't click it
	if(document.getElementById('news-read-link')) {
	$('news-read-link').setStyle('display', 'none');
	}
	
	// if the slash is there between Read Article and Download PDF, make it disappear
	if(document.getElementById('news-delimiter')) {
	$('news-delimiter').setStyle('display', 'none');
	}
	
	}
	
	// this is the actual function that updates the scroll window	

	dw_scrollObj.loadLayer = function(wndoId, lyrId, horizId) {
    if ( dw_scrollObj.col[wndoId] ) dw_scrollObj.col[wndoId].load(lyrId, horizId);
	}
	

// the close article function
		
	window.addEvent('domready', function() { 
  
    /* ajax replace element text */  
      $('news-article-close').getElements('a').addEvent('click', function(event){ 
        //prevent the page from changing  
        event.stop();
  
	
	// get rid of the text that's in there
	$('lyr2').innerHTML="";
	
	// fade out the text (so that it's set properly to fade back in)
	$('newsarticletext').fade('out');
	
	// get rid of the scroll buttons
	$('scrollLinks').setStyle('display', 'none');
	
	// fade out the close x
	$('news-article-close').fade('out');
	
	// make the read link reappear
	if(document.getElementById('news-read-link')) {
	$('news-read-link').setStyle('display', 'inline');
	}

	// move the transparent bg back to its original location
	$('news-article-bg').tween('left', '-530px');
		
	// if the slash was there, put it back
	
	// if the slash is there between Read Article and Download PDF, make it disappear
	if(document.getElementById('news-delimiter')) {
	$('news-delimiter').setStyle('display', 'inline');
	}
	
	
	  });  
	});  	
	

	window.addEvent('domready', function() { 
  
    // show read/download details
    
      $('news-thumbs').getElements('a').addEvent('click', function(event){ 
        //prevent the page from changing  
        event.stop();
        
        // get number of link
        //var numberArray = this.id.split("-");
        //var linkNumber = numberArray[2];
        
        // get the image src of the same number
        //var newImgSrc = $('thumb-'+linkNumber).src;
        
        // switch image
        //$('news-main-image').src = newImgSrc;
        
        // separate the link from the querystring
        var linkArray = this.href.split("?");
        
        // isolate querystring pairs
        var queryArray = linkArray[1].split("&");
          
        //make the ajax call, replace content 
        var req = new Request.HTML({  
            method: 'get',  
            url: requestPage,  
            data: { 'do' : '1' },
            onRequest: function() { showArticleLoader('loading-div') },  
            update: $('news-featured-container'),
            onComplete: function() { $('loading-div').setStyle('display', 'none'); initReadLink();  
            }
        }).send(queryArray[0] + '&ajax=yes');
          
    });  
});  

	
	
// initialize the first read link	
window.addEvent('domready', function() {
initReadLink();
});
	
// show the little loading layer	
function showArticleLoader(loadElement) {
$(loadElement).setStyle('display', 'block');
$(loadElement).innerHTML="loading...";
}

function loadThumbDone() {

}
