// SCORM 1.2 Interface Code

var findAPITries = 0;
var scormAPI = null;

function findAPI( win )
{

    // Check to see if the window (win) contains the API
    // if the window (win) does not contain the API and
    // the window (win) has a parent window and the parent window  
    // is not the same as the window (win)
    while ( (win.API == null) && 
            (win.parent != null) && 
            (win.parent != win) )
    {	
        // increment the number of findAPITries
        findAPITries++;

        // Note: 7 is an arbitrary number, but should be more than sufficient
        if (findAPITries > 7) 
        {
            alert( "Error finding SCORM API -- too deeply nested." );
            return null;
        }
      
        // set the variable that represents the window being 
        // being searched to be the parent of the current window
        // then search for the API again
        if ( win.opener != null )
		{
			win = win.opener;
		}
		else
		{
            win = win.parent;
		}
   }
   
   return win.API;

}

function getAPI()
{

    // start by looking for the API in the current window
    var theAPI = findAPI( window );

    // if the API is null (could not be found in the current window)
    // and the current window has an opener window
    if ( (theAPI == null) && 
        ( window.opener != null ) && 
        ( typeof( window.opener ) != "undefined") )
    {
        // try to find the API in the current windowÍs opener
        theAPI = findAPI( window.opener );
    }

    // if the API has not been found
    if ( theAPI == null )
    {
        // Alert the user that the API Adapter could not be found
        alert( "The course cannot connect to the tracking system that records your progress and score therefore please note that no scores will be tracked." );
    }
    
    return theAPI;
    
}


  
            