var lastPanel = 1;
var maxPanel = 1;
var rotateSpeed = 2000;
var rotator = null;

function rotateBillBoard() {
	var newBoard = parseInt(lastPanel) + 1;

	if (newBoard > maxPanel) {
		newBoard = 1;
	}

	switchPanel(newBoard);
	
	rotator = setTimeout("rotateBillBoard()",rotateSpeed);
}

function switchPanel(panelNum) {
	Effect.Fade(('billBoard' + lastPanel), { duration: 1.0 });
	lastPanel = panelNum;
	
	setTimeout("showPanel()",1100);
}

function manSwitchPanel(panelNum) {
	clearInterval(rotator);

	Effect.Fade(('billBoard' + lastPanel), { duration: 1.0 });
	lastPanel = panelNum;
	
	setTimeout("showPanel()",1100);
	rotator = setTimeout("rotateBillBoard()",rotateSpeed);
}
			
function showPanel() {
	// shows a new panel
	Effect.Appear(('billBoard' + lastPanel), { duration: 1.0 });
}

function startRotation(startPanel) {
	// starts the rotation
	rotator = setTimeout("rotateBillBoard()",rotateSpeed);
	lastPanel = startPanel;
	showPanel();
}


		
function BillBoard() {
	this.panelCount = 0;
	this.panels = null;
	this.rotationSpeed = 2000;
	
	this.setPanelCount = function(num) {
		this.panelCount = num;
		this.panels = new Array();
	}
	
	this.getPanelCount = function() {
		return this.panelCount;
	}
	
	this.setRotationSpeed = function(speed) {
		this.rotationSpeed = speed;
	}
	
	this.getRotationSpeed = function() {
		return this.rotationSpeed;
	}
	
	this.addPanel = function(panel) {
		this.panels[(this.panels.length)] = panel;
	}

	this.render = function(targetDiv) {
		var target = document.getElementById(targetDiv);

		// go through each panel and make html
		for (x = 0; x < this.panels.length; x++) {
			var panel = this.panels[x];
			var html = '';
			
			// most of the content
			html += '<div class="span-10">';
			html += '<img src="' + panel.getThumbNail() + '" width="' + panel.getThumbWidth() + '" height="' + panel.getThumbHeight() + '" title="' + panel.getThumbTitle() + '" alt="' + panel.getThumbTitle() + '"/>';
			html += '</div>';
			html += '<div class="span-14 last">';
			html += '<div class="billBoardHeader">' + panel.getTitle() + '</div>';
			html += '<div class="billBoardText">';
			html += '<span>' + panel.getDescription() + '</span>';
			html += '<span class="break"></span>';
			html += '<span><a href="' + panel.getMoreLink() + '">Learn More...</a></span>';
			html += '</div>';
			html += '<div>';
			
			// put in links to the other panels
			for (y = this.panels.length; y > 0; y--) {
				if (y == (x+1)) {
					html += '<div class="billBoardNumber billBoardNumberOn">' + (y) + '</div>';
				} else {
					html += '<div class="billBoardNumber billBoardNumberOff" onClick="manSwitchPanel(\'' + (y) + '\')">' + (y) + '</div>';
				}
			}
			
			html += '</div>';
			html += '</div>';
			
			// create a new element so we can access it later
			var newDiv = document.createElement('div');
			newDiv.setAttribute('id', 'billBoard' + (x+1));
			newDiv.setAttribute('class', 'span-24 last billBoardPanel');
			newDiv.innerHTML = html;
			
			// tack it in the doc
			target.appendChild(newDiv);
			
			// need to do here because IE sucks
			document.getElementById('billBoard' + (x+1)).style.display = 'none';
		}
	}
}



function BillBoardPanel() {
	this.title = '';
	this.description = '';
	this.moreLink = '';
	this.thumbNail = '';
	this.thumbWidth = '400';
	this.thumbHeight = '270';
	this.thumbTitle = '';
	
	this.setTitle = function(text) {
		this.title = text;
	}
	
	this.getTitle = function() {
		return this.title;
	}
	
	this.setDescription = function(text) {
		this.description = text;
	}
	
	this.getDescription = function() {
		return this.description;
	}
	
	this.setMoreLink = function(link) {
		this.moreLink = link;
	}
	
	this.getMoreLink = function() {
		return this.moreLink;
	}
	
	this.setThumbNail = function(image) {
		this.thumbNail = image;
	}
	
	this.getThumbNail = function() {
		return this.thumbNail;
	}
	
	this.setThumbWidth = function(width) {
		this.thumbWidth = width;
	}
	
	this.getThumbWidth = function() {
		return this.thumbWidth;
	}
	
	this.setThumbHeight = function(height) {
		this.thumbHeight = height;
	}
	
	this.getThumbHeight = function() {
		return this.thumbHeight;
	}
	
	this.setThumbTitle = function(title) {
		this.thumbTitle = title;
	}
	
	this.getThumbTitle = function() {
		return this.thumbTitle;
	}
}

function createBillBoard() {
	// create a new billboard rotator
	var billBoard = new BillBoard();
	billBoard.setPanelCount(3);
	billBoard.setRotationSpeed(10000);

	// add in the panels
	var panel = new BillBoardPanel();
	panel.setTitle('Mobile Applications');
	panel.setDescription('BrickSimple created the handheld application and server infrastructure that powers 1337pwn.com, a mobile data application with several hundred thousand users across the globe. With millions of gamers tracked daily, our application now processes the largest amount of XBOX Live data outside of Microsoft.<span class="break"></span>BrickSimple developed native applications for iPhone/iPod Touch and Google Android devices, which are provided to the community free of charge.');
	panel.setMoreLink('mobile_applications.php');
	panel.setThumbNail('images/screens/thumbs/iphone_4.png');
	panel.setThumbTitle('iNXES XBOX Live Friends Application - iPhone/iPod Touch');
	billBoard.addPanel(panel);
	
	panel = new BillBoardPanel();
	panel.setTitle('Criminal Justice Software');
	panel.setDescription('Public safety threats cross community and agency boundaries. Preventing dangerous outbreaks requires timely access to information and the ability to identify risks before they threaten communities.<span class="break"></span>Prevention and Response Infrastructure for Safety and Management (PRISM&trade;) is a technology solution that gathers timely aggregate data and vital statistics from first responder information systems. With PRISM&trade;, emergency management, law enforcement, and criminal justice personnel are provided with a comprehensive view of threats to communities across existing systems.');
	panel.setMoreLink('criminal_justice_software.php');
	panel.setThumbNail('images/screens/thumbs/prism_1.png');
	panel.setThumbTitle('PRISM - Geolocation of Incidents');
	billBoard.addPanel(panel);
	
	panel = new BillBoardPanel();
	panel.setTitle('Staffing Software');
	panel.setDescription('BrickSimple developed one of the first large-scale, web-based software systems to support executive recruiting and temp/perm contracting organizations.<span class="break"></span>The software is available via ASP on a user-per month pricing basis, or on a software license basis for organizations desiring to host themselves.');
	panel.setMoreLink('executive_staffing_software.php');
	panel.setThumbNail('images/screens/thumbs/warp_1.png');
	panel.setThumbTitle('WARP - Candidate Detail');
	billBoard.addPanel(panel);
	
	maxPanel = billBoard.getPanelCount();
	rotateSpeed = billBoard.getRotationSpeed();
	
	// render it on the page
	billBoard.render('billBoardContainer');

	// start rotating on a random panel
	var randStart = Math.floor(Math.random()*(billBoard.getPanelCount() + 1));

	if (randStart == 0) {
		randStart = 1;
	}
	
	// forcing at 1 for now
	randStart = 1;
	
	startRotation(randStart);
}
