/*
    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_sizea	= 0;
// desired height and width of images, only takes affect if above is one
var img_widtha	= 190;
var img_heighta	= 300;

// time between refreshs of ad locations, to disable refreshs set to 0. In milliseconds, 1000 = 1 second
var refresh_timea = 0;
// maximum amount of refreshs, good to set if a user may be on a page for a long period of time.
var refresh_maxa = 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_bannersa = 0;


// ignore/skip this line 
var bannersa = 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
bannersa[0] = new bannera('banner0', 'http://www.valleyjournal.net/photo_galleries.html', 'http://www.valleyjournal.net/ads/VJ_bballtourney_2010.jpg', '10/04/2019');
bannersa[1] = new bannera('banner1', 'http://www.valleyjournal.net/photo_galleries.html', 'http://www.valleyjournal.net/ads/VJ_LB_fotogallery.jpg', '10/04/2019');
// bannersa[2] = new bannera('banner2', 'http://www.valleyjournal.net/adinfo.html', 'http://www.valleyjournal.net/ads/house_yourbizhere.jpg', '10/04/2019');
// bannersa[3] = new bannera('banner3', 'http://www.valleyjournal.net/photo_galleries.html', 'http://www.valleyjournal.net/ads/VJ_LB_fotogallery.jpg', '10/04/2019');

//         				There is no need to edit below here
var useda = 0;
var first_passa = 0;
var location_countera = 1;
var refresh_countera = 1;

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

function show_bannera()
{
	var htmla = '<div id="adLocationa-' + location_countera + '"></div>';
	document.write(htmla);
	display_bannersa(location_countera);
	location_countera++;
}

function display_bannersa(locationa)
{
	if(locationa == '' || !locationa || locationa < 0)
	{
		// no location given
		return;
	}
	
	var ama	= bannersa.length;
	
	if((ama == useda) && duplicate_bannersa == 0) {
		// all banners have been used
		return;
	}

	var randa	= Math.floor(Math.random()*ama);	
	var bna 		= bannersa[randa];
	
	var image_sizea 	= (force_sizea == 1) ? ' width="' + img_widtha + '" height="' + img_heighta + '"' : '';
	var htmla 		= '<a href="' + bna.url + '" title="' + bna.name + '" target="_blank"><img border="0" src="' + bna.image + '"' + image_sizea + ' alt="' + bna.name+ '" /></a>';
	
	var nowa		= new Date(); 
	
	var inputa	= bna.date;
	inputa		= inputa.split('/', 3);
	var end_datea	= new Date();
	end_datea		= end_datea.setFullYear(parseFloat(inputa[2]), parseFloat(inputa[1]), parseFloat(inputa[0]));
	
	if((nowa < end_datea) && bna.active == 1) 
	{
		var location_elementa = document.getElementById('adLocationa-' + locationa);
		
		if(location_elementa == null)
		{
			// ad location doesn't exist
			alert('Banner rotator\nError: adLocationa doesn\'t exist!');
		}
		else
		{
			location_elementa.innerHTML = htmla;
			
			if(duplicate_bannersa == 0)
			{
				bna.active = 0;
				useda++;
			}
		}
	}
	else
	{
		display_bannersa(locationa);
	}
}

function refresh_bannersa()
{
	if((refresh_countera == refresh_maxa) || refresh_timea < 1)
	{
		clearInterval(banner_refresha);  
	}
	useda = 0;
	for(i = 0; i < bannersa.length; i++)
	{
		bannersa[i].active = 1;
	}
	for(i = 1; i < location_countera; i++)
	{
		display_bannersa(i);
	}
	refresh_countera++;
}
var banner_refresha = window.setInterval(refresh_bannersa, refresh_timea);