/*
    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_sized	= 0;
// desired height and width of images, only takes affect if above is one
var img_widthd	= 230;
var img_heightd	= 230;

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


// ignore/skip this line 
var bannersd = 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
// bannersd[0] = new square('square0', 'http://www.ricciardis.com', 'http://www.valleyjournal.net/ads/RIcciardis_SQ_pizza.jpg', '10/04/2019');
bannersd[0] = new square('square0', 'http://www.valleyjournal.net', 'http://www.valleyjournal.net/ads/VJ_sq_click_thru.jpg', '10/04/2019');
bannersd[1] = new square('square1', 'http://www.valleyjournal.net/current%20issue/classifieds.html', 'http://www.valleyjournal.net/ads/house_classified_sq.jpg', '10/04/2019');
bannersd[2] = new square('square2', 'http://www.valleyjournal.net', 'http://www.valleyjournal.net/ads/VJ_sq_click_thru.jpg', '10/04/2019');
bannersd[3] = new square('square3', 'http://www.valleyjournal.net/current%20issue/classifieds.html', 'http://www.valleyjournal.net/ads/house_classified_sq.jpg', '10/04/2019');

//         				There is no need to edit below here
var usedd = 0;
var first_passd = 0;
var location_counterd = 1;
var refresh_counterd = 1;

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

function show_square()
{
	var htmld = '<div id="adLocationd-' + location_counterd + '"></div>';
	document.write(htmld);
	display_bannersd(location_counterd);
	location_counterd++;
}

function display_bannersd(locationd)
{
	if(locationd == '' || !locationd || locationd < 0)
	{
		// no location given
		return;
	}
	
	var amd	= bannersd.length;
	
	if((amd == usedd) && duplicate_bannersd == 0) {
		// all banners have been used
		return;
	}

	var randd	= Math.floor(Math.random()*amd);	
	var bnd 		= bannersd[randd];
	
	var image_sized 	= (force_sized == 1) ? ' width="' + img_widthd + '" height="' + img_heightd + '"' : '';
	var htmld 		= '<a href="' + bnd.url + '" title="' + bnd.name + '" target="_blank"><img border="0" src="' + bnd.image + '"' + image_sized + ' alt="' + bnd.name+ '" /></a>';
	
	var nowd		= new Date(); 
	
	var inputd	= bnd.date;
	inputd		= inputd.split('/', 3);
	var end_dated	= new Date();
	end_dated		= end_dated.setFullYear(parseFloat(inputd[2]), parseFloat(inputd[1]), parseFloat(inputd[0]));
	
	if((nowd < end_dated) && bnd.active == 1) 
	{
		var location_elementd = document.getElementById('adLocationd-' + locationd);
		
		if(location_elementd == null)
		{
			// ad location doesn't exist
			alert('Banner rotator\nError: adLocationd doesn\'t exist!');
		}
		else
		{
			location_elementd.innerHTML = htmld;
			
			if(duplicate_bannersd == 0)
			{
				bnd.active = 0;
				usedd++;
			}
		}
	}
	else
	{
		display_bannersd(locationd);
	}
}

function refresh_bannersd()
{
	if((refresh_counterd == refresh_maxd) || refresh_timed < 1)
	{
		clearInterval(banner_refreshd);  
	}
	usedd = 0;
	for(i = 0; i < bannersd.length; i++)
	{
		bannersd[i].active = 1;
	}
	for(i = 1; i < location_counterd; i++)
	{
		display_bannersd(i);
	}
	refresh_counterd++;
}
var banner_refreshd = window.setInterval(refresh_bannersd, refresh_timed);