window.autoPaused = 0;


//<![CDATA[
$(document).ready(function(){



	// Fix PNG (ie6 / ie5.5 only!)
	jQuery(document).pngFix(); 

	// Init PrettyPhoto
	$("a[rel^='prettyPhoto']").prettyPhoto({
		show_title: false,
		deeplinking: false,
		overlay_gallery: true
	});
	$("a[rel^='prettyVideo']").prettyPhoto({
		show_title: true,
		deeplinking: false,
		overlay_gallery: false,
		slideshow: false,
		callback: function() {
			if(window.autoPaused == 1) {
				$('#jquery_jplayer_1').jPlayer("play");
				window.autoPaused = 0;
			}		
		}
	}).click(function() {
	
		// if playing, pause and set global
		if($('#jquery_jplayer_1').data("jPlayer").status.paused === false) {
			$('#jquery_jplayer_1').jPlayer("pause");
			window.autoPaused = 1;
		}
	});
	
	// open video callback for pausing player
	

	// Init player
	new jPlayerPlaylist({
		jPlayer: "#jquery_jplayer_1",
		cssSelectorAncestor: "#jp_container_1"
	}, [
	
			{
				title:"Moneymaker",
				artist:"Far Too Loud",
				mp3:"/jplayerSkin/moneymaker_-_far_to_loud.mp3"
			},
			{
				title:"I Needed to Go",
				artist:"Cyberpunkers",
				mp3:"/jplayerSkin/i_needed_to_go_-_cyberpunkers.mp3"
			},
			{
				title:"Hold You",
				artist:"Dopamine/Pyramid Rmx",
				mp3:"/jplayerSkin/hold_you_-_dopamine_(pyramid_rennie_pilgrem_remix).mp3"
			},
			{
				title:"I Need (Sample)",
				artist:"LoopsOfFury",
				mp3:"/jplayerSkin/loops_of_fury_-_i_need_128.mp3"
			},
			{
				title:"Scary Monsters",
				artist:"Roc-IT",
				mp3:"/jplayerSkin/Scary Breaks Re-Roc.mp3"
			},
			{
				title:"Hear Dem Style",
				artist:"Far Too Loud",
				mp3:"/jplayerSkin/hear_dem_style_-_far_too_loud.mp3"
			},
			{
				title:"Show Me Love",
				artist:"Roc-IT",
				mp3:"/jplayerSkin/show_me_love_-_roc-it.mp3"
			}
	], {
		swfPath: "/js/",
		supplied: "mp3",
		solution: "flash",
		wmode: "window"
	});

	
	// mlsu click handler
	$('#mlsu-email').focus(function() {
		$(this).css('background', '#fff');
	});
	$('#mlsu-email').blur(function() {
		if(!$(this).val()) {
			$(this).css('background', '#fff url(/img/mlsu-text.jpg) no-repeat 0px 4px');
		}
	});
	$('#mlsu-email').keydown(function(event) {

        if ( event.keyCode == 13 ) {
			event.preventDefault();		
			doMLSU();

        }
	
	});
	
	$('#mlsu-go').click(function() {
		
		doMLSU();
		
	});
	
	// bcarousel slide shows
	// delay init() because webkit is just TOO f'n fast
	setTimeout(function(e){
		bCarousel.init('#slider1', {target:'photoslider'});
		bCarousel.init('#slider2', {target:'videoslider'});	
		
		setTimeout(function(e) {
			// arrow hover glow effect
			$('.forward').each(function() {
				$(this).mouseover(function() {
					$(this).children(':first').attr('src', '/img/right-arrow-over.png');
				});
			});
			$('.forward').each(function() {
				$(this).mouseout(function() {
					$(this).children(':first').attr('src', '/img/right-arrow.png');
				});
			});
			$('.back').each(function() {
				$(this).mouseover(function() {
					$(this).children(':first').attr('src', '/img/left-arrow-over.png');
				});
			});
			$('.back').each(function() {
				$(this).mouseout(function() {
					$(this).children(':first').attr('src', '/img/left-arrow.png');
				});
			});
		}, 300);
		
	}, 300);

	// facebook init
	FB.init({
		appId  : '113682261986330',
		status : true, // check login status
		cookie : true, // enable cookies to allow the server to access the session
		xfbml  : true, // parse XFBML
		channelUrl : 'http://www.dayonechicago.com/fbchannel.php', // channel.html file
		oauth  : true // enable OAuth 2.0
	});		

	fbDoRsvp();
	
	

	
	
});
//]]>


$(document).ready(function() {
	// autostart player
	setTimeout(function() {
		console.log("playing");
		$('#jquery_jplayer_1').jPlayer("play");	
	}, 2000);
});

function doMLSU() {

	var email = $('#mlsu-email').val();
	
	var temp = $('#mlsu').html();

	$('#mlsu').html('<h1 style="color: #fff; margin-top: 60px; margin-bottom: 10px;">PROCESSING</h1><img src="/img/loader.gif" width="126" height="22" alt="Loading" />');
	
	$.post('mlsu.php', {act: 'signup', email: email}, function(data) {
	
		if(data == 0) {
			alert("Error! No valid email address was entered!");
		}
		
		if(data == 1) {
			alert("Error communicating with API. Please try again later.");
		}
		
		if(data == 2) {
			alert("Great! One more step!\n\nYou have to confirm your subscription by clicking a link in the confirmation email that was just sent to you!\n\nThank you for your interest in Day One.");
		}
		
		$('#mlsu').html(temp);
		$('#mlsu-email').val('');
		$('#mlsu-email').css('background', '#fff url(/img/mlsu-text.jpg) no-repeat 0px 4px');
		
		// mlsu click handler
		$('#mlsu-email').focus(function() {
			$(this).css('background', '#fff');
		});
		$('#mlsu-email').blur(function() {
			if(!$(this).val()) {
				$(this).css('background', '#fff url(/img/mlsu-text.jpg) no-repeat 0px 4px');
			}
		});
		$('#mlsu-email').keydown(function(event) {
			if ( event.keyCode == 13 ) {
				event.preventDefault();		
				doMLSU();

			}
		});
		$('#mlsu-go').click(function() {
			doMLSU();
		});		
	});
}


function fbDoAttending() {

	FB.getLoginStatus(function(response) {
		if (response.status === 'connected') {
			FB.api('/310311042344122/attending', 'post', {}, function(response) {
			
				console.log(response);
				$('#fbrsvp').html('');
				$('#fbrsvp').append("<img src=\"/img/attending.jpg\" alt=\"You're Attending!\" height=\"47\" width=\"186\" />");
				$('#fbrsvp').append("<p class=\"elink\"><a href=\"https://www.facebook.com/event.php?eid=310311042344122\" target=\"_blank\">View Event Page</a></p>");
				
			
			});

		}
	});
}

function fbDoRsvp() {

FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
    // the user is logged in and connected to your
    // app, and response.authResponse supplies
    // the user’s ID, a valid access token, a signed
    // request, and the time the access token 
    // and signed request each expire
    var uid = response.authResponse.userID;
    var accessToken = response.authResponse.accessToken;
	
	FB.api(
		{
			method: 'fql.query',
			query: 'select rsvp_status from event_member where eid = "310311042344122" and uid=me()'
		}, function(response) {
			console.log(response[0].rsvp_status);
			if(response[0].rsvp_status === 'attending') {
				$('#fbrsvp').append("<img src=\"/img/attending.jpg\" alt=\"You're Attending!\" height=\"47\" width=\"186\" />");
				$('#fbrsvp').append("<p class=\"elink\"><a href=\"https://www.facebook.com/event.php?eid=310311042344122\" target=\"_blank\">View Event Page</a></p>");
			} else {
				// not attending!
				$('#fbrsvp').append("<p class=\"button\"><input type=\"button\" value=\"\" class=\"attending-button\" onclick=\"fbDoAttending();\" /></p>");
				$('#fbrsvp').append("<p class=\"elink\"><a href=\"https://www.facebook.com/event.php?eid=310311042344122\" target=\"_blank\">View Event Page</a></p>");

			}
		}
	);
	
	
	
  } else {
		$('#fbrsvp').append("<p class=\"button\"><fb:login-button scope=\"rsvp_event\">Connect with us!</fb:login-button></p>");
		$('#fbrsvp').append("<p class=\"elink\"><a href=\"https://www.facebook.com/event.php?eid=310311042344122\" target=\"_blank\">View Event Page</a></p>");
		
		FB.XFBML.parse(document.getElementById('fbrsvp'));

		FB.Event.subscribe('auth.authResponseChange', function(response) {
			if(response.status === 'connected') {
				var uid = response.authResponse.userID;
				var accessToken = response.authResponse.accessToken;				
				FB.api(
					{
						method: 'fql.query',
						query: 'select rsvp_status from event_member where eid = "310311042344122" and uid=me()'
						}, function(response) {
							console.log(response[0].rsvp_status);
							if(response[0].rsvp_status === 'attending') {
								$('#fbrsvp').html('');
								$('#fbrsvp').append("<img src=\"/img/attending.jpg\" alt=\"You're Attending!\" height=\"47\" width=\"186\" />");
								$('#fbrsvp').append("<p class=\"elink\"><a href=\"https://www.facebook.com/event.php?eid=310311042344122\" target=\"_blank\">View Event Page</a></p>");
							} else {
								// not attending!
								$('#fbrsvp').html('');
								$('#fbrsvp').append("<p class=\"button\"><input type=\"button\" value=\"\" class=\"attending-button\" onclick=\"fbDoAttending();\" /></p>");
								$('#fbrsvp').append("<p class=\"elink\"><a href=\"https://www.facebook.com/event.php?eid=310311042344122\" target=\"_blank\">View Event Page</a></p>");

							}
						}
				);				
			
			}
		});

  }
});


}
