jQuery.noConflict();
$j = jQuery;
$j().ready(
  function()
  {
    //httpsRedirect();
        
    // add the swf slideshow where appropriate
    if( $j('#slideshow-container').length ){
      var flashvars  = {};
      var params     = { wmode:'transparent' };
      var attributes = {};
	  $j('#slideshow-container').attr('src',''); // ie6 wants to show the image under the swf
      swfobject.embedSWF( '/_swf/slideshow.swf', 'slideshow-container', '348', '293', "9.0.115", "/_swf/expressInstall.swf", flashvars, params, attributes );
    }
    
    // add a tooltip message to the satisfaction guaranteed icon where available

    if( $j('.satisfaction-guarantee').length ){
      if( typeof( $j().tooltip ) != 'function' ) $j('body').append('<scr'+'ipt type="text/javascript" src="/_js/jquery.tooltip.min.js"></scr'+'ipt>');
      var msg = "<strong>100% Satisfaction Guarantee.</strong><br/>Cancel your membership by email or phone during the first 14 days and we will refund your money. This offer is only valid for new members.";
      $j('.satisfaction-guarantee').each(
        function()
        {
          $j(this).attr('title', msg );
          $j(this).tooltip({
          	track: true,
          	delay: 0,
          	showURL: false,
          	showBody: " - ",
            extraClass: "info",
          	fade: 250
          });
        }
      )
    }

	  // add rounded corner support to IE
    if( $j.browser.msie ) hackRoundedCorners();
    
  }
);


//---------------------------------------------------------------------
//  preload images
//---------------------------------------------------------------------
$j.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    $j("<img>").attr("src", arguments[i]);
  }
}
var imgs = [];
$j( 'img' ).each( 
  function()
  {
    imgs.push( this.src );
  }
);
$j.preloadImages( imgs.join('","') );


//---------------------------------------------------------------------
//  remove the border, add the extra markup (and remove the margin from the first h3)
//---------------------------------------------------------------------
function hackRoundedCorners()
{  
  // first stretch the left column
  $j( '.green-ltgreen .inner' ).height( $j( '.curriculum' ).height() );  
  $j( window ).resize(
    function()
    {
      $j( '.green-ltgreen .inner' ).height(0);
      $j( '.green-ltgreen .inner' ).height( $j( '.curriculum' ).height() );
    }
  );

  $j( '.curriculum h3' ).eq(0).css({marginTop:0});
  // rounded corners for IE7 and up only
  if( $j.browser.msie && $j.browser.version > 6 ){
    $j( '.rounded' ).each(
      function()
      {
        var $this = $j(this);
        $this.css({border:0,backgroundColor:'transparent'}).find('.inner').wrap( '<div class="l"><div class="r"><div class="t"><div class="tr"><div class="b"><div class="br"></div></div></div></div></div></div>' );
      }
    );
  }
}


//---------------------------------------------------------------------
//  redirect out of https if necessary
//---------------------------------------------------------------------
function httpsRedirect()
{  
  var secured_pages = [ '' ]; // just an example
  
  var aurl    = window.location.href.split('/');
  var file    = aurl[aurl.length-1];
  var afile   = file.split('?');
  file        = afile[0];
  if( aurl[0] == 'https:' && secured_pages.indexOf( file )<0 ){
    aurl[0] = 'http:';
    window.location = aurl.join('/');
  }
}


//---------------------------------------------------------------------
// IE6/7 doesn't have an Array.indexOf property so add it if it doesn't exist.
//---------------------------------------------------------------------
if( !Array.prototype.indexOf ){
  Array.prototype.indexOf = function( obj, from )
  {
    from = ( from == null ) ? 0 : Math.max( 0, this.length + from );
    for( var i = from, j = this.length; i < j; i++ ) if (this[i] === obj) return i;
    return -1;
  };
}

