var contestants = new Array(6);

contestants[0] = new Array(7);
contestants[1] = new Array(7);
contestants[2] = new Array(7);
contestants[3] = new Array(7);
contestants[4] = new Array(7);
contestants[5] = new Array(7);

contestants[0][0] = -1083; //TONY
contestants[0][1] = -274;
contestants[0][2] = 123;
contestants[0][3] = 'tony';
contestants[0][4] = 0;
contestants[0][5] = 261;
contestants[0][6] = 192;

contestants[1][0] = -1021; //KEVIN
contestants[1][1] = -307;
contestants[1][2] = 15;
contestants[1][3] = 'kevin';
contestants[1][4] = 40;
contestants[1][5] = 489;
contestants[1][6] = 121;

contestants[2][0] = -1219; //RICK
contestants[2][1] = 12;
contestants[2][2] = -28;
contestants[2][3] = 'rick';
contestants[2][4] = 80;
contestants[2][5] = 773;
contestants[2][6] = 81;

contestants[3][0] = -1060; //JARETT
contestants[3][1] = -415;
contestants[3][2] = -65;
contestants[3][3] = 'jarett';
contestants[3][4] = 120;
contestants[3][5] = 501;
contestants[3][6] = 355;

contestants[4][0] = -750; //JIMMY
contestants[4][1] = -25;
contestants[4][2] = 88;
contestants[4][3] = 'jimmy';
contestants[4][4] = 160;
contestants[4][5] = 110;
contestants[4][6] = 328;

contestants[5][0] = -434; //MITCH
contestants[5][1] = -338;
contestants[5][2] = -39;
contestants[5][3] = 'mitch';
contestants[5][4] = 200;
contestants[5][5] = 240;
contestants[5][6] = 13;

var loaded=0;
var xvar = -1;
var y = 3;
var first = 1;
var playpause = 'play';
var rotator = window.setInterval("moveContestants()",5000);
rotator = window.clearInterval(rotator);
var str = 'string';




$(document).ready(function() {

	showContestantsMap();	
	
	if($.cookie('DFplaypause') != 'pause') { $.cookie('DFplaypause', 'play', { expires: 180, path: '/' }); playpause = 'play'; play(); }
	else{ playpause = 'pause'; pause(); }
		
	if (typeof sideBarActive!="undefined")
	{
	
	  	$('#liveBar1').animate({ 'height': (liveBar1+14) }, 1000);
	  	$('#liveBar2').animate({ 'height': (liveBar2+14) }, 1000);
	  	$('#liveBar3').animate({ 'height': (liveBar3+14) }, 1000);
	  	$('#liveBar4').animate({ 'height': (liveBar4+14) }, 1000);
	  	$('#liveBar5').animate({ 'height': (liveBar5+14) }, 1000);
	  	$('#liveBar6').animate({ 'height': (liveBar6+14) }, 1000);

	}
	
	$("#contestantsPage a").hover( function() { if(loaded==1){$(this).stop().animate({"opacity": "1"}, "slow");} }, function() { if(loaded==1){$(this).stop().animate({"opacity": ".5"}, "slow"); }}); 
	$("a.mainNavLink").hover( function() { $(this).stop().animate({"opacity": "1"}, 400); }, function() { $(this).stop().animate({"opacity": ".7"}, 400); }); 
	
	$("#rcPause").click(function () { 
		if(playpause == 'play'){
	    	rotator = window.clearInterval(rotator);
	    	
	    	$('#rcPlay').animate({
				'opacity': '.5'
			}, 1000);
			
	    	$('#rcPause').animate({
				'opacity': '1'
			}, 1000);
			
			playpause = 'pause';
			pause();
			$.cookie('DFplaypause', 'pause');
		}
    });
		
	$("#rcPlay").click(function () {
		if(playpause == 'pause'){
	    	rotator = window.setInterval("moveContestants()",5000);
	    	
			
			playpause = 'play';
			play();
			$.cookie('DFplaypause', 'play');
			moveContestants();
		}
    });
		
		
	xvar = Math.floor(Math.random()*6);
	
	$(function () {
	  var img = new Image();
	  
	  // wrap our new image in jQuery, then:
	  $(img)
	    // once the image has loaded, execute this code
	    .load(function () {
	      
	      $(this).hide();
	      $('#contestantNames').hide();
	      $('#contestantMove').append(this);
	     
	      moveContestants();
	      
	      if($.cookie('DFplaypause') == 'play'){
	    	  rotator = window.setInterval("moveContestants()",5000);
	   	  }
	      
	      // set the image hidden by default    
	      
	    
	      // with the holding div #loader, apply:
	      $('#loadingCircle').fadeOut('slow');
	    
	      // fade our image in to create a nice effect
	      $(this).fadeIn();
	    })
	    
	    // if there was an error loading the image, react accordingly
	    .error(function () {
	      // notify the user that the image could not be loaded
	    })
	    
	    // *finally*, set the src attribute of the new image to our image
	    .attr('src', 'data/img/groupPhoto.jpg');
	});
	
	$("#newsletterSubmit").click(function(){
		  var email = $("input#newsletterEmail").val();
		  var dataString = 'email='+ email;
		  //alert (dataString);return false;
		  $.ajax({
		    type: "POST",
		    url: "processForm.php",
		    data: dataString,
		    success: function() {
		      $('#newsletterField').html("You're Signed Up! Thanks!");
		    }
		  });
		  return false;
		  

	});

});

function play(){
		$('#rcPlay').animate({
			'opacity': '1'
		}, 1000);
		$('#rcPause').animate({
			'opacity': '.5'
		}, 1000);

	}

function pause(){
		$('#rcPlay').animate({
			'opacity': '.5'
		}, 1000);
		$('#rcPause').animate({
			'opacity': '1'
		}, 1000);

	}

function moveContestants(){
	
	if(first == 1){

		first = 0;
			
      	$('#contestantMove').css({
			'left': contestants[xvar][0],
			'top': contestants[xvar][1]
		});
		
		$('#contestantMove').rotate({
			angle:contestants[xvar][2]
		});
		
      	$('#contestantNames').css({
			'background-position': 'center -' + contestants[xvar][4] + 'px'
		});
		
      	$('#rcCircle' + xvar).css({
			'opacity': '1'
		});
		
	    $('#contestantNames').fadeIn(800);
	    $('#rotatorShadow').fadeIn(800);
	    $('#rotatorControls').fadeIn(800);
		
	}
	else{
	
		xvar++;
		
		if(xvar==6){
			xvar = 0;
		}

		$('#contestantNames').fadeOut(1000, function(){
		
	      	$('#contestantNames').css({
				'background-position': 'center -' + contestants[xvar][4] + 'px'
			});
						
			$('#contestantNames').fadeIn(1000);
		});
		
		
      	$('#rcPlay').animate({
			'opacity': '1'
		}, 1000);
	
      	$('#rcCircle' + xvar).animate({
			'opacity': '1'
		}, 2000);
		
		if(xvar != 0) { y = xvar - 1; }
		else{ y = 5; }

      	$('#rcCircle' + y).animate({
			'opacity': '.5'
		}, 2000);
	
		$('#contestantMove').animate({
			'left': contestants[xvar][0],
			'top': contestants[xvar][1]
		}, 2000, 'easeInOutCubic');
		
		$('#contestantMove').rotate({
			duration:1000,
			animateTo:contestants[xvar][2]
		});
				
	}

}

function test(){
	$('#contestantMove').animate({
		'left': '0',
		'top': '0'
	}, 400);
	}

function showContestantsMap(){
	var n = 0;
	
	while(n != 6){
		
      	$('#contestantPage' + n).css({
			'left': contestants[n][5] + 75,
			'top': contestants[n][6] + 75
		});
		
		n++;
	}
		
	$('#contestantPage0').show('1', function() { $('#contestantPage0').animate({ 'width': '150', 'height': '150', 'left': '-=75', 'top': '-=75' }, 750, 'easeOutBack')}).delay(Math.floor(Math.random()*250)-1);
	$('#contestantPage1').show('1', function() { $('#contestantPage1').animate({ 'width': '150', 'height': '150', 'left': '-=75', 'top': '-=75' }, 750, 'easeOutBack')}).delay(Math.floor(Math.random()*250)-1);
	$('#contestantPage2').show('1', function() { $('#contestantPage2').animate({ 'width': '150', 'height': '150', 'left': '-=75', 'top': '-=75' }, 750, 'easeOutBack')}).delay(Math.floor(Math.random()*250)-1);
	$('#contestantPage3').show('1', function() { $('#contestantPage3').animate({ 'width': '150', 'height': '150', 'left': '-=75', 'top': '-=75' }, 750, 'easeOutBack')}).delay(Math.floor(Math.random()*250)-1);
	$('#contestantPage4').show('1', function() { $('#contestantPage4').animate({ 'width': '150', 'height': '150', 'left': '-=75', 'top': '-=75' }, 750, 'easeOutBack')}).delay(Math.floor(Math.random()*250)-1);
	$('#contestantPage5').show('1', function() { $('#contestantPage5').animate({ 'width': '150', 'height': '150', 'left': '-=75', 'top': '-=75' }, 750, 'easeOutBack')}).delay(Math.floor(Math.random()*250)-1);
	$('#contestantsOverlay').delay(1000).fadeIn(1000, function() {
        loaded=1;
      });

		
}

function pwdFocus() {
    $('#passwordReplace').hide();
    $('#password').show();
    $('#password').focus();
	
	$('#password').css({'text-align': 'left'});
}

function pwdBlur() {
    if ($('#password').attr('value') == '') {
        $('#password').hide();
        $('#passwordReplace').show();
		
		$('#password').css({'text-align': 'center'});
    }
}

function usernameBlur() {
    if ($('#username').attr('value') == '') {
        $('#username').val("USERNAME");
		
		$('#username').css({'text-align': 'center'});
    }
}

function nameBlur() {
    if ($('#name').attr('value') == '') {
        $('#name').val("NAME (SHOWN)");
		
		$('#name').css({'text-align': 'center'});
    }
}

function emailBlur() {
    if ($('#email').attr('value') == '') {
        $('#email').val("EMAIL (NOT SHOWN)");
		
		$('#email').css({'text-align': 'center'});
    }
}

function commentAreaBlur() {
    if ($('#commentArea').attr('value') == '') {
        $('#commentArea').val("\nCOMMENT");
		
		$('#commentArea').css({'text-align': 'center'});
    }
}

function commentSuccess(){
	
	$('#commentForm span').fadeOut(400);
	$('#commentForm form').fadeOut(400, function(){
		$('#commentSuccess').fadeIn(400);
	});
	

	}
