var emailfieldvalue;
var nivo_currslide;
var nivo_nextslide;
$j(window).load(function() { 
	$j('#bannerbox_img').nivoSlider({
		directionNav: false,
		controlNav: false,
		effect:'fade',
		animSpeed:250,
		beforeChange: function(){ 
			currindex = $j('#bannerbox_img').data('nivo:vars').currentSlide;
			totslides = $j('#bannerbox_img').data('nivo:vars').totalSlides;
			nivo_currslide = currindex + 1;
			
			
			if (nivo_currslide == totslides) nivo_nextslide = 1;
			else nivo_nextslide = nivo_currslide + 1;
			
			$j('#subj'+nivo_currslide).removeClass('banner_on');
			$j('#subj'+nivo_nextslide).addClass('banner_on');
		}
	});
	/*$j('.cycler').cycle({ 
		fx: cycler_type, 
		sync: true, 
		pause: 1, 
		timeout: 5000, 
		next: '#cyclerlink_right', 
		prev: '#cyclerlink_left', 
		cssBefore: { width:'728px', height:'327px' } 
	});*/
	
	/* $j('#orbit').orbit({
		animation: 'horizontal-push',
		animationSpeed: 500,
		advanceSpeed: 5000,
		pauseOnHover: true,
		startClockOnMouseOut: true,
		startClockOnMouseOutAfter: 500
	}); */
});


function swapSocialHomeButtons(elem) {
	if (elem != last_social_content) {
		$("img_home_"+last_social_content).src = "/img/mainv6/buttons/v8/home_"+last_social_content+"_off.png";
		$("img_home_"+elem).src = "/img/mainv6/buttons/v8/home_"+elem+"_on.png";
		$("socmedia_content_"+last_social_content).hide();
		$("socmedia_content_"+elem).show();
		last_social_content = elem;
	}
}

function checkMailStateFocus() {
	fld = document.forms['mailing'].signup_mail;
	if (fld.value!="") {
		emailfieldvalue = fld.value;
		fld.value="";
	}
}
function checkMailStateBlur() {
	fld = document.forms['mailing'].signup_mail;
	if (fld.value=="") fld.value = emailfieldvalue;
}
function fixedSize(url,name,features) {
	//This launches a new window and then
	//focuses it if window.focus() is supported.
	win = window.open(url,name,features);
}
function processSurvey(update) {
	question = $('pollqid').value;
	answer = 0;
	for (var i=0; i<document.survey.answer.length; i++) {
		if (document.survey.answer[i].checked) {
			answer = document.survey.answer[i].value;
		}
	}
	new Ajax.Request("/content/poll/processsurvey.php", { onSuccess: displaySurveyResult, method: "post", parameters: "answer="+answer+'&question='+question+'&update='+update });
}

function displaySurveyResult(data) {
	var obj = data.responseJSON;
	if (!Object.isUndefined(obj.result)) {
		$('pollanswers').toggle();
		$('pollresult').toggle();
		
		answers = obj.answer;		
		for (var i in answers) {
			barsize = answers[i].barsize+'px';
			$('pollresultanswer'+i).update(answers[i].text);
			$('pollresultvotes'+i).update(answers[i].perc+'%');
			//$('pollresultbar'+i).setStyle({ width:barsize });
			$('pollresultbar'+i).morph('width:'+barsize);
		}
	}
}
function setSurveyResults(answers) {
	x = 1;
	for(var i in answers) { $('pollresultbar'+x).morph('width:'+answers[i]+'px'); x++; }
}
