tryReady = function(time_elapsed) {
  // Continually polls to see if jQuery is loaded.
  if (typeof $ == "undefined") { 
    if (time_elapsed <= 5000) { 
      setTimeout("tryReady(" + (time_elapsed + 200) + ")", 200); // set a timer to check again in 200 ms.
    } else {
      alert("Timed out while loading jQuery.")
    }
  } else {
  	
  	// hover phones
	$(document).ready(function() {

		// internal carousel
			function mycarousel_initCallback(carousel) {
			    jQuery('#teaser-controls a').bind('click', function() {
			        rel = jQuery(this).attr('rel');
			        jQuery('.rotator').data('jcarousel').scroll(jQuery.jcarousel.intval(rel));
			        
			        return false;
			    });
		
			};
			function itemVisibleIn(carousel, li, index, state)
			{
				rel = $(li).attr('id');
				$('#c'+rel).addClass('active');
			}
			
			function itemVisibleOut(carousel, li, index, state)
			{
				rel = $(li).attr('id');
				$('#c'+rel).removeClass('active');
			}
			
			// Ride the carousel...
			jQuery(document).ready(function() {
			    jQuery('.rotator').jcarousel({
			        scroll: 1,
			        auto: 6,
			        initCallback: mycarousel_initCallback,
			        wrap: 'last',
			        // This tells jCarousel NOT to autobuild prev/next buttons

			        buttonNextHTML: null,
			        buttonPrevHTML: null,

        			itemVisibleInCallback: itemVisibleIn,
        			itemVisibleOutCallback: itemVisibleOut
			    });
			    
			});

	});


  }
}

tryReady(0);
