
MTVM.services.Ads = function(adSize, adPositionThreshold)
{
	this.adSize					= adSize;
	this.adPositionThreshold	= (adPositionThreshold?adPositionThreshold:"1");
	this.codaParams 			= new MTVM.services.CODAParams();
	this.extraKeyValues			= "";
}



MTVM.services.Ads.prototype = 
{
	addKeyValue: function(kv){
		this.extraKeyValues = this.extraKeyValues + kv;
	},
	
	getAd:	function()
	{	
		
		this.codaParams.ads.size = this.adSize;		
		//this.codaParams.ads.positionThreshold = this.adPositionThreshold; somehow this is not feeding the value into the codaParams obj

		this.getRegionKeyValue(); //region-specific kv additions
		
		
		
		/*
		document.write("<scr"+"ipt>"+
		"com.mtvi.ads.AdManager.setAdClass(\"InternationalAd\");"+
		"com.mtvi.ads.AdManager.setDefaultContentType(\""+this.codaParams.ads.defaultContentType+"\");"+
		"com.mtvi.ads.AdManager.setDartSite(\""+this.codaParams.ads.dartSite+"\");"+
		"com.mtvi.ads.AdManager.setKeyValues(\""+this.codaParams.ads.keyValues+this.extraKeyValues+"\");"+
		"com.mtvi.ads.AdManager.setPositionThreshold(\""+this.adPositionThreshold+"\");"+
		"com.mtvi.ads.AdManager.setDefaultSections(\""+this.codaParams.ads.defaultSections+"\"); "+
		"com.mtvi.ads.AdManager.placeAd"+
		"("+
		"	{ size: \""+this.codaParams.ads.size+"\",     "+
			 "region: \""+MTVM.contextValues.userRegion+"\",     "+
			 "keyword: \""+MTVM.contextValues.search_kw+"\",     "+
			 "vid: \""+MTVM.contextValues.vid+"\",     "+
			 "vid_type: \""+MTVM.contextValues.vid_type+"\",     "+
			 "log: \""+ (MTVM.flux.isUserLoggedInFlux() ? 1 : 0).toString() +"\",     "+
			 "dcove: \"d\",     "+
			 "event: \"none\",     "+
			 "demo: \"none\"}"+
			 
		");	"+
		"</scr"+"ipt>")*/

	
		
		
		com.mtvi.ads.AdManager.setAdClass('InternationalAd');
		com.mtvi.ads.AdManager.setDefaultContentType(this.codaParams.ads.defaultContentType);
		com.mtvi.ads.AdManager.setDartSite(this.codaParams.ads.dartSite);
		com.mtvi.ads.AdManager.setKeyValues(this.codaParams.ads.keyValues+this.extraKeyValues);
		com.mtvi.ads.AdManager.setPositionThreshold(this.adPositionThreshold);
		com.mtvi.ads.AdManager.setDefaultSections(this.codaParams.ads.defaultSections);
		com.mtvi.ads.AdManager.placeAd
		(
			{ size: this.codaParams.ads.size,
			 region: MTVM.contextValues.userRegion,
			 keyword: MTVM.contextValues.search_kw,
			 vid: MTVM.contextValues.vid,
			 vid_type: MTVM.contextValues.vid_type,
			 log: (MTVM.flux.isUserLoggedInFlux() ? 1 : 0).toString(),
			 dcove: 'd',
			 event: 'none',     
			 demo: 'none'}
			 
		)
	},
	
	setCoad: function(adObject)
	{
		var src = adObject.url;
		var w = adObject.width;
		var h = adObject.height;
		coad.updateWindow(src, w, h);
	},
	
	getRegionKeyValue: function() //region-specific kv additions
	{
		
		
		//for italy dual sponsorship
		switch(MTVM.config.countryCode)
		{
			case "it":
				if(window.mtvmItSponsor!=null && window.mtvmItSponsor!="" ){			
					this.addKeyValue(";adv_sp="+window.mtvmItSponsor+";");
				}
				else
				{
					this.addKeyValue(";adv_sp=none;");
				}
				break;
		}
	}
}

MTVM.services.Ads.getSurveyAd = function()
{
	var pagePath = location.pathname.substring(1);
	var sections = pagePath.split("/");
	var params = location.search;
	
	var getAd = function(){
		MTVM.services.Ads.adSurvey = new MTVM.services.Ads("1x2", "btf");
		MTVM.services.Ads.adSurvey.addKeyValue("!category=video;!category=expand;!category=pop;");
		MTVM.services.Ads.adSurvey.getAd();
	}
	
	
	switch(sections[0]){
		case "playlists":
				if(sections[1]==null || sections[1]=="")
				{getAd();}
				break;
	
		case "featured":
			if(sections[1]=="just_added")
			{getAd();}			
			break;
	
		case "search":
			break;
			
		case "browse":
			getAd();
			break;
		
		case "top100":
			if(sections[1]==null || sections[1]==""  && (params =="" || params == null))
			{getAd();}
			break;
			
		case "artist":
			getAd();
			break;
			
	}
	
}