/* 
--- THE CONFIGURABLES ---
width: this will control the width of the widget, should be used to let the widget fit the column it is being included in.
bordercolor: The color of the borer of this widget, should be a 6 digit hex number or 'none' if no border is the requirement.
bgcolor: The background color of the widget.
textcolor: The color of the text blurb, , should be a 6 digit hex number.
textfont: The font style of the blurb, should be either 'sans' or 'serif' and the script will make it Arial or Georgia.
textsize: The pixel size of the blurb text.
linkcolor: The color of the link text, , should be a 6 digit hex number.
linkfont: The font style of the link, should be either 'sans' or 'serif' and the script will make it Arial or Georgia.
linksize: The pixel size of the link text.
partnerid: This is a way to track your partners
logolink: If you need to link to a different image for a certain partner this is how to do it.

--- THE TAG ---
The basic tag with no customization:
<script id="asbcwidget" src="http://asbc.oomphdev.com/widget.js"></script>

The tag with all the bells and whistles: NOTE: The ? after the widget.js starts the process of customization and the & after each configurable tells the script that there is another element to come.
<script id="asbcwidget" src="http://asbc.oomphdev.com/widget.js?partnerid=cmurray&width=181&bordercolor=ff0000&bgcolor=000000&textcolor=ffffff&textfont=serif&textsize=10&linkcolor=eeeeee&linkfont=sans&linksize=10&logolink=usbusinesscouncil.com/asbc-logo-2.png"></script>
*/



/* THE TEXT - This is the text blurb that appears uner the logo */

var text = 'Current Policy Campaigns:';

var thelinks = new Array();

/* THE LINKS - These are the links that appear under the text */

/* THE LINKS - Format: for each link you need 'thelinks[NUMBER] =' to be declared */

/* THE LINKS - Format: The you put '["LINK NAME", "LINK URL"];' Besure to remember the semi-colon or it will break*/

thelinks[0] = ["Benefit Corporations", "http://org2.democracyinaction.org/o/6269/p/dia/action/public/?action_KEY=3371"];

thelinks[1] = ["Climate Change", "http://org2.democracyinaction.org/o/6269/p/dia/action/public/?action_KEY=4784"];

thelinks[2] = ["Business for Democracy","http://org2.democracyinaction.org/o/6269/p/dia/action/public/?action_KEY=5431"];

thelinks[3] = ["Tax Havens", "http://org2.democracyinaction.org/o/6269/p/dia/action/public/?action_KEY=3710"];

thelinks[4] = ["Toxic Chemicals", "http://org2.democracyinaction.org/o/6269/p/dia/action/public/?action_KEY=2048"];

thelinks[5] = ["more...", "http://www.asbcouncil.org"];






/* the following two are not currently live */

/* thelinks[0] = ["Get Involved", "http://www.asbcouncil.org/Overview.html"]; */

/* thelinks[1] = ["Contact Us", "http://www.asbcouncil.org/Contact_ASBC.html"]; */



/* ! SETS UP DEFAULT STYLES */
var logolink = 'asbc.oomphdev.com/asbc-logo.png';
var styles = 'padding:5px;';
var width = '181';
var imgwidth = width;
var bordercolor = '999933';
var bgcolor = 'ffffff';
var textcolor = '999999';
var textfont = 'sans';
var textsize = '11';

var links = '';
var linkstyles = 'text-decoration:none;';
var linkcolor = '336699';
var linkfont = 'serif';
var linksize = '11';

var partnerid = false;


/* ! DO NOT EDIT BELOW THIS COMMENT */
function getValue(varname)
{
  // First, we load the URL into a variable
  var url = document.getElementById('asbcwidget').getAttribute('src');

  // Next, split the url by the ?
  var qparts = url.split("?");

  // Check that there is a querystring, return "" if not
  if (qparts.length == 0)
  {
    return "";
  }

  // Then find the querystring, everything after the ?
  var query = new String(qparts[1]);

  // Split the query string into variables (separates by &s)
  var vars = query.split("&");

  // Initialize the value with "" as default
  var value = "";

  // Iterate through vars, checking each one for varname
  for (i=0;i<vars.length;i++)
  {
    // Split the variable by =, which splits name and value
    var parts = vars[i].split("=");
    
    // Check if the correct variable
    if (parts[0] == varname)
    {
      // Load value into variable
      value = parts[1];

      // End the loop
      break;
    }
  }
  
  // Convert escape code
  value = unescape(value);

  // Convert "+"s to " "s
  value.replace(/\+/g," ");
   
  // Return the value
  if (value.length < 1) { return false; }
  else { return value; }  
}
// ! TEXT BLOCK VALUE AND STYLES
(text) ? text = '<p style="padding: 5px 0; margin:0;">'+text+'</p>' : text = '';
(getValue('textcolor') != false) ? styles = styles + 'color:#'+getValue('textcolor')+';' : styles = styles + 'color:#'+textcolor+';';
(getValue('textfont') == 'sans') ? styles = styles + 'font-family:Arial, sans-serif;' : styles = styles + 'font-family:Georgia, serif;';
(getValue('textsize') != false) ? styles = styles + 'font-size:'+getValue('textsize')+'px;' : styles = styles + 'font-size:'+textsize+'px;';
// ! CONTAINER STYLES
(getValue('bgcolor')) ? styles = styles + 'background-color:#'+getValue('bgcolor')+';' : styles = styles + 'background-color:#'+bgcolor+';';
(getValue('bordercolor')) ? styles = styles +'border:solid 1px #'+getValue('bordercolor')+';' : styles = styles +'border:solid 1px #'+bordercolor+';';
(getValue('width')) ? styles = styles +'width:'+getValue('width')+'px;' : styles = styles +'width:'+width+'px;';
(getValue('width')) ? imgwidth = getValue('width') : imgwidth = width;
// ! LINK ARRAY STYLES
(getValue('linkcolor')) ? linkstyles = linkstyles +'color:#'+getValue('linkcolor')+';' : linkstyles = linkstyles +'color:#'+linkcolor+';';
(getValue('linkfont') == 'sans') ? linkstyles = linkstyles + 'font-family:Arial, sans-serif;' : linkstyles = linkstyles + 'font-family:Georgia, serif;';
(getValue('linksize') != false) ? linkstyles = linkstyles + 'font-size:'+getValue('linksize')+'px;' : linkstyles = linkstyles + 'font-size:'+linksize+'px;';
// ! PARTNER ID 
var partneridvalue = '';
(getValue('partnerid') != false) ? partneridvalue = '?partnerid='+getValue('partnerid') : '';
// ! LOGO LINK
(getValue('logolink') != false) ? logolink = getValue('logolink') : logolink = logolink;
// ! LOOP THE LINKS
for (var i = 0; i < thelinks.length; i++)
{
	var url = thelinks[i][1];
	var name = thelinks[i][0];
	links = links + '<a style="'+linkstyles+'"href="'+url+partneridvalue+'" onmouseover="this.style.textDecoration = \'underline\'" onmouseout="this.style.textDecoration = \'none\'">'+name+'</a><br />';
}
document.write('<div style="'+styles+'"><img style="margin:0 auto; width:'+imgwidth+'px;" src="http://'+logolink+'" /><br />'+text+''+links+'</div>');
