PTV.namespace("ajax");

PTV.ajax.CrossDomainAjax = function (crossDomainFrameName, domain, path, usingCallback, asyncronous) {
	this.crossDomainFrameName = crossDomainFrameName;
	this.domain = domain;
	this.path = path;
	this.usingCallback = usingCallback;
	this.asyncronous = asyncronous;
	this.crossDomainFrame;
	
	this.useCrossDomainFunction = function() {
	  this.crossDomainFrame = window.frames[this.crossDomainFrameName];
	  
	  try {
	    if (this.domain != ""
    		  && this.crossDomainFrame != undefined 
	    	  && this.crossDomainFrame.getContentWithHandler
	    	  && this.crossDomainFrame.getContentCallback
	    	  && navigator.appName != 'Opera') {
	      return true;
	    }
	  } catch (e) {;}
	  
	  return false;
  }
		
	this.getContent = function(renderHandler, errorHandler) {
		var props = {
				url: this.domain + this.path,
				type: 'GET',
				cache: false,
				dataType: "xml",
				success: renderHandler,
				error: errorHandler,
				async: this.asyncronous
		};
		
		if (this.useCrossDomainFunction()) {
			try {
		  	if (this.usingCallback) {
		  		this.crossDomainFrame.getContentCallback(props);
		  	} else {
		  		this.crossDomainFrame.getContentWithHandler(props);
		  	}
		  } catch (e) {
		  	props.url = this.path;
			  this.getNonCrossDomainContent(props);
		  }
		} else {
			props.url = this.path;
			this.getNonCrossDomainContent(props);
		}
  }

	this.getNonCrossDomainContent = function(props) {
	  try {
		  $.ajax(props);
	  } catch (e) {;}
	}
}
