var postCommentObject	= null;

function PostCommentObj (  ) {
	var self = this;
	
	this.postObject 		= new PostObject (  );
	this.commentObject 		= new CommentObject (  );
	this.streamObject 		= new StreamObject (  );
	this.streamShareObject 	= new StreamShareObject (  );
	this.streamInviteObject = new StreamInviteObject (  );
	this.streamInviteSingleObject = new StreamInviteSingleObject (  );
	this.streamSetStatusObject = new StreamSetStatusObject (  );
	
	this.contentCountryCode = $("#countryCode").val (  );
	this.countryCode 		= $("#countryCode").val (  );
	this.urlCountryCode		= null;
	this.campaignUrl 		= "http://campaign.sloggi.com/iv/";
	
	// alert ( this.countryCode );
	
	this.cmsData			= new Object (  );
	
	this.searchType_only_friends 	= false;
	this.searchType_only_own 		= false;
	this.searchType_all 			= true;
	
	this.RESIZE_TIMEOUT_ID 	= null;
	
	this.TMP_TIMEOUT_ID		= null;
	this.CMS_DATA_READY = false;
	
	FB.Canvas.setAutoResize();
};

PostCommentObj.prototype = {
	init : function (  ) {
		var self = this;
		
		self.postObject.init (  );
		self.commentObject.init (  );
		
		self.getCmsContent (  );
		self.getCountryCode ( "website_url" );
	},
	resizeContentBox : function (  ) {
		var self = this;
		
		FB.Canvas.setAutoResize();
	
		this.RESIZE_TIMEOUT_ID = setTimeout ( function (  ) {
			FB.Canvas.setAutoResize(false);
			clearTimeout ( self.RESIZE_TIMEOUT_ID );
		}, 1000 );
	},
	getScreenSizeNotice : function ( callback ) {
		var self = this;
		
		if ( postCommentObject.CMS_DATA_READY ) {
			if ( postCommentObject.TMP_TIMEOUT_ID ) {
				clearTimeout ( postCommentObject.TMP_TIMEOUT_ID );
			};
			
			if ( callback ) {
				callback ( postCommentObject.cmsData.texts_basic[18] );
			}
			return false;
		} else {
			postCommentObject.TMP_TIMEOUT_ID = setTimeout ( function (  ) {
				clearTimeout ( postCommentObject.TMP_TIMEOUT_ID );
				postCommentObject.getScreenSizeNotice ( callback );
			}, 100 );	
		}
		
		return false;
	},
	setHandler : function (  ) {
		var self = this;
		
		self.postObject.setHandler (  );
		self.commentObject.setHandler (  );
	},
	setCountryCode : function ( countryCode ) {
		this.countryCode = countryCode;
	},
	getCountryCodeApplication : function (  ) {
		return this.countryCode;
	},
	setContentCountryCode : function ( countryCode ) {
		this.contentCountryCode = countryCode;
	},
	createJsonObjectFBData : function (  ) {
		var self = this;
		
		self.postObject.createJsonObjectFBData (  );
		self.commentObject.createJsonObjectFBData (  );
	},
	getCmsContent : function (  ) {
		var self = this;
		
		ajaxObject.doAjax ( {
			type			: "POST",
			url				: self.campaignUrl + "fb_gateway.php",
			dataType		: "json",
			data			: {
				action		: "GET_CMS_CONTENT",
				countryCode : self.countryCode
			},
			callBackFunc	: postCommentObject.ajaxCallBack
		} );
	},
	getCountryCode : function ( _type ) {
		var self = this;
		
		ajaxObject.doAjax ( {
			type			: "POST",
			url				: self.campaignUrl + "fb_gateway.php",
			dataType		: "json",
			data			: {
				action		: "GET_COUNTRY_CODE",
				countryCode 		: self.countryCode,
				COUNTRY_CODE_TYPE 	: _type
			},
			callBackFunc	: postCommentObject.ajaxCallBackCountryCode
		} );
	},
	ajaxCallBack : function ( data ) {
		for ( var i in data.cmsData ) {
			var tmpArray = new Array (  );
			
			for ( var ii in data.cmsData[i] ) {
				tmpArray.push ( data.cmsData[i][ii] );
			};
			
			postCommentObject.cmsData[i] = tmpArray;
		}
		
		postCommentObject.CMS_DATA_READY = true;
	},
	ajaxCallBackCountryCode : function ( data ) {
		if ( data && data.countryCode != "" ) {
			postCommentObject.urlCountryCode = data.countryCode;	
		}
	}
};
