var SetPollValue = function(){
	var i_poll_answer = this.id.replace(/^poll-option-/, '');

	$('pollanswer').value = i_poll_answer;
	
	$$('div.poll-radiobutton').each(function(oEl){
		if (oEl.id == this.id){
			if (!oEl.hasClass('rb-checked')){
				oEl.addClass('rb-checked');
			}
			
			if (oEl.hasClass('rb-unchecked')){
				oEl.removeClass('rb-unchecked');
			}
		} else {
			if (oEl.hasClass('rb-checked')){
				oEl.removeClass('rb-checked');
			}
			
			if (!oEl.hasClass('rb-unchecked')){
				oEl.addClass('rb-unchecked');
			}
		}
	}, this);
	
	return false;
};

var InitTabs = function(){
	$$('div.tab').each(function(oTab){
		if (oTab.hasClass('passive')){
			oTab.addEvent('mouseover', function(){
				oTab.addClass('tab-mouseover');
			});
		
			oTab.addEvent('mouseout', function(){
				oTab.removeClass('tab-mouseover');
			});
		}
	});
}

var fbs_click = function (sTitle, sUrl){
	u = location.href;
	t = document.title;
	window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(sUrl) + '&t=' + encodeURIComponent(sTitle), 'sharer', 'toolbar=0,status=0,width=626,height=436');
	return false;
};

window.addEvent('domready', function(){
	
/*	if ($('vvdamsterdam-logo')){
		$('vvdamsterdam-logo').addEvent('click', function(){
			document.location = '/';
		});
	}*/
// ===== POLL ================================================================
	$$('div.poll-radiobutton').each(function(oEl){
		oEl.addEvent('click', SetPollValue);
	});
	
	$$('img.poll-vote-button').each(function(oEl){
		oEl.addEvent('click', function(){
			var i_poll_id = oEl.id.replace(/^poll-vote-button-/, '');
			$('pollid').value = i_poll_id;
			$('poll-vote').submit();
		});
	});

// ===========================================================================

// ===== TABS ================================================================
	$$('div.tab').each(function(oTab){
		switch (oTab.id){
			case 'tab-contact':
				oTab.addEvent('click', function(){
					document.location = '/contact/';
				});
				break;

			case 'tab-lidworden':
				oTab.addEvent('click', function(){
					document.location = '/lidworden/';
				});
				break;

			case 'tab-vvd-amsterdam':
				oTab.addEvent('click', function(){
					document.location = '/';
				});
				break;

			case 'tab-stadsdelen':
				oTab.addEvent('click', function(){
					document.location = '/stadsdelen/';
				});
				break;
		}
	});
	
	
	InitTabs();
// ===========================================================================


	$$('a.rc-button').each(function(oEl){
		oEl.addEvent('mouseover', function(){
			oEl.getElements('p').set('style','text-decoration: underline');
		});
		
		oEl.addEvent('mouseout', function(){
			oEl.getElements('p').set('style','text-decoration: none');
		});
	});

// ===== LOGIN FORM ==========================================================
	if ($('login-form')){
			$('login-user').addEvent('focus', function(){
				this.value = '';
				this.addClass('focus');
			}).addEvent('keypress', function(oEvent){
				if (oEvent.code == 13){
					$('login-form').submit();
				}
			}).addEvent('blur', function(){
				this.removeClass('focus');
			});

			$('login-pass').addEvent('focus', function(){
				this.value = '';
				this.addClass('focus');
			}).addEvent('keypress', function(oEvent){
				if (oEvent.code == 13){
					$('login-form').submit();
				}
			}).addEvent('blur', function(){
				this.removeClass('focus');
			});

			$('go-login').addEvent('click', function(){
				$('login-form').submit();
			});
		}
// ===========================================================================

	if ($('agenda-link')){
		$('agenda-link').addEvent('mouseover', function(){
			this.addClass('agenda-hover');
		}).addEvent('mouseout', function(){
			this.removeClass('agenda-hover');
		}).addEvent('click', function(){
			if ($('sub-site').get('text') == 'vvdamsterdam'){
				document.location = '/agenda/';
			} else {
				document.location = '/' + $('sub-site').get('text') + '/agenda/';
			}
		});
	}
	
	$$('table.agenda-punt').each(function(oEventTable){
		oEventTable.addEvent('click', function(){
			if ($('sub-site').get('text') == 'vvdamsterdam'){
				document.location = '/agenda/'+ oEventTable.id.replace(/^event-table-([\d]+)$/, '$1') +'/';
			} else {
				document.location = '/' + $('sub-site').get('text') + '/agenda/'+ oEventTable.id.replace(/^event-table-([\d]+)$/, '$1') +'/';
			}
		});
	});
});
