function refreshShortList(){
	//Fake URL to force a reload of the shortlist 
	$j.ajax({
		type: "GET",
		url:  AppBaseURL + '/wa/Refresh/refresh?addShortlist=xxx',
		success: function(msg){
			$j('#shortlist').replaceWith(msg);	
			
		}
 	});		
 	
}

function checkShortlistPosition(shortlistTop) {
	// what the y position of the scroll is
	var y = $j(this).scrollTop();
	shortlistTop = shortlistTop;
	
	// whether that's below the form
	if (y >= shortlistTop) {
	  // if so, ad the fixed class
	  $j('#shortListWrapper').addClass('fixed');
	} else {
	  // otherwise remove it
	  //alert("removed");
	  $j('#shortListWrapper').removeClass('fixed');
	}
}

function elementInViewport(el) {
  var top = el.offsetTop;
  var left = el.offsetLeft;
  var width = el.offsetWidth;
  var height = el.offsetHeight;

  while(el.offsetParent) {
    el = el.offsetParent;
    top += el.offsetTop;
    left += el.offsetLeft;
  }

  return (
    top >= window.pageYOffset &&
    left >= window.pageXOffset &&
    (top + height) <= (window.pageYOffset + window.innerHeight) &&
    (left + width) <= (window.pageXOffset + window.innerWidth)
  );
}

$j(document).ready(function() {
	
	$j('p.focus-list-line').nextAll().remove();
	$j('p.focus-list-line').remove();
	
	$j('#ListPage .description').remove();
	
	$j("#site_toolbar p:empty, #site_toolbar br").remove();
	
	/*if ($j("#page5670").length > 0) { 
	

	}*/
		
	/* Check if we are on the Buy Tickets page, if so display the most current contents of the shortlist */
	if ($j("#page5673").length > 0) { 	
		$j("#page5673 .webnodecontent p:empty, #page5673 .webnodecontent br").remove();
		
		var shortlistTop = $j('#shortListWrapper').offset().top - parseFloat($j('#shortListWrapper').css('marginTop').replace(/auto/, 0));

		$j(window).scroll(function (event) {
			checkShortlistPosition(shortlistTop);
			
		});
		
		refreshShortList();
	}
	
		 
	
	$j(".conf_session").tsort(".class_time_raw",{order:"asc"});
	
	/*$j.autopager({
		content: '.post-collapse',
		appendTo: '.post-collapse',
		start: function(current, next) {
			$j(".conf_session").tsort(".class_time_raw",{order:"asc"});
			alert("!!");
		}
	});*/

	$j(".search_day").text($j(".search_day").text().replace(/[^a-zA-Z 0-9]+/g,''));

	$j(".more-results").click(function() {
		$j(".conf_session").tsort(".class_time_raw",{order:"asc"});
	});
	
	$j('.nyromodal_noanim').nyroModal({		
		showLoading: function(elts, settings, callback) {
			callback();
		},
		showContent: function(elts, settings, callback) {
			elts.contentWrapper
				.css({
					width: settings.width+'px',
					height: settings.height+'px',
					marginTop: settings.marginTop+'px',
					marginLeft: settings.marginLeft+'px'
				})
				.show();
				elts.loading.fadeOut(200, callback);
		},
		hideContent: function(elts, settings, callback) {
			elts.contentWrapper.hide();
			callback();
		}
	});

	

	
});
