/*

quote=##&showText=(true|false)

image max height: 89px;
no matting

*/


// to test view a specific quote use either
// NAME (taken from "imageName", eg: marketing or mary_kay_ash)
// or ARRAY NUMBER (starting with 0), 
// otherwise leave blank
var whichImage = "";

// if false, will display the quote as text rather than an image
var displayQuotesAsGraphics = false;

// if true, will display generated html in alert dialog
var debug = false;

// if false, will not write to page;
var writeHTML = true;

// pathname to the quotes folder;
var pathName = "images/global/quotes/";

// image type
var ext = ".png";

// imageName: name of png;
// imageMarginTop: margin to vertically center image;
// imageAlt: same text as the text found in the image; 
//		used as alt tag; 
//		used as alternative if showing quotes as text rather than graphics;
// textWidth: width of <div> holding the text quote;
// textMarginTop: margin to vertically center the text quote;

/*

with text only quotes, user is concerned with only 4 attributes:

imageAlt = the text quote

attribution = who said it

textWidth = how wide you want the quote to be
you can adjust this if the layout looks weird

textMarginTop = padding above the quote to make it vertically centered;
user might need to adjust till it looks good

when going with text quotes, there is no image, 
but user must still enter those data fields, like so:

		"imageName":"", 
		"imageWidth":0, 
		"imageHeight":0, 
		"imageMarginTop":0, 

*/

var quotes = new Array
	(
		{
		"imageName":"marketing", 
		"imageWidth":257, 
		"imageHeight":64, 
		"imageMarginTop":15,  
		
		"imageAlt":"If you don't approach Promotion Marketing as a constantly evolving service, your business is destined to wither and die.", 
		"attribution":"", 
		"textWidth":320,
		"textMarginTop":25
		}, 
	
		{
		"imageName":"mary_kay_ash", 
		"imageWidth":360, 
		"imageHeight":70, 
		"imageMarginTop":12, 
		
		"imageAlt":"People are definitely a company's greatest asset. It doesn't make any difference whether the product is cars or cosmetics. A company is only as good as the people it keeps.", 
		"attribution":"Mary Kay Ash", 
		"textWidth":390,
		"textMarginTop":18
		},
		 
		{
		"imageName":"zig_ziglar", 
		"imageWidth":252, 
		"imageHeight":51, 
		"imageMarginTop":22, 
		
		"imageAlt":"It is your attitude, not your aptitude, that determines your altitude.", 
		"attribution":"Zig Ziglar", 
		"textWidth":270,
		"textMarginTop":27
		},
	
		{
		"imageName":"john_illhan", 
		"imageWidth":301, 
		"imageHeight":71, 
		"imageMarginTop":12, 
		
		"imageAlt":"This may seem simple, but you need to give customers what they want, not what you think they want. And, if you do this, people will keep coming back.", 
		"attribution":"John Illham", 
		"textWidth":370,
		"textMarginTop":18
		},
		
		{
		"imageName":"stuart_wilde", 
		"imageWidth":334, 
		"imageHeight":71, 
		"imageMarginTop":11, 
		
		"imageAlt":"The point to remember about selling things is that, as well as creating atmosphere and excitement around your products, you've got to know what you're selling.", 
		"attribution":"Stuart Wilde", 
		"textWidth":390,
		"textMarginTop":17
		},
		
		{
		"imageName":"bill_clinton", 
		"imageWidth":321, 
		"imageHeight":58, 
		"imageMarginTop":17, 
		
		"imageAlt":"In the new economy, information, education, and motivation are everything.", 
		"attribution":"Bill Clinton", 
		"textWidth":290,
		"textMarginTop":25
		},
		
		{
		"imageName":"jeff_bezos", 
		"imageWidth":325, 
		"imageHeight":63, 
		"imageMarginTop":15, 
		
		"imageAlt":"If you do build a great experience, customers tell each other about that. Word of mouth is very powerful.", 
		"attribution":"Jeff Bezos", 
		"textWidth":350,
		"textMarginTop":28
		},
		
		{
		"imageName":"phillip_green", 
		"imageWidth":331, 
		"imageHeight":67, 
		"imageMarginTop":13, 
		
		"imageAlt":"It's all about quality of life and finding a happy balance between work and friends and family.", 
		"attribution":"Phillip Green", 
		"textWidth":370,
		"textMarginTop":28
		},
		
		{
		"imageName":"joe_gibbs", 
		"imageWidth":303, 
		"imageHeight":63, 
		"imageMarginTop":15, 
		
		"imageAlt":"People who enjoy what they are doing invariably do it well.", 
		"attribution":"Joe Gibbs", 
		"textWidth":290,
		"textMarginTop":28
		},
		
		{
		"imageName":"albert_einstein", 
		"imageWidth":324, 
		"imageHeight":46, 
		"imageMarginTop":25, 
		
		"imageAlt":"It's not that I'm so smart, it's just that I stay with problems longer.", 
		"attribution":"Albert Einstein", 
		"textWidth":235,
		"textMarginTop":28
		},
		
		{
		"imageName":"voltaire", 
		"imageWidth":279, 
		"imageHeight":61, 
		"imageMarginTop":15, 
		
		"imageAlt":"No problem can stand the assault of sustained thinking.", 
		"attribution":"Voltaire", 
		"textWidth":200,
		"textMarginTop":28
		}
	);
var totalQuotes = quotes.length;

// The Central Randomizer 1.3 (C) 1997 by Paul Houle (paul@honeylocust.com)
// See:  http://www.honeylocust.com/javascript/randomizer.html
// real: rnd();    integer: rand(someNumber)
rnd.today=new Date();
rnd.seed=rnd.today.getTime();
function rnd() { rnd.seed = (rnd.seed*9301+49297) % 233280; return rnd.seed/(233280.0); };
function rand(number) { return Math.floor(rnd()*number); };

var imgDivWidth = '<div style="float:right; width:';
var imgDivHeight = 'px;border:0px solid red; height:';
var imgDivImageMarginTop = 'px; margin-top:';
var imgDivEnd = 'px;">';
var imgEndDiv = '</div>';

var imgIMGSRC = '<img src="';
var imgWIDTH = '" width="';
var imgHEIGHT = '" height="';
var imgTITLE = '" title="';
var imgALT = '" alt="';
var imgBORDER = '" border="0" />';

var pngfixSPAN = "<span ";
var pngfixTITLE = " title=\""
var pngfixWIDTH = "\" style=\"display:inline-block; float:right; width:";
var pngfixHEIGHT = "px; height:";
var pngfiximageMarginTop = "px; margin-top:";
var pngfixALPHA1 = "px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'";
var pngfixALPHA2 = "\', sizingMethod='scale');\"></span>";

var textOnlyDIV = '<div style="float:right;text-align:right;width:';
var textOnlyDIVStyle = 'px;font-family:Arial;font-style:italic;font-size:13px;font-weight:bold;color:#FFFFFF;';
var textOnlyMarginTop = 'margin-top:';
var textOnlyDivEnd = 'px;">';
var textOnlyEndDiv = '</div>';

var clearDiv = '<div class="clear"></div>';



function quote()
	{
	if (getParameter("quote")) { r = getParameter("quote")-1; }
	// testing data using the image name
	else if ( whichImage.length>0 && !isNumeric(whichImage) ) { r = findQuote(whichImage); }
	// testing data using the array number of the image to test
	else if ( isNumeric(whichImage) ) { r = whichImage; }
	// otherwise, choose a random number to display a random quote
	else { r = rand(totalQuotes); }

	// error in testing mode: user chose image name not in array,
	// or chose number out of range of array
	if (r>totalQuotes || r==-1) 
		{
		displayQuotesAsGraphics=false; 
		var chosenAlt="Error. test number &gt; total number of quotes or test name is not a valid image name."
		var textWidth=200;
		var textMarginTop=20;
		var attribution="";
		var quotationMark="";
		}
	// choice within range
	else
		{
		var chosenImgName = quotes[r]["imageName"];
		var chosenWidth = quotes[r]["imageWidth"];
		var chosenHeight = quotes[r]["imageHeight"];
		var chosenAlt = quotes[r]["imageAlt"];
		var imageMarginTop = quotes[r]["imageMarginTop"];
		
		var attribution = quotes[r]["attribution"];
		var textMarginTop = quotes[r]["textMarginTop"];
		var textWidth = quotes[r]["textWidth"];
		var newImgStr = "";
		var quotationMark='<span class="quotationMarks">"</span>';
		}	
	// show quotes as images
	if (getParameter("showText")=="true") { displayQuotesAsGraphics = false; }
	
	if ( displayQuotesAsGraphics )
		{
		// find browser 
		var arVersion = navigator.appVersion.split("MSIE");
		var version = parseFloat(arVersion[1]);
		// png fix for ie5.5 and ie6
		if ((version >= 5.5 && version < 7 ) && (document.body.filters) && ext==".png")
			{ newImgStr = clearDiv + pngfixSPAN + pngfixTITLE + chosenAlt + pngfixWIDTH + chosenWidth + pngfixHEIGHT + chosenHeight + pngfiximageMarginTop + imageMarginTop + pngfixALPHA1 + pathName + chosenImgName + ext + pngfixALPHA2 + clearDiv; }
		// other browsers show png or gif directly
		else 
			{
			var imgHTML = imgIMGSRC + pathName + chosenImgName + ext + imgTITLE + chosenAlt + attribution + imgALT + chosenAlt + attribution + imgWIDTH + chosenWidth + imgHEIGHT + chosenHeight + imgBORDER;
			newImgStr =  clearDiv + imgDivWidth + chosenWidth + imgDivHeight  + chosenHeight + imgDivImageMarginTop + imageMarginTop + imgDivEnd + imgHTML +  imgEndDiv + clearDiv;
			}
		}
	// show quotes as text
	else
		{
		newImgStr = clearDiv + textOnlyDIV + textWidth + textOnlyDIVStyle + textOnlyMarginTop + textMarginTop + textOnlyDivEnd + quotationMark + chosenAlt + quotationMark;
		if (attribution.length>0) { newImgStr += "<p align='right' class='attribution'> &mdash; " + attribution + "</p>"; }
		newImgStr +=  textOnlyEndDiv + clearDiv;
		}
	// for developer debugging purposes
	if ( debug ) { alert(newImgStr); }
	if ( writeHTML ) { document.getElementById("quoteBox").innerHTML = newImgStr; }		
	}

function isNumeric(field) { var rtn = false; if (field) { var filter = /^[-.][0-9]+$/; rtn = filter.test(field); } return rtn; }
function findQuote(whichQuote) { r=-1;for(x=0;x<totalQuotes;x++) { if(whichQuote==quotes[x]["imageName"]){r=x;} } return r; }


function getParameter(arg)
	{
	var _d = document.location.toString();
	if(_d.indexOf("?")>0)
		{
		var _e = _d.split("?")[1];
		var _parms = new Array();
		var _valus = new Array();
		// parameters must have a &!
		var _f = _e.split("&");
		for(var i=0;i<_f.length;i++) 
			{
			if(_f[i].split("=")[0] == arg)
				{
		  		var qval = _f[i].split("=")[1];
		  		var qval_idx = qval.indexOf("#");
		  		if (qval_idx > -1) 
		  			{ qval = qval.substring(0, qval_idx); }
				return unescape(qval.replace(/\+/," "));
				}
			}
		}
	return "";
	}
