// JavaScript Document
function submitPoll() {
	
var callback =
	{
	  success: function(o) {
		  			var poll_container = document.getElementById("poll_container");
		  			poll_container.innerHTML = o.responseText;
		  		},
	  failure: function(o) {/*failure handler code*/},
	  timeout: 5000
	}
	
	var formObject = document.getElementById('poll_form');
	YAHOO.util.Connect.setForm(formObject);
	document.cookie="poll_id="+document.getElementById("poll_id").value+";path=/";
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/ajax/poll/', callback);


	return false;
}

function viewTally(poll_id) {
	
	// argument formId can be the id or name attribute value of the
// HTML form, or an HTML form object.

var callback =
	{
	  success: function(o) {
		  			var poll_container = document.getElementById("poll_container");
		  			poll_container.innerHTML = o.responseText;
					
					
		  		},
	  failure: function(o) {/*failure handler code*/},
	  timeout: 5000
	}
	
	
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/ajax/poll/', callback, "poll_id="+poll_id+"&view_tally=1");


	return false;
}

function viewPoll(poll_id) {
	
	// argument formId can be the id or name attribute value of the
// HTML form, or an HTML form object.

var callback =
	{
	  success: function(o) {
		  			var poll_container = document.getElementById("poll_container");
		  			poll_container.innerHTML = o.responseText;
					
					
		  		},
	  failure: function(o) {/*failure handler code*/},
	  timeout: 5000
	}
	
	
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/ajax/poll/', callback, "poll_id="+poll_id+"&view_poll=1");


	return false;
}

/***********************************************************/
/***** Handle onpening and closing of archived polls  *****/


function expandPoll(poll_id, controller){
	
	//var region = YAHOO.util.Dom.getRegion(synopsis_id);
	//var synopsis_height = region.bottom - region.top;
	controller.onclick=function(){shrinkPoll(poll_id, controller);};
	 //YAHOO.util.Dom.setStyle(article_id, 'display', 'block'); 
	 
	 for(var i =0; i<result_heights.length; i++){
			if (result_heights[i].id == poll_id){
				var height = parseInt(result_heights[i].height);
				if(BrowserDetect.browser=="Explorer" && BrowserDetect.version<=6) 			
					height += 10;
				break;
			}
	 }
	 
	 
	
	
	
	
	
    var anim = new YAHOO.util.Anim(poll_id, {height: { from: 0, to: height }}, 1.0, YAHOO.util.Easing.easeBothStrong);
	anim.onComplete.subscribe(resetContentBackground);
	anim.animate(); 
	
}

function shrinkPoll(poll_id, controller){
	
	
	controller.onclick=function(){expandPoll(poll_id, controller);};
	
	var anim = new YAHOO.util.Anim(poll_id, {height: { to:0 }}, 1.0, YAHOO.util.Easing.easeBothStrong);
	anim.onComplete.subscribe(resetContentBackground);
	anim.animate(); 
	
	
}

var result_heights = new Array()
function init() { 
		var ec= new Array();
		ec = YAHOO.util.Dom.getElementsByClassName('archive_poll_results');
		
			for (var i=0; i<ec.length; i++){
				
				var id = ec[i].id;
				var region = YAHOO.util.Dom.getRegion(ec[i]);
				result_heights.push( {id:ec[i].id, height: (region.bottom-region.top)}); 
				
			}
				
	   YAHOO.util.Dom.setStyle(ec, "height", "0"); 
	   
	   //openArticle();
	   
	  resetContentBackground()
	} 
	YAHOO.util.Event.onDOMReady(init);