currentview = 0;
maxview = 9;

questionarray = new Array();
questionarray[0]="All delegates (2,118 needed)";
questionarray[1]="All super delegates";
questionarray[2]="In states still to vote";
questionarray[3]="In states won by Clinton";
questionarray[4]="In states won by Obama";
questionarray[5]="Former presidents & nat'l leaders";
questionarray[6]="'Add-ons' who balance gender";
questionarray[7]="Senate & House chairs";
questionarray[8]="Former presidential hopefuls";
questionarray[9]="Current members of Congress";
questionarray[10]="Super delegates voting with their state";
questionarray[11]="super delegates voting against their state";
questionarray[12]="Super delegates who have switched";
questionarray[13]="New endorsements in past week";
questionarray[14]="Uncommitted super delegates in states won by candidate";


function nextcomparison(){
	currentview++;
	if (currentview>maxview){
		currentview=0;
	}
	showComparison(currentview);
}
function prevcomparison(){
	currentview--;
	if (currentview<0){
		currentview=maxview;
	}
	showComparison(currentview);
}

function showComparison(compnum){
	currentview = compnum;
	
	maxvalue = comparisonarray[compnum][0]+comparisonarray[compnum][1];
	if (maxvalue < comparisonarray[compnum][2]+comparisonarray[compnum][3]){
		maxvalue = comparisonarray[compnum][2]+comparisonarray[compnum][3];
	}
	if (maxvalue < comparisonarray[compnum][4]+comparisonarray[compnum][5]){
		maxvalue = comparisonarray[compnum][4]+comparisonarray[compnum][5];
	}
	if (compnum==0){
		maxvalue=2118;
	}
	else {
		maxvalue = 500;//number_of_superdelegates;
	}
	width1a = Math.round(comparisonarray[compnum][0]/maxvalue*totalwidth);
	width1b = Math.round(comparisonarray[compnum][1]/maxvalue*totalwidth);
	width1c = totalwidth - width1a - width1b;
	width2a = Math.round(comparisonarray[compnum][2]/maxvalue*totalwidth);
	width2b = Math.round(comparisonarray[compnum][3]/maxvalue*totalwidth);
	width2c = totalwidth - width2a - width2b;
	width3a = Math.round(comparisonarray[compnum][4]/maxvalue*totalwidth);
	width3b = Math.round(comparisonarray[compnum][5]/maxvalue*totalwidth);
	width3c = totalwidth - width3a - width3b;
	
	document.getElementById('imgc1').style.width=width1a + "px";
	document.getElementById('imgc2').style.width=width1b + "px";
	document.getElementById('imgc3').style.width=width1c + "px";
	if (compnum==0){
		document.getElementById('counter_c1').innerHTML=(comparisonarray[compnum][0]);
		document.getElementById('counter_c1text').innerHTML="pledged";
		document.getElementById('counter_c2').innerHTML=(comparisonarray[compnum][1]);
		document.getElementById('counter_c2text').innerHTML="super";
	}
	else {
		document.getElementById('counter_c1').innerHTML=(comparisonarray[compnum][0]);
		if (comparisonarray[compnum][0] == 1){
			document.getElementById('counter_c1text').innerHTML="super delegate";
		}
		else{
			document.getElementById('counter_c1text').innerHTML="super delegates";
		}
		document.getElementById('counter_c2').innerHTML="";
		document.getElementById('counter_c2text').innerHTML="";
	}
	document.getElementById('imgo1').style.width=width2a + "px";
	document.getElementById('imgo2').style.width=width2b + "px";
	document.getElementById('imgo3').style.width=width2c + "px";
	if (compnum==0){
		document.getElementById('counter_o1').innerHTML=(comparisonarray[compnum][2]);
		document.getElementById('counter_o1text').innerHTML="pledged";
		document.getElementById('counter_o2').innerHTML=(comparisonarray[compnum][3]);
		document.getElementById('counter_o2text').innerHTML="super";
	}
	else {
		document.getElementById('counter_o1').innerHTML=(comparisonarray[compnum][2]);
		if (comparisonarray[compnum][2] == 1){
			document.getElementById('counter_o1text').innerHTML="super delegate";
		}
		else{
			document.getElementById('counter_o1text').innerHTML="super delegates";
		}
		document.getElementById('counter_o2').innerHTML="";
		document.getElementById('counter_o2text').innerHTML="";
	}
	document.getElementById('imgu1').style.width=width3a + "px";
	document.getElementById('imgu2').style.width=width3b + "px";
	document.getElementById('imgu3').style.width=width3c + "px";
	if (compnum==0){
		//document.getElementById('counter_u1').innerHTML=(comparisonarray[compnum][4]);
		document.getElementById('counter_u1').innerHTML="";
		document.getElementById('counter_u1text').innerHTML="pledged";
		document.getElementById('counter_u2').style.display="inline";
		document.getElementById('counter_u2text').style.display="inline";
	}
	else {
		//document.getElementById('counter_u1').innerHTML=(comparisonarray[compnum][4]);
		document.getElementById('counter_u1').innerHTML="";
		if (comparisonarray[compnum][4] == 1){
			//document.getElementById('counter_u1text').innerHTML="super delegate";
			document.getElementById('counter_u1text').innerHTML="";
		}
		else{
			//document.getElementById('counter_u1text').innerHTML="super delegates";
			document.getElementById('counter_u1text').innerHTML="";
		}
		document.getElementById('counter_u2').style.display="none";
		document.getElementById('counter_u2text').style.display="none";
	}


	if (compnum==0){
		document.getElementById('label_needed_hrc').style.display = "inline";
		document.getElementById('label_needed_bo').style.display = "inline";
		document.getElementById('uncommittedextraheadline').style.display = "inline";
	}
	else {
		document.getElementById('label_needed_hrc').style.display = "none";
		document.getElementById('label_needed_bo').style.display = "none";
		document.getElementById('uncommittedextraheadline').style.display = "none";
	}

	document.getElementById('nhsdt_headline').innerHTML = questionarray[compnum];
	
}

YAHOO.namespace("example.container2");

function showEmbedLink (){

	alert ('a');
	YAHOO.example.container2.simpledialog2 = new YAHOO.widget.SimpleDialog("simpledialog2", 
																		 { width: "300px",
																		   fixedcenter: true,
																		   visible: false,
																		   draggable: false,
																		   close: true,
																		   text: 'Copy and paste the following code to your Web site or blog:<br /><br /><input type="text" size=40 value="<scr'+'ipt src=\'http://www.pbs.org/newshour/vote2008/primaries/superdelegates/newshour_superdelegate_tracker_widget.php\' type=\'text/javascript\'></scr'+'ipt>" /><br /><br /><span onclick="YAHOO.example.container2.simpledialog2.hide();"  style="cursor:pointer;cursor:hand;float:right;" onMouseOver="this.style.textDecoration=\'underline\';" onMouseOut="this.style.textDecoration=\'none\';" ><b>Done</b></span>',
																		   icon: false,
																		   constraintoviewport: true,
																		   buttons: [ ]
																		 } );
	YAHOO.example.container2.simpledialog2.setHeader("Embed the Tracker on Your Web Site");
	YAHOO.example.container2.simpledialog2.render("container2");
	YAHOO.example.container2.simpledialog2.show();
}