//event.preventDefault();
$(document).ready(function(){
	setTimeout('hallofshamewidget()', 1000);
	setupForms();
	$('.item-p-dd').click(function(event){
		var item = this.getAttribute('item');
		var i = 0;
		while(true){
			var obj = document.getElementById('ul-'+i);
			if(i > 20) break;
			if(obj == null){
				break;
			}else{
				if(i != item){
					obj.style.display = 'none';
				}
			}
			i++;
		}
		if($('#ul-'+item).is(':hidden')){
			$('#ul-'+item).fadeIn('slow');
		}else{
			$('#ul-'+item).fadeOut('slow');
		}
	});
	
	$('#main-header-inputs input').click(function(event){
		$(event.target).val('');
	});

	$('#join-button').click(function(event){
		var email = $('#join-email').val();
		var zip  = $('#join-zip').val();
		if(	email != '' && email != 'email' &&
			zip != '' && zip  != 'zip'){
			$('.join').animate({ opacity: 'hide' }, 'slow');
			$.ajax({
				url: '/action/join',
				data: 'email=' + email + '&zip=' + zip,
				success: function(msg){
					$('#join-notification').show();
					$('#join-notification').html('Thank you for joining');
					$('#join-notification').css({'color' : 'white'});
					jQuery.cookie('email-list-join', 'true');
				}
			});
		}else{
			if(email == '' || email == 'email'){
				$('#join-email').css({'border-color' : 'red'});
			}

			if(email != '' && email != 'email'){
				$('#join-email').css({'border-color' : 'black'});
			}

			if(zip == '' || zip == 'zip'){
				$('#join-zip').css({'border-color' : 'red'});
			}

			if(zip != '' && zip != 'zip'){
				$('#join-zip').css({'border-color' : 'black'});
			}
		}
	});
	$('#espanol-button').click(function(event){
		window.location.href = '/espanol';
	});
});

function setupForms(){
	$('#join-email').val('email');
	$('#join-zip').val('zip');
	if(jQuery.cookie('email-list-join') == 'true'){
		$('#join-notification').show();
		$('#join-notification').html('Thank you for joining');
		$('#join-notification').css({'color' : 'white'});
		$('.join').hide();
	}
}

function hallofshamewidget(){
	jQuery.ajax({
		url: '/hallofshame/widget',
		success: function(msg){
			$('#main-shame').html(msg);
			$('#main-shame').click(function(event){
				window.location.href = "/hallofshame"
			});

			$('#shame-scroller').cycle({
				fx: 'fade',
				timeout: 6500,
				speed: 2000
			});
		}
	});
}
