var Player = {
	LANG:"fr",
	minSWFVersion		:"9.0.28",
	screenPlayerPath	:"/ave-comics/AVEBrowser/externalPlayer.swf",
	avePlayerPath		:"<?php echo file_get_contents('http://player.ave-comics.com/url.php?player=player-ave'); ?>",
	aveID:null,
	
	init:function( swfVersion, avePlayerPath, screenPlayerPath ) {
		Player.aveID = {};
		Player.minSWFVersion = swfVersion;
		Player.avePlayerPath = avePlayerPath;
		Player.screenPlayerPath = screenPlayerPath;
	},
	
	openScreenPlayer:function(aveID) {
		Player.aveID["screen"] = aveID;
		
		Player.closeScreenPlayer();
		var popup=document.createElement("div");
		popup.id = "player-box";
		
		var regParam="";
		if( navigator.userAgent.indexOf( "MSIE" ) >= 0 ) { // ie
			// prevent IE to store SWF in cache --> all external interface handlers are lost if set
			regParam="?reg="+new Date().getTime();
		}
	
		setOpacity( popup, 0 );
		document.body.appendChild(popup);
		// remove main scrollbar
		document.body.style.overflow =  "hidden";
		AVEffect.fade["out"]( popup, function() {
			var ind='<object type="application/x-shockwave-flash" data="'+Player.screenPlayerPath+regParam+'" ';
			ind+='id="externalPlayer" width="100%" height="100%">';
			ind+='<param name="movie" value="'+Player.screenPlayerPath+'" />';
			ind+='<param name="quality" value="high" />';
			ind+='<param name="bgcolor" value="#000000" />';
			ind+='<param name="allowFullScreen" value="true" />';
			ind+='<param name="allowScriptAccess" value="sameDomain" />';
			ind+='<param name="flashVars" value="language='+Player.LANG+'" />';
			ind+='</object>';
			popup.innerHTML=ind;
		});
	},
	
	closeScreenPlayer:function() {
		document.body.style.overflow =  "auto";
		if(document.getElementById("player-box")) {
			var player = document.getElementById("player-box");
			document.body.removeChild(player);
		}
	},

	openAVEPlayer:function(aveID) {
		Player.aveID["avep"] = aveID;				
		// AVE Preview iPhone:
		var avepi={
			bgcolor				:'#c0c5e0',
			wmode				:'transparent',
			allowFullScreen		:'true',
			allowScriptAccess	:'always',
			quality				:'high'
		};
					
		swfobject.embedSWF(
			Player.avePlayerPath,
			'avePlayer','1','1',
			Player.minSWFVersion,
			Player.avePlayerPath,
			false,
			avepi
		);
	}	
};

///////////////////////////
// SCREEN READER JS HANDLER
function playerConnected() {
	if( $("externalPlayer") ) {
		//console.log( "playerConnected" );
		$("externalPlayer").readBook(Player.aveID["screen"],'false','','','','','' );
	}
};
function playerReadyToClose(inPage) {
	Player.closeScreenPlayer();
};

/////////////////////////
// AVE READER JS HANDLER
function setSWFIsReady() {
	//var player = $("player");
	var obj = $("avePlayer");
	if ( obj ) {
		obj.setSkin("http://player.ave-comics.com/player-ave/skins/normalSkin.swf");
		obj.setAveID(Player.aveID["avep"]);
	} // else error
 };
function resizePlayer(pWidth, pHeight, name) {
	if( pWidth == 519 ) return;
	var obj = $("avePlayer");
	var player = $("player");
	var tempZone=$("tempZone");

	if (obj) {
		obj.width = pWidth;
		obj.height = pHeight;
			
		obj.style.height=pHeight+"px";
		obj.style.visibility="visible";

		tempZone.style.height=pHeight+"px";
			
		var offsetLeft=( 595 - pWidth )/2;
		player.style.marginLeft=offsetLeft+"px";	
		player.style.height=pHeight+"px";
		obj.style.zIndex="1";
		
		// contruct the menu
		var menu=$("rotate-iphone");
		var html='<div id="title-test-bd-middle"></div>';;
		html+='<div id="horizontal-iphone"></div>';
		html+='<div id="vertical-iphone"></div>';
		menu.innerHTML=html
		menu.onclick=changeOrientation;
	}
 };
function changeOrientation() {
	var obj = $("avePlayer");
	var player = $("player");
	var imgIphone=$("imgIphone");
	if (obj) {
		try {
			obj.nextDevice();
			window.scrollTo(0, 400);
			imgIphone.style.display="none";
		} catch(e) {
			
		}
	}
};
