$(document).ready(function(){

	initLayout();
	
});

function initLayout(){
	setupAskPollyCoa();
	setupAskPolly();	
}


function updateLayoutOnStateChange(state) {
	// add and remove scroll pane for archive
	if(state=="archive"){
		$('.scroll-pane').jScrollPane({scrollbarWidth: 15, dragMinHeight: 43, dragMaxHeight:43});
	} else {
		$('.scroll-pane').jScrollPaneRemove();
	}
}

function setupAskPollyCoa(){
	// show ask polly question
	$('#ask-poly-coa').removeClass('hide');

	// on complete function
	var askCoaOnCompleteOut = function() {
		jQuery('#ask-poly').animate({
		    top: [0, 'easeout']
		}, 500);
	};
	
	// add click animation
	$('#ask-poly-coa').click(function(event) {
		$('#ask-poly-coa').animate({top:-100},{
		    duration: 300,
		    complete: askCoaOnCompleteOut
		});
	});
	
	// add click animation
	$('#ask-poly-close').click(function(event) {
		$('#ask-poly').animate({top:-200},{
		    duration: 300,
		    complete: askPolyCloseOut
		});
		return false;
	});
}

function askPolyCloseOut(){
	$('#ask-poly-coa').animate({top:0},{
	    duration: 300
	});
	// clear functions 
	resetAskForm();
	clearSubmitwarnings();
}


function setupAskPolly() {
	// move off screen
	$('#ask-poly').addClass('ask-poly-start-position');

	// hide ask question thankyou message
	$('#ask-poly-thankyou').hide();
	
	// hide cast vote thank you message
	$('#vote-thanks').hide();
	
	// hide cast vote final message
	$('#vote-thanks-final').hide();
}
