// JavaScript Document
//constructor to create a news item

function makeNews(c,l,f,i){
      this.copy = c;
      this.link = l;
      this.follow = f;
      this.img = i;
      this.write = writeNews;
   }

// writeNews function 

function writeNews(){
      var str = '';
      str += '<a href="' + this.link + '">';
      str += '<img border="0" src="' + 
         this.img.src + '"></a><br>';
      str += this.copy + '<br>';
      str +=  '<a href="' + this.link + '">' + 
         this.follow + '</a>';
      return str;
   }


//code to pre-load the images

 /*var AlcobaseImg = new Image();
   AlcobaseImg.src = 'images/alcobase_kit_.gif'; */
   var FlashImg = new Image();
   FlashImg.src = './images/rotating_ad/beer_brewing.gif';
   var FriendImg = new Image();
   FriendImg.src = './images/rotating_ad/dot.gif';
   var FavouriteImg = new Image();
   FavouriteImg.src = './images/rotating_ad/dot.gif';
   




//collection of the news items to display on the page

var newsArray = new Array();
   /*  newsArray[0] = new makeNews(
      "Make high quality spirits",
       'http://www.malthouse.com.au/index.php?cat=11',
       'More Info',AlcobaseImg).write();*/



  

  newsArray[0] = new makeNews(
      "Beer Brewing Made Easy",
       'content.php?content_id=6',
       'More Info',FlashImg).write(); 


   
   newsArray[1] = new makeNews(
      "Check out our specials",
      'category.php?sale=1',
      'More Info',FriendImg).write(); 
   
  newsArray[2] = new makeNews(
      "Brew Your Favourite Beers",
      'content.php?content_id=11',
      'More Info',FavouriteImg).write(); 


  
//rotateNews function

 var nIndex = 0;
   var timerID = null;
   
   function rotateNews(){
      var len = newsArray.length;
      if(nIndex >= len)
         nIndex = 0;
      document.getElementById('stories').innerHTML = 
         newsArray[nIndex];
      nIndex++;
      timerID = setTimeout('rotateNews()',6000);
   }



// functions to display pause and re-start the rotation

   function pauseNews() {
      if (timerID != null) {
         clearTimeout(timerID);
         timerID = null;
      }
   }
   
   function playNews() {
      if (timerID == null) {
         timerID = setTimeout('rotateNews()', 2000);
      }
   }