
window.addEvent('domready', function() {
	var portlets = new Portlets();
	$$('#content div div').each(function(portlet) {
		if ( portlet.hasClass('portlet') ) {
			portlets.enableMotion(portlet);
			
			if ( portlet.getProperty('id').substring(0, portlet.getProperty('id').indexOf('_')) == 'blog' ) {
				// previous button
				portlet.getChildren()[1].getChildren()[1].addEvent('click', function() {
					var contentDivs = portlet.getChildren()[3].getChildren();
					var count = Number(this.getParent().getChildren()[0].getText());
					contentDivs[count].setStyle('display', 'none');
					count = (count - 1 < 0) ? contentDivs.length-1 : count - 1;
					contentDivs[count].setStyle('display', 'block');
					this.getParent().getChildren()[0].setText(count)
				});
				
				// next button
				portlet.getChildren()[1].getChildren()[2].addEvent('click', function() {
					var contentDivs = portlet.getChildren()[3].getChildren();
					var count = Number(this.getParent().getChildren()[0].getText());
					contentDivs[count].setStyle('display', 'none');
					count = (count + 1 > contentDivs.length - 1) ? 0 : count + 1;
					contentDivs[count].setStyle('display', 'block');
					this.getParent().getChildren()[0].setText(count)
				});
			}
		}
	});
	
	// for portal.php
	// make View Results link toggle to show results and poll
	$$('#content div div div p').each(function(item) {
		if (item.hasClass('viewResults') ) {
			item.addEvent('click', function() {
				item.getParent().getChildren().each(function(content) {
					if ( content.hasClass('portletContent') ) {
						if ( content.getStyle('display') == 'none' ) {
							content.setStyle('display', 'block');
						} else {
							content.setStyle('display', 'none');
						}
						if ( item.getText() == 'View Results' ) {
							item.setText('View Poll');
						} else {
							item.setText('View Results');
						}
					}
				});
			});
		}
	});
	
	/*$$('#portletsMenu ul li').each(function(listItem) {
		portlets.enableListMotion(listItem);
	});*/
});

function setup() {	
	
}
