//Provides script for the Dejumble Promo View (html5 baby!)

$(function() {
  
  //Handle opt-row click for animation effect
  $('.promo-row').click(function() {;
						if(!$(this).hasClass('selected')) {
						$('.promo-row').removeClass('selected');
						$(this).addClass('selected');
						AnimateArrowPointerToRow(this);
						
						var that = this;
						if($('.promo-right .content.selected').length) {
						$('.promo-right .content.selected').fadeOut('fast', function() {
																	$('.promo-right .content').removeClass('selected');
																	$('.promo-right #'+$(that).attr('id')+'-content.content').fadeIn().addClass('selected');
																	});
						} else {
						$('.promo-right #'+$(that).attr('id')+'-content.content').fadeIn().addClass('selected');
						}
						
						//document.location.hash = $(this).attr('id');
						}
						
						$('#create-play-button a').click(function() {
														 $('#create-content').empty().append('<object class="video" width="510" height="310"><param name="movie" value="http://www.youtube.com/v/5DS11kS8qlA&hl=en_US&fs=1&rel=0&hd=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/5DS11kS8qlA&hl=en_US&fs=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="510" height="310"></embed></object>');
														 });
						
						
						$('#tags-play-button a').click(function() {
													   $('#tags-content').empty().append('<object width="510" height="310"><param name="movie" value="http://www.youtube.com/v/bB4H4c9hgJE&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/bB4H4c9hgJE&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="510" height="310"></embed></object>');
													   });
						
						
						});
  
  //On load drop in the at-arrow
  if(document.location.hash) {
  $('#'+document.location.hash+'.promo-row').click();
  } else {
  $('.promo-row.defualt').click();
  }
  
  
  });

function AnimateArrowPointerToRow(row, callback) {
	$('#at-arrow').animate({top:AtArrowPointForRow(row)}, callback);
}

function AtArrowPointForRow(row) {
	return  $(row).position().top + $(row).outerHeight()/2.0 - $('#at-arrow').outerHeight()/2.0;
}