var accountId = "accountIdAssigned"; // assigned by Technologo.com
var accessKey = "accesskeyassigned"; // assigned by Technologo.com
//Variables for Custom Covers; some will require changing specific to the vCat
var catalogId = "20091214";					 // assigned by Technologo.com, if Custom cover is used - the unique identifier for the vCat
									 // keep it EMPTY, if Custom cover IS NOT used with this vCAT
var lastPage = 56;					 // this must be changed to reflect the last page of the vCat


/******************* ! ! ! !     A T T E N T I O N      ! ! ! ! ******************/
/******************* DON'T MODIFY INFORMATION BELOW THIS POINT *******************/
/*********************************************************************************/
var currentLogoUploadedId = "";
var siteAddress = "http://www.technologo.com";
var productIdForBackgroundWithLogo = "23633760882475";
var backgroundImageWithNoLogo = "/eodpro/images/eMagBackgroundWithNoLogo.gif";
var fileFolder = "/imagedumpemag";
var backgroundImageLocation_x = -275;
var backgroundImageLocation_y = 100;
var emailFrom = "";

// ************* CUSTOM COVER SECTION *****************
// *************       SECTION 1      *****************
//Variables for Custom Covers; some will require changing specific to the vCat
var isCustomCoverAllowed = false;
if (catalogId!=null && catalogId.length > 0) {
	isCustomCoverAllowed = true;
}
var LMObj = {}; // one of these is needed for each image to be inserted into the vCat
var LMObj2 = {};
var fileFolderCustomCover = "/imagedumpvcat";
var coverId = "";

//Assigning initial values to the custom cover variables
LMObj.type = 'shape';
LMObj.stype = 'rect';
LMObj.oX = 0;
LMObj.oY = 0;
LMObj.oW = 100;
LMObj.oH = 100;
LMObj.depth = 200;
LMObj.color = 0xFFFFFF;
LMObj.alpha = 0;
LMObj.rotation = 0;

LMObj2.type = 'shape';
LMObj2.stype = 'rect';
LMObj2.oX = 0;
LMObj2.oY = 0;
LMObj2.oW = 100;
LMObj2.oH = 100;
LMObj2.depth = 200;
LMObj2.color = 0xFFFFFF;
LMObj2.alpha = 0;
LMObj2.rotation = 0;
// ************* CUSTOM COVER SECTION *****************
// END *********       SECTION 1      *****************


//Creating a custom namespace to avoid conflict with other scripts
var _myAPI = {};

//Creating a reference to the API class instance
_myAPI._api = Api_07f1b8e003dc6dec7d06fa5fbd2308a6;

//Allow or disallow debugging using the FireBug console
//_myAPI._debug = true;

//Check for logoId in url
checkCurrentLogoInURL = function(evt){
	var logoId =  decodeURI(_myAPI._api.getQueryString('logoId'));
	if (logoId.length > 0 && logoId!="null"){
		currentLogoUploadedId = logoId;
	}
	//set cookie for TH
	_myAPI._api.sendData(siteAddress+"/EODProManager?action=addLogoToCookie&ver=emag&logoIdNew="+currentLogoUploadedId+"&accesskey="+accessKey, "POST", "");
}

//update background image after eMag opening if needed
updateBackgroundImage = function(evt){
	if (screen.width<1280 && screen.height<1024){
		backgroundImageLocation_x = -180;
		backgroundImageLocation_y = 90;
	}
//	if(currentLogoUploadedId!=null && currentLogoUploadedId.length > 0){
//		_myAPI._api.setBackgroundImage(siteAddress+"/OneClick.OneClick?fwid="+productIdForBackgroundWithLogo+"&clickpath="+currentLogoUploadedId+"&width=229&height=375&fixed=false&ver=emag&accesskey="+accessKey, "Align", "center", "center", backgroundImageLocation_y, backgroundImageLocation_x);
//	}else{
//		_myAPI._api.setBackgroundImage(siteAddress+backgroundImageWithNoLogo, "Align", "center", "center", backgroundImageLocation_y, backgroundImageLocation_x);
//	}
}

//will be used if standard eMag Send button used
//for custom Send button - will peform JS parse for these parameters before sending in an appropriate method
//add logoId, cov parameters to link for email
addParametersToLinkForEmail = function(evt){
	//which Button is pressed?
	if (evt.menuType=="icon" && evt.buttonType=="send_ToFriendButton") {
		//add logoId and other parameters to a link
		if (isCustomCoverAllowed) {
			//add logoId, cov parameters
			_myAPI._api.addSendToFriendQuery({logoId:(currentLogoUploadedId!=null && currentLogoUploadedId.length > 0)?currentLogoUploadedId:"", coverId:coverId});
		}else{
			//add logoId only
			_myAPI._api.addSendToFriendQuery({logoId:(currentLogoUploadedId!=null && currentLogoUploadedId.length > 0)?currentLogoUploadedId:""});
		}
	}
}

//Loads policy files for the remote domains that we will be accessing
loadPolicys = function(){
	_myAPI._api.loadPolicyFile(siteAddress + "/crossdomain.xml");
}


// ************* CUSTOM COVER SECTION *****************
// *************       SECTION 2      *****************
_myAPI._getCovers = function(evt) {
	//this always returns some string value; string "null" if the parameter is empty
	var tempCoverId = decodeURI(_myAPI._api.getQueryString('coverId'));
	if (tempCoverId.length == 0 || tempCoverId=="null"){
		isCustomCoverAllowed = false;
		return false;
	}
	coverId = tempCoverId;

	//Adding the content object using dot notation
	LMObj.content = {};
	LMObj.content.type = 'img_ext';
	LMObj.content.data = {};
	LMObj.content.data.url = siteAddress + fileFolderCustomCover + '/' + catalogId + '/' + coverId + '.jpg';
	LMObj.content.data.smooth = true;
                
	LMObj2.content = {};
	LMObj2.content.type = 'img_ext';
	LMObj2.content.data = {};
	LMObj2.content.data.url = siteAddress + fileFolderCustomCover + '/' + catalogId + '/' + coverId + 'b.jpg';
	LMObj2.content.data.smooth = true;

	//Adding the LMObj to a page in the eMag
	_myAPI._api.addLMObj(1, LMObj);
	_myAPI._api.addLMObj(lastPage, LMObj2);
}

_myAPI._zoomIn = function(evt) {
	if (isCustomCoverAllowed) {
		//Adding the content object using dot notation
		LMObj.content.data.url = siteAddress + fileFolderCustomCover + '/' + catalogId + '/z' + coverId + '.jpg';
		LMObj2.content.data.url = siteAddress + fileFolderCustomCover + '/' + catalogId + '/z' + coverId + 'b.jpg';
		//Adding the LMObj to a page in the eMag
		_myAPI._api.addLMObj(1, LMObj);
		_myAPI._api.addLMObj(lastPage, LMObj2);
	}
}

_myAPI._removeZoom = function(evt) {
	if (isCustomCoverAllowed) {
		LMObj.content.data.url = siteAddress + fileFolderCustomCover + '/' + catalogId + '/' + coverId + '.jpg';
		LMObj2.content.data.url = siteAddress + fileFolderCustomCover + '/' + catalogId + '/' + coverId + 'b.jpg';
		//Adding the LMObj to a page in the eMag
		_myAPI._api.addLMObj(1, LMObj);
		_myAPI._api.addLMObj(lastPage, LMObj2);
	}
}
// ************* CUSTOM COVER SECTION *****************
// END *********       SECTION 2      *****************

//Add an event listener to the api that loads permissions for remote domains
_myAPI._api.addEventListener('onEmagInit', loadPolicys);
_myAPI._api.addEventListener('onEmagReady', checkCurrentLogoInURL);

//for Custom Cover
if (isCustomCoverAllowed) {
	_myAPI._api.addEventListener('onEmagReady', _myAPI._getCovers);
}
//use a separated block, because previous line can change the value of isCustomCoverAllowed
//however these functions have the same condition statement withing a body as well
if (isCustomCoverAllowed) {
	_myAPI._api.addEventListener('onZoom', _myAPI._zoomIn);
	_myAPI._api.addEventListener('onZoomOut', _myAPI._removeZoom);
}
//END for Custom Cover

//update background image if necessary
_myAPI._api.addEventListener('onEmagLoaded', updateBackgroundImage);
_myAPI._api.addEventListener('onMenuClick', addParametersToLinkForEmail);