/**
* jFlashLoader
* Loads the Flex photo player.  
* Note: The full XML path (iGiftXmlPath), width and height are constructed and sent through the getXml.php script.
*
* @author	Ali Shahriyari
**/

// Get guid from url
var guid = "";
var guidIndex = window.location.href.indexOf( "guid=" );
if ( guidIndex >= 0 ) 
    guid = window.location.href.substr( guidIndex + 5 );

// Include all needed files
include( './scripts/getXml.php?guid=' + guid );
include( './scripts/swfobject.js' );
include( './scripts/flash_detect.js' );

// The player
function jPhotoPlayer( redirect )
{
    // Return if a valid iGiftXmlPath is not found
    if ( iGiftXmlPath == null ) return;

    // If flash is installed, load and run the flash player
    if ( FlashDetect.versionAtLeast( 7 ))
    {
        // If width/height is not set then use default width/height
        if ( width == 0 || height == 0 )
        {   
            width = 416;
            height = 320;        
        }
                
        useSWFObject( );
    }
    // Else redirect to mobile page
    else if ( redirect )
        window.location = './viewMobile.html?guid=' + guid;

    // Reloads the flash player
    this.reloadGift = function( ) 
    {
        var old = document.getElementById( "PhotoPlayer" );
        old.removeChild( old.firstChild );
        
        useSWFObject( );
    }
    
    // Embed Flash
    function useSWFObject( )
    {
        var s = new SWFObject( "jPhotoPlayer.swf", "jPhotoPlayer", width, height, "9" );
	    s.addParam( "allowfullscreen", "true" );
	    s.addParam( "allowScriptAccess", "always" );
	    s.addParam( "wmode", "opaque" );
	    s.addVariable( "align", "middle" );
	    s.addVariable( "width", width );
	    s.addVariable( "height", height );
	    s.addVariable( "igift", iGiftXmlPath );
	    s.useExpressInstall( "expressinstall.swf" );
	    s.write( "PhotoPlayer" ); 
    }
}

// Include function
function include( filename ) 
{
    document.write( '<script type="text/javascript" src="' + filename + '"></script>' ); 
}
