/*
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

	--------------------------------------------------------------------
	
	Simple banner rotator. Version: 1.2.0
	Download, support, contact: http://www.spyka.net 
	(c) Copyright 2009 spyka Web Group
*/

/* 
	For full documentation:  http://www.spyka.net/docs/simple-banner-rotator
	For support:			 http://www.spyka.net/forums
*/

//								EDIT FROM HERE
///////////////////////////////////////////////////////////////////////////////////
//         						Program options


// if 1 (one), all images will be resized to img_width and img_height, else images will display their correct size
var force_sizeg	= 0;
// desired height and width of images, only takes affect if above is one
var img_widthg	= 155;
var img_heightg	= 62;

// time between refreshs of ad locations, to disable refreshs set to 0. In milliseconds, 1000 = 1 second
var refresh_timeg = 0;
// maximum amount of refreshs, good to set if a user may be on a page for a long period of time.
var refresh_maxg = 10;

// if you do not want the same banners to display on the same page then set this to 0, else set it to 1.
// this option is only used if you have put the show_banners() javascript code more than once into a page
var duplicate_bannersg = 0;


// ignore/skip this line 
var bannersg = new Array();

// banner list syntax: banners[x] = new banner(website_name, website_url, banner_url, show_until_date);  DATE FORMAT: dd/mm/yyyy
// be sure to increase x by 1 for each banner added!
// to make sure a banner is always rotating, just set the date far into the future, i.e. year 3000
bannersg[0] = new button1('button11', 'http://www.valleyjournal.net/adinfo.html', 'http://www.valleyjournal.net/ads/butt_VJ_adlogo.jpg', '30/04/2019');
bannersg[1] = new button1('button12', 'http://www.valleyjournal.net/current issue/classifieds.html', 'http://www.valleyjournal.net/ads/butt_VJ_findher.jpg', '10/04/2019');
bannersg[2] = new button1('button13', 'http://www.valleyjournal.net/current issue/classifieds.html', 'http://www.valleyjournal.net/ads/butt_VJ_classifieds.jpg', '10/04/2019');
bannersg[3] = new button1('button14', 'http://www.valleyjournal.net/adinfo.html', 'http://www.valleyjournal.net/ads/butt_VJ_remindthem.jpg', '10/04/2019');
bannersg[4] = new button1('button13', 'http://www.valleyjournal.net/current issue/classifieds.html', 'http://www.valleyjournal.net/ads/butt_VJ_classifieds2.jpg', '10/04/2019');

//         				There is no need to edit below here
var usedg = 0;
var first_passg = 0;
var location_counterg = 1;
var refresh_counterg = 1;

function button1(name, url, image, date)
{
	this.name	= name;
	this.url	= url;
	this.image	= image;
	this.date	= date;
	this.active = 1;
}

function show_button1()
{
	var htmlg = '<span id="adLocationg-' + location_counterg + '"></span>';
	document.write(htmlg);
	display_bannersg(location_counterg);
	location_counterg++;
}

function display_bannersg(locationg)
{
	if(locationg == '' || !locationg || locationg < 0)
	{
		// no location given
		return;
	}
	
	var amg	= bannersg.length;
	
	if((amg == usedg) && duplicate_bannersg == 0) {
		// all banners have been used
		return;
	}

	var randg	= Math.floor(Math.random()*amg);	
	var bng 		= bannersg[randg];
	
	var image_sizeg 	= (force_sizeg == 1) ? ' width="' + img_widthg + '" height="' + img_heightg + '"' : '';
	var htmlg 		= '<a href="' + bng.url + '" title="' + bng.name + '" target="_blank"><img border="0" hspace="2" src="' + bng.image + '"' + image_sizeg + ' alt="' + bng.name+ '" /></a>';
	
	var nowg		= new Date(); 
	
	var inputg	= bng.date;
	inputg		= inputg.split('/', 3);
	var end_dateg	= new Date();
	end_dateg		= end_dateg.setFullYear(parseFloat(inputg[2]), parseFloat(inputg[1]), parseFloat(inputg[0]));
	
	if((nowg < end_dateg) && bng.active == 1) 
	{
		var location_elementg = document.getElementById('adLocationg-' + locationg);
		
		if(location_elementg == null)
		{
			// ad location doesn't exist
			alert('Banner rotator\nError: adLocationg doesn\'t exist!');
		}
		else
		{
			location_elementg.innerHTML = htmlg;
			
			if(duplicate_bannersg == 0)
			{
				bng.active = 0;
				usedg++;
			}
		}
	}
	else
	{
		display_bannersg(locationg);
	}
}

function refresh_bannersg()
{
	if((refresh_counterg == refresh_maxg) || refresh_timeg < 1)
	{
		clearInterval(banner_refreshg);  
	}
	usedg = 0;
	for(i = 0; i < bannersg.length; i++)
	{
		bannersg[i].active = 1;
	}
	for(i = 1; i < location_counterg; i++)
	{
		display_bannersg(i);
	}
	refresh_counterg++;
}
var banner_refreshg = window.setInterval(refresh_bannersg, refresh_timeg);