﻿/* 20123101-1035 */
/* 
* Friendly Iframe Library version 0.3 
* @date 30/11/2011
* @author Jaydson Gomes
* @email jaydson.gomes@corp.terra.com.br
*/
(function(doc){
	/* FiF Global Object - Represents a Friendly Iframe API */
	var FiF = {

		/* Default settings */
		core : {
			settings : {
				'placeholder'				: '',
				'fifsrc'						: 'iframe.html',
				'adsrc'							: null,
				'adcode'						: null,
				'width'							: '',
				'height'						: '',
				'exp_width'					: '',
				'exp_height'				: '',
				'expandable'				: false,
				'rectangle'					: false,
				'expandFunction'		: false,
				'contractFunction'	: false,
				'extra'							: false,
				'callback'					: function(){}
			},
		
			/* Build the Friendly Iframe */
			buildFiF : function(config){
				// Merge default settings with new settings
				var settings = FiF.core.settings = FiF.core.mergeObj(FiF.core.settings,config),				
					fif = null,

					// Reference to document
					d = doc;

				/* If the ad code is provided */
				if(settings.adcode){
					// fifBody is a Friendly Iframe template
					var fifBody = '<!DOCTYPE html><html><body style="background-color:transparent;" id="FiF_container"><script>'+settings.adcode+'</script></body></html>',
						fifId = 'fif_'+settings.placeholder,
						idoc,
						idocContent,
						// iframeModel is the HTML template to append to document
						iframeModel = '<iframe id="'+fifId+'" style="width:100%;height:100%;border:none" vspace="0" hspace="0" allowtransparency="true" scrolling="no" frameborder="no" marginwidth="0" marginheight="0"></iframe>';

					try{
						// Get the Friendly Iframe placeholder, that is where will be placed
						var fifElement = d.getElementById(settings.placeholder);

						// We need to use innerHTML instead appendChild for some Internet Explorer issues
						fifElement.innerHTML = iframeModel;

						// Execute a callback function after insert HTML Iframe code to the document
						if(typeof(settings.callback) === 'function'){
							settings.callback();
						}
					}catch(error){
						FiF.core.debug.errors.push({'HumanReadable':'Error appendind Iframe in placeholder','error':error});
					}

					// Get Friendly Iframe object reference
					fif = document.getElementById(fifId);
					
					/*
					/ Here is where the magic of Friendly Iframe happens
					/ We open the Friendly Iframe document, then write dinamicaly inside
					/ The content is defined in fifBody variable, that is a Iframe model
					*/
					// Get a content window of a Friendly Iframe
					idocContent = fif.contentWindow.document;

					// Open the Friendly Iframe document
					idocContent.open();

					// Write inside the Friendly Iframe document
					idocContent.write(fifBody);

				/* If the ad src is provided */
				}else if(settings.adsrc){
					/* Trick:
					*  We need to create the iframe in this way(with a string and innerHTML stuff),because firefox reload the flash content inside an iframe
					*  if we change the position dinamicaly to absolute - Fu**ing odd!
					*/
					var fifHTML = '<iframe id="fif_'+settings.placeholder+'" style="position:absolute" vspace="0" hspace="0" allowtransparency="true" scrolling="no" frameborder="no"></iframe>',

					// Get the Friendly Iframe placeholder
					ph = d.getElementById(settings.placeholder);
				
					// Parse fifHTML string into placeholder
					if(ph){
						ph.innerHTML = fifHTML;
						
						// Now, get a friendly iframe object
						fif = d.getElementById('fif_'+settings.placeholder);
						
						// And some styles (waiting for HTML5 seamless feature)
						try{
							fif.style.width =  settings.width + "px";
							fif.style.height =  settings.height + "px";
							fif.style.borderWidth = "0px";
							fif.style.padding = "0px";	
						}catch(e){}

						/* 
						* This is a trick! create a fif_src attribute, that is the javascript file ad(that one that return the evil document.write)
						* This attribute will be used to dinamicaly change the iframe src
						*/
						fif.fif_src = settings.adsrc;
						fif.area_name = settings.adname;
						FiF.core._addEvent(fif,'load',function(){
							if(typeof fif.contentWindow[settings.contractFunction] == 'function'){
								var oldContractFunction = fif.contentWindow[settings.contractFunction];
							}
							fif.contentWindow[settings.contractFunction] = function(){
								if(fif.contentWindow.isOpenedAd){
									setTimeout(function(){
										if(settings.rectangle){
											fif.style.marginLeft = '0px';
										}
										fif.style.height = settings.height + 'px';
										fif.style.width = settings.width + 'px';
										fif.contentWindow.isOpenedAd = false;
									},1000);								
								}
							};
							if(oldContractFunction){
								oldContractFunction();
							}

							if(settings.extra){
								fif.contentWindow.document.body.style.styleFloat = 'left';
								fif.contentWindow.document.body.style.cssFloat = 'left';
							}
							// Execute the callback function when the iframe is loaded
							if(settings.callback){
								settings.callback();
							}						
						});

						// Then apply the source (this is a html page in the same domain)...
						fif.src = settings.fifsrc;
					}

				/* Well.. neither src and code were provided... */
				}else{
					FiF.core.debug.errors.push('Neither src or code for ad were provided. Fix that! I do not do magic!');
				}

				/* Expandable */
				if(fif){
					if(settings.expandable){
						fif.contentWindow.isOpenedAd = false;
						fif.style.position = 'absolute';
						fif.style.zIndex = '99999';
						
						/* Just for rectangles ads */
						if(settings.rectangle){
							if(settings.exp_width !== '' || settings.exp_height !== ''){
			
								FiF.core._addEvent(fif,'load',function(){
									var placeholder = d.getElementById(settings.placeholder),
											container = fif.contentWindow.document.getElementById('FiF_container');
									
									placeholder.style.overflow = 'visible';
									container.style.styleFloat = 'right';
									container.style.cssFloat = 'right';
									
									fif.style.zIndex = '996';									

									if(typeof fif.contentWindow[settings.expandFunction] == 'function'){
										var oldBoxExpand = fif.contentWindow[settings.expandFunction];
									}
									fif.contentWindow[settings.expandFunction] = function(){
										fif.style.position = 'absolute';
										fif.style.marginLeft = '-' + (settings.exp_width - settings.width) + 'px';
										fif.style.width = settings.exp_width + 'px';
										fif.style.height = settings.exp_height + 'px';
										fif.contentWindow.isOpenedAd = true;
									}
									if(oldBoxExpand){
										oldBoxExpand();
									}
								});
							}
						}else{
							if(settings.exp_width !== '' || settings.exp_height !== ''){
								FiF.core._addEvent(fif,'mouseover',function(){
									if(typeof fif.contentWindow[settings.expandFunction] == 'function'){
										fif.style.width = settings.exp_width + 'px';
										fif.style.height = settings.exp_height + 'px';
										fif.contentWindow.isOpenedAd = true;
									}
								});
								FiF.core._addEvent(fif,'mouseout',function(){
									fif.style.width = settings.width + 'px';
									fif.style.height = settings.height + 'px';
								});
							}
						}						
					}
				}
			},

			/*
			Add & Remove event by John Resig 
			http://ejohn.org/projects/flexible-javascript-events/
			*/
			_addEvent : function(obj,type,fn){
				if(obj.attachEvent){
					obj['e'+type+fn] = fn;
					obj[type+fn] = function(){
						try{
							if(obj && type && fn){
								obj['e'+type+fn](window.event);		
							}							
						}catch(err){}
					};

					obj.attachEvent( 'on'+type, obj[type+fn] );
				}else{
					obj.addEventListener(type,fn,false);
				}
			},
			_removeEvent : function(obj,type,fn){
				 if(obj.detachEvent){
					obj.detachEvent( 'on'+type, obj[type+fn] );
					obj[type+fn] = null;
				  }else{
					obj.removeEventListener(type,fn,false);
				  }
			},

			/* Simple merge method to overload settings */
			mergeObj : function(o,ob){
				var obj = {};
				for(var z in ob){
					if(ob.hasOwnProperty(z)){
						obj[z] = ob[z];
					}
				}
				return obj;
			},

			/* Dev stuff - Useful informations about the FiFs */
			debug : {

				// All errors are pushed to this Array
				errors : []
			}
		},
	
		/* Public namespace */
		pub : {

			/* Public method to log errors*/
			logError : function(e){
				FiF.core.debug.errors.push(e);
			},

			/* Create one Friendly Iframe */
		    create : function(new_settings){
				FiF.core.buildFiF(new_settings);
			},
			/* Obviusly show the errors that was found */
			showErrors : function(){
				if(window.console){
					console.log(FiF.core.debug.errors);
				}
			},
			
			/* Reload all friendly iframes */
			reloadAll : function(){
				var iframes = d.getElementsByTagName('iframe'),
					if_length = iframes.length,
					i = 0;
				for(i;i<if_length;i++){
					var fifid = iframes[i].id;
					/^fif_/.test(fifid) ? FiF.pub.reload(fifid.replace('fif_','')) : false;
				}
			},
		
			/* Reload an Iframe */
			reload : function(fifid){
				var iframe = d.getElementById('fif_'+fifid);
				if(iframe){
					d.getElementById('fif_'+fifid).contentDocument.location.reload(true);
				}else{
					FiF.core.debug.errors.push('Error trying to reload an Iframe. The Friendly Iframe with id fif_'+fifid+ ' was not found.');
				}
			},

			/*
			/ Fluid Iframe Flash content
			/ This techinique set an interval to verify the size of embed objects
			/ If the size is changed, aplly the new size to Friendly Iframe
			/ We need to set the Iframe with a big z-index 
			*/
			listenFiF : function(fifContainer,fifid){
                window.FiF_Listener = window.setInterval((function(fifid, fifContainer){
                        return function(){
                            var iframe = d.getElementById(fifid);
		                        iframe.style.position = 'absolute';
		                        iframe.style.zIndex = '996';
							FiF.core.resize(fifContainer,fifid);
						};
                })(fifid, fifContainer), 60);

            },
			/*
			/ Stop to listening, just clear interval, and apply the original size to iframe
			*/
            stopListenFiF : function(fifContainer,fifid){
				var iframe = d.getElementById(fifid);
				iframe.style.height = fifContainer.offsetHeight +"px";
                iframe.style.width = fifContainer.offsetWidth +"px";
				window.clearInterval(window.FiF_Listener);
            }
		}
	};
	
	// Create a public global object
	window.FiF = FiF.pub;	
})(document);

/* 
* AdManager Library version 0.1 
* @date 30/11/2011
* @author Jaydson Gomes
* @email jaydson.gomes@corp.terra.com.br
*/
(function(){
	/* Terra Ad Manager global namespace */
	var TrrAdManager = {};

	/* Configuration  */
	TrrAdManager.config = {
		TGMKEY 						: null,
		SITE 							: null,
		ZONE 							: null,
		PRIOR_AD					: 'top',
		PRIOR_AD_TIMEOUT	: 5000,
		PRIOR_AD_READY		: true
	}
	
	/* Private core namespace */
	TrrAdManager.core = {
		currentEnv : 'production',
		env : {
			development : {
				TAGMAN_PATH : 'http://p2.trrsf.com.br/tagmanfe/ShowArea.aspx',
				TGMKEY : 'br.test2010.home',
				SITE : 'br.teste',
				ZONE : 'home'
			},
			production : {
				TAGMAN_PATH : 'http://p2.trrsf.com.br/tagmanfe/ShowArea.aspx',
				TGMKEY : tgmKey ? tgmKey : 'br.homepage.home',
				SITE : site ? site : 'br.terra.homepage',
				ZONE : zone ? zone : 'home'
			}
		},

		/* Get the Tagman URL for ads */
		getURL : function(area){
			var _this = TrrAdManager.core,
					_conf = TrrAdManager.config,
					tgmkey = _conf.TGMKEY ? _conf.TGMKEY : top.tgmKey,
					site = _conf.SITE ? _conf.SITE : top.site,
					zone = _conf.ZONE ? _conf.ZONE : top.zone;					
			if(typeof tgm.getShowAreaUrl === 'function'){
				var url = tgm.getShowAreaUrl(area,'site='+ top.site, 'zone='+ top.zone);
				return url;
			}else{
				if(area){
					return _this.env[_this.currentEnv].TAGMAN_PATH + '?' +
							'key=' +_this.env[_this.currentEnv].TGMKEY + '.' +
							area +'&site='+_this.env[_this.currentEnv].SITE + 
							'&zone='+_this.env[_this.currentEnv].ZONE;
				}else{
					_this.errors.push('Error creating the TagMan URL. Please provide a valid area name');
				}
			}
		},

		/* Get information about an Ad */
		getAdInfo : function(ad_name){
			var floatings = TrrAdManager.pub.ads.floating,
				ad = null;
			for(var i=0;i<floatings.length;i++){
			   if(floatings[i].alias === ad_name){
				  ad = floatings[i]; 
			   }
			}
			if(ad===null){
				var integrateds = TrrAdManager.pub.ads.integrated;
				for(var x=0;x<integrateds.length;x++){
				   if(integrateds[x].alias == ad_name){
					  ad = integrateds[x];
				   }
				}
			}
			return ad !== null ? ad : false;
		},

		/* Errors */
		errors : []
	};

	/* Public pub namespace */
	TrrAdManager.pub = {

		/* Ads */
		ads : {

			/* Floating format */
			floating : [{
				name   : 'super_expandable_banner',
				expandable : true,
				config : {
					types      : ['swf','jpg','gif'],
					dimensions : {
						closed : {
						   width  : 728,
						   height : 90
						},
						opened : {
						   width  : 728,
						   height : 300
						}
					},
					expandFunction : 'posEls',
					contractFunction : 'repEls'
				}
			},
			{
				name   : 'super_expandable_banner_full',
				expandable : true,
				alias  : 'top',
				config : {
					types      : ['swf','jpg','gif'],
					dimensions : {
						closed : {
							   width  : 728,
							   height : 90
							},
							opened : {
							   width  : 728,
							   height : 540
							}
						},
						expandFunction : 'posEls',
						contractFunction : 'repEls'
					}
				},
				{
					name   : 'middle_rectangle_intervation',
					expandable : true,
					alias  : 'right',
					config : {
						types      : ['swf','jpg','gif'],
						dimensions : {
							closed : {
							   width  : 300,
							   height : 250
							},
							opened : {
							   width  : 936,
							   height : 465
							}
						},
						expandFunction : 'boxExpand',
						contractFunction : 'boxContract'
					}
				},
				{
					name   : 'middle_rectangle_expandable',
					expandable : true,
					config : {
						types      : ['swf','jpg','gif'],
						dimensions : {
							closed : {
							   width  : 300,
							   height : 250
							},
							opened : {
							   width  : 730,
							   height : 350
							}
						},
						expandFunction : 'retanguloExpand',
						contractFunction : 'retanguloContract'
					}
				},
				{
					name   : 'half_banner_expandable',
					expandable : true,
					config : {
						types      : ['swf','jpg','gif'],
						dimensions : {
							closed : {
							   width  : 234,
							   height : 60
							},
							opened : {
							   width  : 234,
							   height : 300
							}
						},
						expandFunction : 'posEls',
						contractFunction : 'repEls'
					}
				}],

				/* Integrated format */
				integrated : [{
						name : 'pagesponsor',
						alias : 'pagesponsor',
						expandable : false,
						config : {
							types      : ['swf','jpg','gif'],
							dimensions : {
								closed : {
								   width  : 97,
								   height : 90
								},
								opened : {
								   width  : null,
								   height : null
								}
							}
						}
					},
					{
						name : 'bar1_1280',
						alias : 'bar1_1280',
						expandable : false,
						config : {
							types      : ['swf','jpg','gif'],
							dimensions : {
								closed : {
								   width  : 200,
								   height : 446
								},
								opened : {
								   width  : null,
								   height : null
								}
							}
						}
					},
					{
						name : 'sbuttonturism',
						alias : 'sbuttonturism',
						expandable : false,
						config : {
							types      : ['swf','jpg','gif'],
							dimensions : {
								closed : {
								   width  : 88,
								   height : 31
								},
								opened : {
								   width  : null,
								   height : null
								}
							}
						}
					},
					{
						name : 'sbuttoneconomy',
						alias : 'sbuttoneconomy',
						expandable : false,
						config : {
							types      : ['swf','jpg','gif'],
							dimensions : {
								closed : {
								   width  : 195,
								   height : 31
								},
								opened : {
								   width  : null,
								   height : null
								}
							}
						}
					},
					{
						name : 'bottom',
						alias : 'bottom',
						expandable : false,
						config : {
							types      : ['swf','jpg','gif'],
							dimensions : {
								closed : {
								   width  : 936,
								   height : 106
								},
								opened : {
								   width  : null,
								   height : null
								}
							}
						}
					},
					{
						name : 'right2',
						alias : 'right2',
						expandable : false,
						config : {
							types      : ['swf','jpg','gif'],
							dimensions : {
								closed : {
								   width  : 300,
								   height : 250
								},
								opened : {
								   width  : null,
								   height : null
								}
							}
						}
					},
					{
						name : 'textlinks',
						alias : 'textlinks',
						expandable : false,
						config : {
							types      : ['swf','jpg','gif'],
							dimensions : {
								closed : {
								   width  : 619,
								   height : 109
								},
								opened : {
								   width  : null,
								   height : null
								}
							}
						}
					},
					{
						name : 'bar2_1280',
						alias : 'bar2_1280',
						expandable : false,
						config : {
							types      : ['swf','jpg','gif'],
							dimensions : {
								closed : {
								   width  : 200,
								   height : 446
								},
								opened : {
								   width  : null,
								   height : null
								}
							}
						}
					},
					{
						name : 'pbuttons1',
						alias : 'pbuttons1',
						expandable : false,
						config : {
							types      : ['swf','jpg','gif'],
							dimensions : {
								closed : {
								   width  : 195,
								   height : 40
								},
								opened : {
								   width  : null,
								   height : null
								}
							}
						}
					},
					{
						name : 'pbuttons2',
						alias : 'pbuttons2',
						expandable : false,
						config : {
							types      : ['swf','jpg','gif'],
							dimensions : {
								closed : {
								   width  : 195,
								   height : 40
								},
								opened : {
								   width  : null,
								   height : null
								}
							}
						}
					},
					{
						name : 'specialsponsor2',
						alias : 'specialsponsor2',
						expandable : false,
						config : {
							types      : ['swf','jpg','gif'],
							dimensions : {
								closed : {
								   width  : 195,
								   height : 31
								},
								opened : {
								   width  : null,
								   height : null
								}
							}
						}
					},
					{
						name : 'sbuttonsports',
						alias : 'sbuttonsports',
						expandable : false,
						config : {
							types      : ['swf','jpg','gif'],
							dimensions : {
								closed : {
								   width  : 195,
								   height : 31
								},
								opened : {
								   width  : null,
								   height : null
								}
							}
						}
					},
					{
						name : 'ppi',
						alias : 'ppi',
						expandable : false,
						config : {
							types      : ['swf','jpg','gif'],
							extra	   : {
								overflow : 'left'
							},
							dimensions : {
								closed : {
								   width  : 300,
								   height : 866
								},
								opened : {
								   width  : null,
								   height : null
								}
							}
						}
					},
					{
						name : 'sbuttonnews',
						alias : 'sbuttonnews',
						expandable : false,
						config : {
							types      : ['swf','jpg','gif'],
							dimensions : {
								closed : {
								   width  : 195,
								   height : 31
								},
								opened : {
								   width  : null,
								   height : null
								}
							}
						}
					},
					{
						name : 'sbuttonentertainment',
						alias : 'sbuttonentertainment',
						expandable : false,
						config : {
							types      : ['swf','jpg','gif'],
							dimensions : {
								closed : {
								   width  : 195,
								   height : 31
								},
								opened : {
								   width  : null,
								   height : null
								}
							}
						}
					},		
					{
						name : 'sbuttonlifestyle',
						alias : 'sbuttonlifestyle',
						expandable : false,
						config : {
							types      : ['swf','jpg','gif'],
							dimensions : {
								closed : {
								   width  : 195,
								   height : 31
								},
								opened : {
								   width  : null,
								   height : null
								}
							}
						}
					},			
					{
						name : 'pollsponsor',
						alias : 'pollsponsor',
						expandable : false,
						config : {
							types      : ['swf','jpg','gif'],
							dimensions : {
								closed : {
								   width  : 195,
								   height : 31
								},
								opened : {
								   width  : null,
								   height : null
								}
							}
						}
					}
				]
		},

		/* Public Config */
		setConfig : function(obj){
			var _core = TrrAdManager.core,
					_public = TrrAdManager.pub;

			if(obj.TGMKEY){
				_public.api.tgmKey(obj.TGMKEY);
			}

			if(obj.SITE){
				_public.api.site(obj.SITE);
			}

			if(obj.ZONE){
				_public.api.zone(obj.ZONE);
			}
		},
		
		/* Public API */
		api : {

			tgmKey : function(tgmkey){
				if(tgmkey != '' && typeof tgmkey != 'undefined'){
					TrrAdManager.config.TGMKEY = tgmkey;
					window.tgmKey = tgmkey;
					window.tgm.page.tgmKeyOriginal = tgmkey;
				}else{
					return TrrAdManager.config.TGMKEY;
				}
			},

			site : function(site){
				if(site != '' && typeof site != 'undefined'){
					TrrAdManager.config.SITE = site;
				}else{
					return TrrAdManager.config.SITE;
				}
			},

			zone : function(zone){
				if(zone != '' && typeof zone != 'undefined'){
					TrrAdManager.config.ZONE = zone;
				}else{
					return TrrAdManager.config.ZONE;
				}
			},

			/* Call to FiF object reload method to reload all ads */
			reloadAds : function(){
				FiF.reloadAll();
			},

			/* Call to FiF object reload method to reload one ad */
			reloadAd : function(placeholder){
				FiF.reload(placeholder);
			},
			
			/* Remove an ad */
			remove : function(placeholder){
				var element = document.getElementById('fif_'+placeholder);
				element.parentNode.removeChild(element);
			},

			/* Get info about an ad */
			getAdInfo : function(name){
				return name ? TrrAdManager.core.getAdInfo(name) : null;
			},

			// Called when script ad from trirdy is loaded
			priorAdLoaded : function(obj,adname){
				if (!obj.readyState || obj.readyState == "loaded" || obj.readyState == "complete") {
					TrrAdManager.config.PRIOR_AD_READY = true;
					TrrAdManager.pub.api.renderQueuedAds();
					window.clearTimeout(window.PRIOR_AD_TIMEOUT);	
				}				
			},

			// Render all quewed ads
			renderQueuedAds : function(){
				var ad = null,
				queuedAds = TrrAdManager.pub.api.adsQueue;
				
				while(queuedAds.length){
					ad = queuedAds.shift();
					TrrAdManager.pub.api.render(ad.name,ad.ph,ad.cb,ad.st);
				}
			},

			// List with ads that must to wait
			adsQueue : [],

			// Define ad priority
			setPriorAd : function(adname, timeout){
				TrrAdManager.config.PRIOR_AD = (adname != undefined && adname != '')  ? adname : TrrAdManager.config.PRIOR_AD;
				TrrAdManager.config.PRIOR_AD_TIMEOUT = (timeout !== undefined && timeout != '') ? timeout : TrrAdManager.config.PRIOR_AD_TIMEOUT;
				TrrAdManager.config.PRIOR_AD_READY = false;
			},
			
			/* Render ad in placeholder */
			render : function(ad_name,placeholder,callback,settings){
				if(null === ad_name      || 
					 undefined === ad_name || 
					 '' === ad_name){
					TrrAdManager.core.errors.push('Invalid AD name: '+ ad_name);
				}
				if(null === placeholder || 
					 undefined === placeholder || 
					 '' === placeholder){
					TrrAdManager.core.errors.push('Invalid placeholder: '+ placeholder);
				}
				var url = TrrAdManager.core.getURL(ad_name),
					ad = TrrAdManager.core.getAdInfo(ad_name),
					config = ad.config,
					width = config ? config.dimensions.closed.width : null,
					height = config ? config.dimensions.closed.height : null,
					xwidth = config ? config.dimensions.opened.width : null,
					expFunction = config ? config.expandFunction : null,
					contFunction = config ? config.contractFunction : null,
					xheight = config ? config.dimensions.opened.height : null,
					ext	= config ? config.extra : null,
					isexpandable = ad.expandable,
					cb = callback ? callback : null,
					rect = ad.alias === 'right' ? true : false;
				if(FiF){
					if(window.AdsMetrics){
						AdsMetrics.register(ad_name,'start');
					}
					FiF.create({
						placeholder 	: placeholder,
						adsrc			: url,
						adname : ad_name,
						width 			: width,
						height 			: height,
						exp_width 		: xwidth,
						exp_height	 	: xheight,
						fifsrc 			: '/globalSTATIC/atm/3/core/_tpl/admanager.html',
						expandable 		: isexpandable,
						rectangle 		: rect,
						expandFunction  : expFunction,
						contractFunction: contFunction,
						extra			: ext,
						callback : function(){
							if(window.AdsMetrics){
								AdsMetrics.register(ad_name,'finish');
							}
						}
					});
				}
			},
			
			/* Create ad in placeholder */
			create : function(ad_name,placeholder,callback,settings){				
				var _this = TrrAdManager.pub;

				if(ad_name == TrrAdManager.config.PRIOR_AD){
					window.PRIOR_AD_TIMEOUT = window.setTimeout(function(){						
						_this.api.renderQueuedAds();						
					},_this.config.PRIOR_AD_TIMEOUT);
					_this.api.render(ad_name,placeholder,callback,settings);

				}else if(TrrAdManager.config.PRIOR_AD_READY == false){					
					TrrAdManager.pub.api.adsQueue.push({
						name : ad_name,
						ph : placeholder,
						cb: callback,
						st : settings
					});					

				}else{
					this.render(ad_name,placeholder,callback,settings);
				}
			},
			
			/* Set environment  */
			setEnv : function(env){
				TrrAdManager.core.currentEnv = env;
			},

			/* Dev Stuff */
			debug : {
				showErrors : function(){
					console.log(TrrAdManager.core.errors);
				}
			}
		}
	};

	// Public global TrrAdManager object
	window.TrrAdManager = TrrAdManager.pub;
	window.TrrAdManager.config = TrrAdManager.config;
})();
