// Command Consulting common.js
// Paul Farning - ISITE Design

var quotes = new Array();
	quotes[0] = new Array();
		quotes[0][0] = "\"We hired Kevin and Devon because we felt the belief and passion about our product in our first meeting - they helped us create marketing tools and packaging that have lead to many positive remarks from our customers.  They are easy, thoughtful, helpful but most of all creative - definitely will continue our work with them.\"";
		quotes[0][1] = "Ronald Koskondy";
		quotes[0][2] = "President, GELZEEZ";
	
	quotes[1] = new Array();
		quotes[1][0] = "\"I've worked with Kevin Curry for several years.  He has a great understanding of communication and political strategies, the skills to implement ideas creatively, and a strong ability to help educate and persuade others.  When HBA recently needed some part-time communications and political consulting work, we turned to Kevin.  In addition, Kevin and Command Creative have also done work successfully for other parts of our organization, including the Home Builders Foundation.\"";
		quotes[1][1] = "David Nielsen";
		quotes[1][2] = "CEO, Home Builders Association of Metropolitan Portland";		

	quotes[2] = new Array();
		quotes[2][0] = "\"Command knows all parts of the legislative process and the players. They know who's important on what issues and why, and uses that knowledge to great advantage.\"";
		quotes[2][1] = "Greg Chaimov";
		quotes[2][2] = "Attorney & former Director of Legislative Counsel";

	quotes[3] = new Array();
		quotes[3][0] = "\"Command diligently met with our stakeholders and helped us determine a key demographic and theme that would work with our limited advertising budget. The resulting radio ad campaign was well received and a good start to our public relations efforts.\"";
		quotes[3][1] = "Elizabeth Coffey";
		quotes[3][2] = "Communications Director, Portland Metropolitan Association of Realtors";

	quotes[4] = new Array();
		quotes[4][0] = "\"I was fortunate to have both Kevin Curry and Devon Lyon on my staff in the Oregon Legislature, and I relied on them and their opinion. Businesses, initiative campaigns and political candidates will benefit from the same excellent political judgment. They get it.\"";
		quotes[4][1] = "Lynn Snodgrass";
		quotes[4][2] = "former Speaker of the Oregon House";
		
	quotes[5] = new Array();
		quotes[5][0] = "\"Command did an outstanding job producing our recent marketing brochure and show guide. The professionalism, speed of response and on-target product served our organization very well.\"";
		quotes[5][1] = "Suzanne Hankins";
		quotes[5][2] = "former Director of Events and Education, Oregon Association of Nurseries (2007)";

	quotes[6] = new Array();
		quotes[6][0] = "\"Kevin and Devon have the best combination of good instincts, creativity, and follow through.\"";
		quotes[6][1] = "Elaine Franklin";
		quotes[6][2] = "campaign consultant and former Chief of Staff, U.S. Senator Bob Packwood (2007-present)";




function dspRandQuote(start) {
	if (!document.getElementById) return false;
	
	var parentDiv = document.getElementById('quotes');

	if (document.getElementById('theblock')) {			
		var blocks = parentDiv.getElementsByTagName('blockquote');
		var removed = parentDiv.removeChild(blocks[0]);
		myQuote = (start+1 != quotes.length) ? start+1 : 0;
	} else {	
		if (document.getElementById('gov')) {
			var myQuote = 0;
		} else {
			var myQuote = Math.round(Math.random()*(quotes.length-1));
		}
	}
	
	var theblock = document.createElement('blockquote');
		theblock.setAttribute('title',quotes[myQuote][1]);
		theblock.setAttribute('id','theblock');
	
	var thequote = document.createElement('p');
	var	thequotet = document.createTextNode(quotes[myQuote][0]);
		thequote.appendChild(thequotet);	
	
	var thecite = document.createElement('p');
	
	var thebold = document.createElement('strong');
	var theboldt = document.createTextNode(quotes[myQuote][1]);
		thebold.appendChild(theboldt);
	
	var thebr = document.createElement('br');
	var thewho = document.createTextNode(quotes[myQuote][2]);
	
		thecite.appendChild(thebold);
		thecite.appendChild(thebr);
		thecite.appendChild(thewho);
		
		theblock.appendChild(thequote);
		theblock.appendChild(thecite);
			
		parentDiv.appendChild(theblock);
	
	Fat.fade_element("theblock", 60, 3000, "#ebebeb", "#333");
	var startit = InitializeTimer(15,'out',myQuote);
}

var direct;
var secs;
var timerID = null;
var timerRunning = false;
var delay = 1000;

function InitializeTimer(fadetime,direction,passalong) {
    secs = fadetime;
	direct = direction;
    StopTheClock();
    StartTheTimer(passalong);
}

function StopTheClock() {
    if(timerRunning) { clearTimeout(timerID); }
    timerRunning = false;
}

function StartTheTimer(quotetostart) {
    if (secs==0) {
        StopTheClock();
        if (direct=='out') {
			Fat.fade_element("theblock", 60, 3000, "#333", "#ebebeb");
			var startitin = InitializeTimer(3,'in',quotetostart);
        } else {
			dspRandQuote(quotetostart);
		}
    } else {
        secs = secs - 1;
        timerRunning = true;
        timerID = self.setTimeout("StartTheTimer("+quotetostart+")", delay);
    }
}

// @name      The Fade Anything Technique
// @namespace http://www.axentric.com/aside/fat/
// @version   1.0-RC1
// @author    Adam Michela
var Fat = {
	make_hex : function (r,g,b) 
	{
		r = r.toString(16); if (r.length == 1) r = '0' + r;
		g = g.toString(16); if (g.length == 1) g = '0' + g;
		b = b.toString(16); if (b.length == 1) b = '0' + b;
		return "#" + r + g + b;
	},
	fade_all : function ()
	{
		var a = document.getElementsByTagName("*");
		for (var i = 0; i < a.length; i++) 
		{
			var o = a[i];
			var r = /fade-?(\w{3,6})?/.exec(o.className);
			if (r)
			{
				if (!r[1]) r[1] = "";
				if (o.id) Fat.fade_element(o.id,null,null,"#"+r[1]);
			}
		}
	},
	fade_element : function (id, fps, duration, from, to) 
	{
		if (!fps) fps = 30;
		if (!duration) duration = 3000;
		if (!from || from=="#") from = "#FFFF33";
		if (!to) to = this.get_bgcolor(id);
		
		var frames = Math.round(fps * (duration / 1000));
		var interval = duration / frames;
		var delay = interval;
		var frame = 0;
		
		if (from.length < 7) from += from.substr(1,3);
		if (to.length < 7) to += to.substr(1,3);
		
		var rf = parseInt(from.substr(1,2),16);
		var gf = parseInt(from.substr(3,2),16);
		var bf = parseInt(from.substr(5,2),16);
		var rt = parseInt(to.substr(1,2),16);
		var gt = parseInt(to.substr(3,2),16);
		var bt = parseInt(to.substr(5,2),16);
		
		var r,g,b,h;
		while (frame < frames)
		{
			r = Math.floor(rf * ((frames-frame)/frames) + rt * (frame/frames));
			g = Math.floor(gf * ((frames-frame)/frames) + gt * (frame/frames));
			b = Math.floor(bf * ((frames-frame)/frames) + bt * (frame/frames));
			h = this.make_hex(r,g,b);
		
			setTimeout("Fat.set_bgcolor('"+id+"','"+h+"')", delay);

			frame++;
			delay = interval * frame; 
		}
		setTimeout("Fat.set_bgcolor('"+id+"','"+to+"')", delay);
	},
	set_bgcolor : function (id, c)
	{
		var o = document.getElementById(id);
		o.style.color = c;
	},
	get_bgcolor : function (id)
	{
		var o = document.getElementById(id);
		while(o)
		{
			var c;
			if (window.getComputedStyle) c = window.getComputedStyle(o,null).getPropertyValue("color");
			if (o.currentStyle) c = o.currentStyle.color;
			if ((c != "" && c != "transparent") || o.tagName == "BODY") { break; }
			o = o.parentNode;
		}
		if (c == undefined || c == "" || c == "transparent") c = "#FFFFFF";
		var rgb = c.match(/rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/);
		if (rgb) c = this.make_hex(parseInt(rgb[1]),parseInt(rgb[2]),parseInt(rgb[3]));
		return c;
	}
}
window.onload = function e() { dspRandQuote(0); Fat.fade_all(); }