
var strPrev = "";

function initVotes() {
	$('.accordion .accordionContent').hide();
	$('.accordion .accordionContent:first').slideToggle(300);
	$(".accordion h2.head").click(function()
    {
		$(this).next("div.accordionContent").slideToggle(300).siblings("div.accordionContent").slideUp("slow");
		$(this).addClass("visited");
		
		//do things differently if it's a toggle situation (the same element is being clicked) or if another item is being opened
		if (strPrev == this.id){
			$(".content").toggleClass(this.id);
			$(this).toggleClass("active");
		}else{
			$(this).addClass("active").siblings(".accordion h2.head").removeClass("active");
			$(".content").addClass(this.id).removeClass(strPrev);
			strPrev = this.id;
		}
		return false;
	});
	
 }
 
	
var createButtonCont = function(cls){
	
	var buttonCont = document.createElement("p");
	buttonCont.className=cls;
	
	buttonCont.appendChild(createButtons("Previous","arrowLink prevButton"));
	buttonCont.appendChild(createButtons("Next","arrowLink nextButton"));
	
	return buttonCont;
	
}

var createButtons = function(label,cls){

	var button = document.createElement("a");
	button.className=cls;
	button.innerHTML=label;
	button.href="#";
	return button;

}	
	  
$(document).ready(function() {
	initVotes();
	
	$("p.categorySponsor").before(createButtonCont("categoryButtons"));
	$("p.categoryButtons:first").empty().append(createButtons("Next","arrowLink nextButton"));
	$("p.categoryButtons:last").empty().append(createButtons("Previous","arrowLink prevButton"));

	$("a.nextButton").click(function() {
		$(this).parents("div.accordionContent").next(".accordion h2.head").trigger("click");
		return false;
	});
	
	$("a.prevButton").click(function() {
	
		var $previousOne = $(this).parents("div.accordionContent").prev(".accordion h2.active");
		$previousOne = $previousOne.prev(".accordion h2.head");
		$previousOne = $previousOne.prev(".accordion h2.head");
		$previousOne.trigger("click");
		return false;
	});
	
	$(".navigation").find("a").each(function(){
		$(this).hover(
			function(){
				$(this).find("span").stop().animate({
					width:"439px"		
				},250)
			},
			function(){
				$(this).find("span").stop().animate({
					width:"22em"
				})
			}
		);
	});
	
	
});



var openWin = function(url){

	window.open(url,"Newsletter","width=540px,height=670px,scrollbars=yes");

}



