PublishPaper = {
	init: function() {
		var platforms = this.platforms,
		    ln = platforms.length,
		    i, platform;
		
		var ppNavigator = navigator || window.navigator;
		
		for (i = 0; i < ln; i++) {
		    platform = platforms[i];
		    this[platform.identity] = platform.regex.test(ppNavigator[platform.property]);
		}
		
		this.Desktop = this.Mac || this.Windows || (this.Linux && !this.Android);

		this.Tablet = this.iPad;

		this.Phone = !this.Desktop && !this.Tablet;

		this.iOS = this.iPhone || this.iPad || this.iPod;
		
		this.Standalone = !!window.navigator.standalone;
	},
	
	platforms: [
	    {
	        property: 'platform',
	        regex: /iPhone/i,
	        identity: 'iPhone'
	    },
	    {
	        property: 'platform',
	        regex: /iPod/i,
	        identity: 'iPod'
	    },
	    {
	        property: 'userAgent',
	        regex: /iPad/i,
	        identity: 'iPad'
	    },
	    {
	        property: 'userAgent',
	        regex: /Blackberry/i,
	        identity: 'Blackberry'
	    },
	    {
	        property: 'userAgent',
	        regex: /Android/i,
	        identity: 'Android'
	    },
	    {
	        property: 'platform',
	        regex: /Mac/i,
	        identity: 'Mac'
	    },
	    {
	        property: 'platform',
	        regex: /Win/i,
	        identity: 'Windows'
	    },
	    {
	        property: 'platform',
	        regex: /Linux/i,
	        identity: 'Linux'
	    }]
};

PublishPaper.init();

// ---------------------------------------------------------------- Paramètres généraux

PublishPaper.getURLParam = function(strParamName)
{
    var strReturn = "";
    var strHref = window.location.href;
    if ( strHref.indexOf("?") > -1 )
    {
        var strQueryString = strHref.substr(strHref.indexOf("?"));
        var aQueryString = strQueryString.split("&");
        for ( var iParam = 0; iParam < aQueryString.length; iParam++ )
        {
            if (aQueryString[iParam].indexOf(strParamName + "=") > -1 )
            {
                var aParam = aQueryString[iParam].split("=");
                strReturn = aParam[1];
                break;
            }
        }
    }
	
    return unescape(strReturn);
	
};



PublishPaper.PBStats = function( EventName, IDCatalog, Page, IDZoom )
{
    switch(EventName) {
        case 'Ready':
            // Ouverture du catalogue
            break;
        case 'CurrentPage':
            // Ouverture d'une page
            break;
        case 'ZoneClick':
            // Clic sur une zone active
            break;
        case "ZoomIn":
            // Zoom sur la page
            break;
        default:
            // au cas où
            break;
    }
};



PublishPaper.flashvars = {
		CATALOG_ID:PublishPaper.getURLParam( "CATALOG_ID" ),
		ZOOM:PublishPaper.getURLParam( "VIEW" ),
		PAGE:PublishPaper.getURLParam( "NUM_PAGE" ),
		appLink: ( PublishPaper.getURLParam( "CONFIG" ) == "" ) ? "files/" : PublishPaper.getURLParam( "CONFIG" ),
		color: ( PublishPaper.getURLParam( "COLOR" ) == "" ) ? "0x000000" : PublishPaper.getURLParam( "COLOR" ),
		files: ( PublishPaper.getURLParam( "FILES" ) == "" ) ? "" : PublishPaper.getURLParam( "FILES" ),
		preview: ( PublishPaper.getURLParam( "PREVIEW" ) == "" ) ? "false" : PublishPaper.getURLParam( "PREVIEW" )
	};
	
	
	
PublishPaper.params = {
		menu: "true",
		scale: "noScale",
		quality: "high",
		allowFullScreen: "true",
		allowScriptAccess: "sameDomain",
		play: "true",
		loop: "false",
		wmode: "transparent",
		bgcolor:"0x000000"
	};
	
	
PublishPaper.detection = {
		version: "9.0.45",
		path: "files/html/swf/expressInstall.swf"
	};

	
PublishPaper.getVars = function() {
		fv = "";
		for(var l in this.flashvars){
			if(this.flashvars[l]!=Object.prototype[l]){
				if(fv != ""){
					fv+="&"+l+"="+this.flashvars[l];
				}else{
					fv="?"+l+"="+this.flashvars[l];
				}
			}
		}
		return fv;
	};

// ---------------------------------------------------------------- Intégration de PublishPaper

PublishPaper.embed = function( swfPath, width , height , div ){
		var att = {
			styleclass: "flashOutline"
		};
		
		swfobject.embedSWF( swfPath+this.getVars() , div , width , height , this.detection.version , this.detection.path , null , this.params, att );
	};

