/**
 * MediaTray
 * --------
 * @author Jeff Clarke
 * @version 1.5
 * 
 * MediaTray is an integrated Flash/JavaScript overlay framework
 * for serving rich media paired with various ad units and sponsorship
 * opportunites, as well as other optional modules.
 * 
 * The tray is launched from a Flash launcher, which gives a preview
 * of the media to be displayed.
 *
 * Sample: http://jeffreyclarke.net/portfolio/projects/interactive-one/media-framework_v3/wordpress/gallery/overlay/giant.php
 * Dependencies: jQuery 1.3, SWFTag, mediatray.css
 *
 * Once MediaTray can be accessed using the following syntax:
 *
 * MediaTrayFactory.getTray()
 *
 * Which will then give you access to its public methods, for example
 * MediaTrayFactory.getTray().refreshAd();
 * 
 * The constructed tray has the following HTML structure (default):
 * <!--
	<div class="media_tray">
		<a class="mt_sponsored_bg"></a>
		<div class="mt_contents">
			<div class="tray_module" class="gallery_module"></div>
			<div class="tray_module" class="ad_module">
				<div id="tray_ad"></div>
				<p class="ad_text">advertisement</p>
			</div>
			<div class="tray_module" class="sponsor_module">
				<div id="tray_sponsor"></div>
			</div>
			<div class="tray_module" class="more_content_module"></div>
		</div>
		<a href="javascript:;" class="tray_close">close</a>
		<div class="tray_title">GALLERY: Maxwell</div>
	</div>
 *	-->
 *
 * Rev 1.5:
 *  - Allows multiple tray configurations per page
 *  - Removes tray / module dependencies -- all modules register their methods as callbacks.
 *
 * Future Revisions:
 * - possibly opt for dom fragments for speedier and lighter loading?
 */
 
function MediaTrayFactory(){}


/**
 * MediaTrayFactory.getTray()
 * ------------------------
 * Tray is a Factory design pattern, where a singleton controller
 * returns a tray object to be accessed and manipulated.
 * @param launcher_id - id of the launcher calling the tray. defaults to null.
 * @param opts - optional arguments to override defaults
 */
 
MediaTrayFactory.getTray = function(launcher_id, opts){
	//Logger.log("getTray(), launcher_id: "+ launcher_id, toString())
	
	if (MediaTrayFactory.trays != null){
		if (MediaTrayFactory.trays[launcher_id]) return MediaTrayFactory.trays[launcher_id];
	}else{
		MediaTrayFactory.trays = [];
		MediaTrayFactory.numTrays = 0;
	}
	
	var trayObj = function(){
	
		//private vars
		var shade, tray, trayContents, sponsoredBg, title;
		var launcherElem = jQuery("#"+launcher_id)[0];
		var options;
		var app = this;
		var _modules = {};
		var trayId = MediaTrayFactory.numTrays;
		
		//defaults
		var defaults = {
			SHADE_ANIM_DURATION: 150,
			TRAY_ANIM_DURATION: 400,
			ANIM_EASING:'linear',
			SHADE_OPACITY:0.5,
			OPEN_WIDTH: 1000,
			OPEN_HEIGHT: 600,
			modules: ['galleryModule','adModule','sponsorModule','moreContentModule']
		}
		options = jQuery.extend(defaults, opts);
		
		// application
		init();
		
		function init(){
			Logger.info('MediaTray.init()', toString());	
			drawShade();
			drawTray();
		};
		
		/**
		 * drawShade()
		 * ---------
		 * private method to draw and prepend the shaded overlay behind the tray
		 */
		function drawShade(){
			Logger.info("MediaTray.drawShade()", toString());
			if (shade == null ){
				if (jQuery('#media_shade').length > 0){
					shade = jQuery('#media_shade');
				}else{
					shade = jQuery('<div></div>').attr('id', 'media_shade').css({display:'none'});
					jQuery('body').prepend(shade);
					
					if (parseFloat(shade.css('opacity')) < 1){
						options.SHADE_OPACITY = shade.css('opacity');
					}
					
					// bypass awful alpha/flash layering problem in FF2.0
					if (jQuery.browser.mozilla && (parseFloat(jQuery.browser.version) < 1.9)) {
						shade.addClass('png_alpha_shade');
						options.SHADE_OPACITY = 1;
					}
				}
			}
		}
		
		/**
		 * drawTray()
		 * ---------
		 * private method to draw the tray container structure and sponsored background
		 * and appnd the tray to the DOM after the shade
		 */
		function drawTray(){
			Logger.info("MediaTray.drawTray()", toString());
			if (tray == null){
				tray = jQuery('<div></div>').attr('id', 'media_tray_'+trayId).attr('class','media_tray').css({display:'none'});
				trayContents =  jQuery('<div></div>').attr('class', 'mt_contents');
				
				sponsoredBg = jQuery('<a name="sponsored_bg"></a>').attr('class', 'mt_sponsored_bg').attr('id', 'media_tray_'+trayId+'_sponsored_bg');
				if (options.background && options.background.css) sponsoredBg.css(options.background.css);
				
				tray.append(sponsoredBg);
				tray.append(trayContents);
				shade.after(tray);
			}
		}
		
		/**
		 * openTray()
		 * ---------
		 * private method called to open the tray.
		 * Load sequence is shade animated, tray animated, tray populated.
		 * 
		 * @param onCloseCallback - function - function called when the tray is closed
		 */
		function openTray(onCloseCallback){
			Logger.info("MediaTray.openTray()",toString());
			
			// IE6 conditional to circumvent position:fixed bug
			if (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1){
				jQuery('.media_tray').css({top:(document.documentElement.scrollTop + document.documentElement.clientHeight/2)+'px'});
				jQuery('html').css({overflow:'hidden'}).height(jQuery(window).height());
			}
			
			populateTray();
			shade.css({display:'block', opacity:options.SHADE_OPACITY});
			//shade.animate({opacity:options.SHADE_OPACITY}, options.SHADE_ANIM_DURATION, options.ANIM_EASING, onShadeDisplayed);
			onShadeDisplayed();
			
			// conditional to hide page flash in IE and FF2
			if ((jQuery.browser.mozilla && (parseFloat(jQuery.browser.version) < 1.9)) || (navigator.userAgent.toLowerCase().indexOf("windows") > -1)) jQuery("#mainContent embed, #mainContent object, #mainContent iframe, #inner-body embed, #inner-body object, #inner-body iframe").not("#"+launcherElem.id+"").addClass('overlay_gallery_cloak');
			// additional catch to hide launcher in FF2
			if (jQuery.browser.mozilla && (parseFloat(jQuery.browser.version) < 1.9)) jQuery("#gallery_launcher_app").addClass('overlay_gallery_cloak');
			// hides all ad modules on the page, in case they're pointrolls
			jQuery(".admod iframe, .admod embed, .admod object").addClass('overlay_gallery_cloak');
			
			if(onCloseCallback) launcherElem.onCloseCallback = onCloseCallback;
		}
		
		/**
		 * onShadeDisplayed()
		 * ---------
		 * function called when shade animation is complete.  animates
		 * the tray container.
		 */
		function onShadeDisplayed(){
			tray.css({display:'block'});
			// turned off animation : 4/12/10 - JC
			//tray.animate({opacity:1}, options.TRAY_ANIM_DURATION, options.ANIM_EASING);
			shade.bind('click', closeTray);
		}
		
		/**
		 * onTrayOpen()
		 * ---------
		 * called when the tray is open.  populates the tray if it's empty.
		 */
		function populateTray(){
			if (trayContents.is(':empty')) {
				var closeButton = jQuery('<a class="tray_close" href="javascript:;">close</a>').bind('click', closeTray);
				title = jQuery('<div class="tray_title"></div>');
				tray.append(closeButton).append(title);
				
				for (var i = 0; i< options.modules.length; i++){
					try {
						Logger.info('MediaTray.onTrayOpen(), loading module: ' + options.modules[i], toString());
						_modules[options.modules[i]] = ModuleFactory.buildModule(options.modules[i], options[options.modules[i]+"_params"], trayContents, 'media_tray_'+trayId, launcher_id);
					} catch (e) {
						Logger.error("MediaTray.onTrayOpen(), " + e.message, toString());
					}
				}
			}
			//if (sponsoredBg) sponsoredBg.bind('click', closeTray);
		}
		
		
		/**
		 * closeTray()
		 * ---------
		 * closes the tray, including animations.  When complete. calls the onShadeClosed.
		 * Sequence = hide tray, animate shade closed, onclosecallback.
		 */
		function closeTray(){
			// IE6 conditional to circumvent position:fixed bug
			if (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) jQuery('html').css({overflow:'auto'}).height('100%');
			
			shade.unbind('click', closeTray);
			if (sponsoredBg) sponsoredBg.unbind('click', closeTray);
			tray.css({display:'none'});
			
			// conditional to circumvent poor gallery close performance in IE 6+
			if (navigator.userAgent.toLowerCase().indexOf("windows") > -1) onShadeClosed();
			else shade.animate({opacity:0}, options.SHADE_ANIM_DURATION, options.ANIM_EASING, onShadeClosed);
		}
		
		/**
		 * onShadeClosed()
		 * ---------
		 * Called at the end of the shade close animation. When animation is closed, calls the onCloseCallback.
		 */
		function onShadeClosed(){
			shade.css({display:'none'});

			// shows flash content and iframes on Windows and FF < 2
			jQuery('.overlay_gallery_cloak').removeClass('overlay_gallery_cloak');

			if(launcherElem.onCloseCallback) launcherElem[launcherElem.onCloseCallback]();
		}

		/**
		 * setTrayTitle()
		 * ---------
		 * sets the tray's title, calling truncateTitleText on it.
		 * @param str - title string
		 */
		function setTrayTitle(str){
			title.text(truncateTitleText(str));
		}
		
		/**
		 * truncateTitleText()
		 * ---------
		 * utility method to truncate the tray title to the available target width before it is set.
		 * @param str - string
		 * @returns truncated title string  
		 */
		function truncateTitleText(str){
			var targetWidth = title.width();
			var tempDiv = title.clone();
			tempDiv.css({visibility:"hidden", width:"auto"}).text(str);
			tray.append(tempDiv);
			
			while(tempDiv.width() > targetWidth){
				str = str.substr(0, str.lastIndexOf(" ")) + "...";
				tempDiv.text(str);
			}
			tempDiv.remove();
			return str;
		}
		
		/**
		 * getTrayModule()
		 * ---------
		 * utility method to get a specific tray module by name.
		 * @param modName - string - the module's name.  see defaults for examples.
		 */
		function getTrayModule(modName){
		
			if (_modules[modName]){
				return _modules[modName];
			}else{
				throw new Error("Module "+ modName + " is not available");
			}
		}
		
		function toString(){
			return "MediaTrayFactory";
		}
		
		
		// public methods
		// --------------
		// see the notes on the private methods called by these
		// for an explanation of what they do.
		
		return {
			open:function(onCloseCallback){
				Logger.info('MediaTray.open()', toString());
				openTray(onCloseCallback);
			},
		 	close:function(){
				Logger.info('MediaTray.close()', toString());
				closeTray();
			},
			
			setTitle:function(str){
				Logger.info('MediaTray.setTitle(), title: '+ str, toString());
				setTrayTitle(str);
			},
			
			// TODO: is there a safer way to do this?
			addCallback:function(name, func){
				if (this[name]) throw new Error("A callback with the name "+name+" has already been defined.");
				if (typeof(func) != "function") throw new Error("func must be a function");
				this[name] = func;
			},
			getTrayElem:function(){
				return tray;
			}
		};
	}();
	MediaTrayFactory.numTrays++;
	MediaTrayFactory.trays[launcher_id] = trayObj;
	return trayObj;
}

// OVERLAY HTML MODULES

/**
 * ModuleFactory
 * -------------
 * Singleton factory for building tray modules.  Defines available module 
 * types, including:
 * 
 * module
 * swfModule
 * sponsorModule
 * adModule
 * galleryModule
 * moreContentModule
 * 
 * All modules are built by extending the module base.  Swf modules (eg. gallery)
 * are then built by extending swfModule.  So, for example, 
 * module-> swfModule-> galleryModule
 *
 * Modules should be treated as objects and should track their own internal variables,
 * methods, events and behaviors.
 */

ModuleFactory = function(){
	this.MODULE_CONSTANTS = {
		// TODO: everyone should refer to these constants
		LOAD_PLAYLIST_BINDING:"loadPlaylist",
		GET_NEXT_PLAYLIST_BINDING:"getNextPlaylist",
		AD_REFRESH_BINDING:"refreshAd",
		AD_HIDE_BINDING:"hideAd"
	};
	return this;
}();

/**
 * buildModule()
 * -----------
 * workhorse of the ModuleFactory.  Builds all module types.
 * @param type : string name of the module
 * @param params: object - paramaters used to define how the module is built
 * @param target: DOM Element where the module should be built
 */
ModuleFactory.buildModule = function(type, params, target, tray_id, launcher_id){
	
	// generic module
	var module = function(params){
		// private
		params = jQuery().extend({}, params);
		
		// public
		var that = jQuery("<div></div>").attr('class', 'tray_module');
		if (params.html) that.html(params.html);
		if (params.id){
			that.attr('id', tray_id+'_'+params.id);
			that.addClass(params.id);
		}
		target.append(that);
		
		// public
		
		return that;
	}
	
	// swf module -- module with flash content.
	var swfModule = function(params, flashvars){
		var that = module(params);
		
		if (!params || ! params["swf"]) throw new Error("To module, swf param in "+tray_id+'_'+params.id+" must be defined by caller");
		var swf = params["swf"];
		
		// globally applied to all swfs in the tray factory by necessity.
		swf.setAllowScriptAccess(SWFTag.ALWAYS);
		swf.setAllowNetworking(SWFTag.ALL);
		swf.setWmode(SWFTag.TRANSPARENT);
		swf.addFlashVars(document.location.search.substring(1));
		
		for (var fv in flashvars){
			swf.addFlashVar(fv, flashvars[fv]);
		}
		
		// gives a method for the module to be able to access its flash movie.
		// needs to be fetched at runtime for IE.
		that.flash = function(){
			var flash = eval("jQuery('#"+swf.getId()+"')[0]");
			return flash;
		};
		
		var target;
		if (params.containerId){
			var container = jQuery('<div id='+params.containerId+'></div>')[0];
			
			that.prepend(container);
			target = container;
			swf.fillElementId(params.containerId);
		}else{
			target = that;
			swf.fillElementId(that[0].id);
		}

		return that;
	}
	
	var sponsorModule = function(params){
		var CALLBACK_NAME = "setSponsorSize";
		
		params = jQuery().extend({}, params, {
			id: 'sponsor_module',
			containerId: tray_id+'_tray_sponsor'
		});
		
		// adds a callback to set the size of the sponsor. primarily to set the sponsor size to 0 if it's unavailable.
		var tray = MediaTrayFactory.getTray(launcher_id);
		tray.addCallback(CALLBACK_NAME, function(w,h){
			var module = jQuery('#'+tray_id+'_'+params.id);
			var sponsor = jQuery('#'+params.containerId);
			sponsor.width(w).height(h);
			
			if (w>0 && h>0){
				module.removeClass('sponsor_inactive');
				sponsor.addClass('active');
			}else{
				sponsor.removeClass('active');
				module.addClass('sponsor_inactive');
				if (!module.css('background')){
					tray.getTrayElem().addClass('no_default_sponsor');
				}
			}
		});
		
		var flashvars = {
			targetWidth:140,
			targetHeight:60,
			setSizeFn:'MediaTrayFactory.getTray("'+launcher_id+'").'+CALLBACK_NAME
		}
		
		var that = swfModule(params, flashvars);
		
		return that;
	}
	
	var bgLoaderModule = function(params){
		var CALLBACK_NAME = "setBackground";
		var CLICK_TARGET = "_blank";
		
		params = jQuery().extend({}, params, {
			id: 'bg_loader_module'
		});
		
		MediaTrayFactory.getTray(launcher_id).addCallback(CALLBACK_NAME, function(dataObj){
			if (dataObj && dataObj.bannerURL){
				Logger.log(CALLBACK_NAME+"(), bannerUrl: "+dataObj.bannerURL, tray_id+'_'+params.id);
				var bg = jQuery("#"+ tray_id + "_sponsored_bg");
				if (bg.css("backgroundImage") == "none"){
					bg.css({display:"block",backgroundImage:"url('"+dataObj.bannerURL+"?ck="+new Date().getTime()+"')"});
					if (dataObj.bannerClickURL){
						bg.attr("target", CLICK_TARGET).attr("href", dataObj.bannerClickURL);
					}else{
						bg.attr("href", "javascript:MediaTrayFactory.getTray('"+launcher_id+"').close();");
					}
				}
			}else{
				Logger.error(CALLBACK_NAME+"(), invalid background data. aborting", tray_id+'_'+params.id);
			}
		});
		
		var flashvars = {
			onData:'MediaTrayFactory.getTray("'+launcher_id+'").'+CALLBACK_NAME
		}
		
		var that = swfModule(params, flashvars);
		
		return that;
	}
	
	
	var adModule = function(params, launcher_id){
		var CALLBACK_NAME = "setAdSize";
		var REFRESH_BINDING = "refresh"
		var DEFAULT_SIZE = {width:300, height:250};
		
		params = jQuery().extend({}, params, {
			id: 'ad_module',
			html: '<iframe id="'+tray_id+'_ad" class="tray_ad active" src="'+params["adFrameSrc"]+'" class="adframe" width="300" height="250" frameborder="0" marginheight="0" marginwidth="0" scrolling="no"></iframe><div class="ad_text"> </div>'
		});
		
		var that = module(params);
		var frame = jQuery('#'+tray_id+'_ad')[0];
		
		// adds a callback to reresh the ad
		MediaTrayFactory.getTray(launcher_id).addCallback(ModuleFactory.MODULE_CONSTANTS.AD_REFRESH_BINDING, function(w,h){
			frame.src = frame.src;
		});
		
		// adds a callback to reresh the ad
		MediaTrayFactory.getTray(launcher_id).addCallback(ModuleFactory.MODULE_CONSTANTS.AD_HIDE_BINDING, function(b){
			if (b){
				that.css({display:"none"});
			}else{
				that.css({display:"block"});
			}
		});
		
		return that;
	}
	
	// flash photo gallery module
	var galleryModule = function(params){
		// const
		var PROMO_TXT = "Check this out: ";
		var OPEN_CALLBACK_NAME = "openShareLink";
		var SHARE_WINDOW_HEIGHT = 570;
		var SHARE_WINDOW_WIDTH = 570;
		
		// private
		params = jQuery().extend({}, params, {
			id: 'gallery_module'
		});
	
		var flashvars = {
			// Media Tray Functions
			adRefreshFn:'MediaTrayFactory.getTray("'+launcher_id+'").'+ModuleFactory.MODULE_CONSTANTS.AD_REFRESH_BINDING,
			nextPlaylistFn:'MediaTrayFactory.getTray("'+launcher_id+'").'+ModuleFactory.MODULE_CONSTANTS.GET_NEXT_PLAYLIST_BINDING,
			setTitleFn:'MediaTrayFactory.getTray("'+launcher_id+'").setTitle',
			
			// Media Tray Bindings
			loadPlaylistBinding:ModuleFactory.MODULE_CONSTANTS.LOAD_PLAYLIST_BINDING,
			
			// Add parameters from page's URL as flashvars:
			appUrl:document.location.href,
			
			// share
			shareMethod:"MediaTrayFactory.getTray('"+launcher_id+"')."+OPEN_CALLBACK_NAME,
			fbShareUrl:"http://www.facebook.com/sharer.php?u="+encodeURIComponent(document.location.href)+"&t="+encodeURIComponent(document.title),
			bpShareUrl:"http://www.blackplanet.com/bulletin_board/external.html?url="+encodeURIComponent(document.location.href)+"&title="+encodeURIComponent(document.title),
			emailShareUrl:"mailto:?subject="+encodeURIComponent(document.title)+"&body="+PROMO_TXT+encodeURIComponent(document.location.href),
			twitShareUrl:"http://twitthis.com/twit?url="+encodeURIComponent(document.location.href)
		}
		
		var that = swfModule(params, flashvars);
		
		/** CALLBACKS **/
		
		// open "share" window
		MediaTrayFactory.getTray(launcher_id).addCallback(OPEN_CALLBACK_NAME, function(url){
			var shareWin = window.open(url, "share", 'width='+SHARE_WINDOW_HEIGHT+',height='+SHARE_WINDOW_WIDTH+',menubar');
			if (shareWin){
				shareWin.focus();
			}else{
				return false;
			}
		});
		
		// open new playlist
		MediaTrayFactory.getTray(launcher_id).addCallback(ModuleFactory.MODULE_CONSTANTS.LOAD_PLAYLIST_BINDING, function(pls){
			Logger.info('MediaTray.loadPlaylist()', toString());
			try {
				that.flash()[ModuleFactory.MODULE_CONSTANTS.LOAD_PLAYLIST_BINDING](pls);
			} catch(e){
				Logger.error(e.message, toString());
			}
		});
		
		return that;
	}
	
	// RSS Module -- defines more content
	var moreContentModule = function(params){
		var 
		// private
		params = jQuery().extend({}, params, {
			id: 'more_content_module'
		});
		
		
		var flashvars = {
			
			// Media Tray Functions
			adRefreshFn:'MediaTrayFactory.getTray("'+launcher_id+'").'+ModuleFactory.MODULE_CONSTANTS.AD_REFRESH_BINDING,
			loadPlaylistFn:'MediaTrayFactory.getTray("'+launcher_id+'").'+ModuleFactory.MODULE_CONSTANTS.LOAD_PLAYLIST_BINDING,
			
			// Media Tray Bindings
			getNextPlaylistBinding:ModuleFactory.MODULE_CONSTANTS.GET_NEXT_PLAYLIST_BINDING
		}
		
		var that = swfModule(params, flashvars);
		
		/** CALLBACKS **/
		
		// getNextPlaylist
		MediaTrayFactory.getTray(launcher_id).addCallback(ModuleFactory.MODULE_CONSTANTS.GET_NEXT_PLAYLIST_BINDING, function(currentPls){
			Logger.info('MediaTray.getNextPlaylist() called with current playlist: '+ currentPls, toString());
			try {
				var playlist = that.flash()[ModuleFactory.MODULE_CONSTANTS.GET_NEXT_PLAYLIST_BINDING](currentPls)
				Logger.info('MediaTray.getNextPlaylist(), playlist:'+ playlist, toString());
				return playlist;
			} catch(e){
				Logger.error(e.message, toString());
				return null;
			}
		});
		
		// public
		return that;
	}
	
	switch (type){
		case 'adModule' : return adModule(params, launcher_id); break;
		case 'galleryModule' : return galleryModule(params); break;
		case 'moreContentModule' : return moreContentModule(params); break;
		case 'sponsorModule' : return sponsorModule(params); break;
		case 'bgLoaderModule' : return bgLoaderModule(params); break;
		default : throw new Error("Module type '"+ type + "' is not available");
	}
}

/**
 * Logger
 * ------
 * Logging framework to allow for more complex Javascript Console logging
 * by level.  All logs disabled if debug is not enabled at application start.
 *
 * To enable logging, add the following to the search string in the address
 * bar: debug=DEBUG_LEVEL
 */
Logger = function(){
	var _level = 0;
	
	var PREFIX = "console.";
	var LOG = "log";
	var INFO = "info";
	var WARN = "warn";
	var ERROR = "error";
	var DEFAULT_ID = "Default Logger";
	
	var query = document.location.search
	if (query.length > 0){
		var qv = query.substr(1).split('=');
		if (qv[0] == 'debug') _level = qv[1];
	}
	
	function logMessage(msg, id, level){
		if(level <= 0) return;
		if (!id) id = DEFAULT_ID;
		
		//if(!(msg is String)) msg = format(msg, indent); // formatting?
		var logEntry = ">> [" + id + "] -> " + msg;
		try { eval(PREFIX + level + "(logEntry)"); }catch(e){}
	}
	return {
		log:function(msg, id){ if(_level > 0 && _level < 2) logMessage(msg, id, LOG); },
		info:function(msg, id){ if(_level > 0 && _level < 3) logMessage(msg, id, INFO); },
		warn:function(msg, id){ if(_level > 0 && _level < 4) logMessage(msg, id, WARN); },
		error:function(msg, id){ if(_level > 0) logMessage(msg, id, ERROR); }
	}
}();


AdHelper = function(){
	var DC_PREFIX = "http://ad.doubleclick.net/";
	var TILE_DEFAULT = 4;
	var POS_DEFAULT = 3;
	
	function getPageCategory(){
		return (window.impressionPostCategory) ? window.impressionPostCategory : "";
	}
	function getPageSlug(){
		return (window.impressionPostSlug) ? window.impressionPostSlug : "";
	}
	function getAdId(){
		return (window.adid) ? window.adid : "";
	}
	
	return {
		getAdTag:function(type, dcTag, size, str){
			if (!dcTag) dcTag = "";
			if (!size) size="300x250";
			
			var slug = getPageSlug();
			var cat = getPageCategory();
			var adid = getAdId();
			
			return (DC_PREFIX+type+'/'+dcTag+'/'+cat+"/gallery/?pg="+cat+";sz="+size+((size=='300x250') ? ";tile="+TILE_DEFAULT+";pos="+POS_DEFAULT : "") + ";article="+slug+";comp="+adid+(str ? (";"+str) : "") + ";ord=");
		}
	}
}();