// $Id: sikad.js,v 1.16 2010/08/12 16:31:06 ntai Exp $



var pos21492 = 0;


if (typeof(sik) == 'undefined') { var sik = {}; }
sik.ad = function() {
	var DART_BASE = 'http://ad.doubleclick.net/adj',
	DART_NETWORK = '3475.sik',
	IFRAME_BASE = '/sites/all/modules/sikad/js/sikad-rf.html',
	DS = '/', SC = ';', EQ = '=', AS = '&', QM = '?',
	zn = '',
	pm = '',
	dcove = 'd',
	sz = '',
	tile = 1,
	dcopt = 'ist',
	ord = Math.ceil(1 + 1E12 * Math.random()),
	add_pos = false,
	pos = 1,
	rf = false,
	rf_game = false,
	to = '',
	src = false;
	
	
	
	function get_iframe_src() {
		var iframe_src = IFRAME_BASE + QM + 'zn' + EQ + zn + AS + 'sz' + EQ + sz + AS + 'tile' + EQ + tile + AS + 'pm' + EQ + pm;
		
		iframe_src += AS + 'articleId' + EQ + afArticleId;
		
		if (to) { iframe_src += AS + 'to' + EQ + to; }
		if (src) { iframe_src += AS + 'src' + EQ + '1'; }
		tile++;
		
		return iframe_src;
	} // get_iframe_src()
	
	function get_iframe_tag() {
		var iframe_src = get_iframe_src(),
		dim = sz.split('x'),
		w = dim[0], h = dim[1];
		return '<iframe src="' + iframe_src + '" width="' + w + '" height="' + h + '" scrolling="no" frameborder="0" marginwidth="0" marginheight="0"></iframe>';
	} // get iframe_tag()
	
	function write_iframe_tag() {
		var iframe_tag = get_iframe_tag();
		document.write(iframe_tag);
	}  // write_iframe_tag()
	
			
	this.qc = new Array();
	
	return {
		
		init: function() {
		}, // sik.ad.init()

		setQc: function(qcArr) {
			this.qc = qcArr;
		},
		
		setZone: function(zoneString) {
			this.zone = zoneString;
		},
		
		setArticleId: function(articleId) {
			this.artId = articleId;
		},
		
		getNewZone: function(oldZone) {
			
			
			//console.log('getNewZone(' + oldZone + ')');
			
			// REMOVE THIS ... MAYBE!
			newZone = '';
			
			winLoc = '' + window.location.href + '';
			//c('winLoc : ' + winLoc);
			
			//c('winLoc.indexOf(\'?\') : ' + winLoc.indexOf('?'));
			
			// strip out GET string
			
			if (winLoc.indexOf('?') != -1) {
				firstQmPos = winLoc.indexOf('?');
				winLoc = winLoc.substr(0,firstQmPos);
			}
			
			
			//c('winLoc : ' + winLoc);
			
			switch (oldZone) {
				case 'mainpage' :
					newZone = 'homepage';
					break;
				case 'football_nfl/main' :
					newZone = 'nflzone';
					break;
				case 'freeze_frame' :
					newZone = 'photos';
					break;
				case 'games' :
					switch (winLoc) {
						case 'http://preview-sikids.ibs.aol.com/games/' :
						case 'http://preview-sikids.ibs.aol.com/games' :
						case 'http://www.sikids.com/games/' :
						case 'http://www.sikids.com/games' :
							newZone = 'games/main';
							break;
						default :
							newZone = 'games';
							break;
					}
					break;
				case 'specials' :
					
					if (winLoc.search('sikids-tv') == -1) {
						newZone = '';
					} else {
						newZone = 'video';
					}
					break;
				case 'kidstv' :
					newZone = 'video';
					break;
				case 'kid-reporter' :
					newZone = 'kidreporter';
					break;
				case 'contests' :
				case 'build' :
				case 'about-us' :
					newZone = oldZone;
					if (winLoc.search('cover-viewer') != -1) {
						newZone = 'covers'
						match = true;
					}
					break;
				case '' :
				default :
					//c('default');
					match = false;
					// blogs , then news
					if (winLoc.search('blog') != -1) {
						newZone = 'blogs'
						match = true;
					}
					if (winLoc.search('news') != -1) {
						newZone = 'news'
						match = true;
					}
					if (winLoc.search('picture-puzzle') != -1) {
						newZone = 'puzzle'
						match = true;
					}
					if (winLoc.search('buzzs-laugh-locker') != -1) {
						newZone = 'buzz_locker'
						match = true;
					}
					// for uncaught pages, set newZone to empty string
					if (match == false) {
						newZone = '';
					}
					break;
			}
			
			
			//console.log('newZone : ' + newZone);
			
			
			
			
			
			
			return newZone;
			
			
			
			
			
			
			
			
			
			
		},
		
		integrated: function(size) {
			sz = size; // sz is a class-wide variable
			//add_pos = true;
			//write_dart_tag();
			sizeArr = size.split('x');
			afAd = adFactory.getAd(sizeArr[0], sizeArr[1]);
			if (size == '214x92') {
				pos21492++;
				//c('pos21492 : ' + pos21492);
				afAd.setParam('pos', pos21492);
			}
			afAd.write();
		}, // sik.ad.integrated()
		
		load: function(size) {
			sz = size; // sz is a class-wide variable
			if (rf_game && window.location.href.match(/\/games\/.+$/)) {
				//this.refresh();
				rf = true;
			}
			// TESTING ONLY - FORCE rf = true
			//rf = true;
			//c('afArticleId : ' + afArticleId);
			
			
			//c('this.qc');
			// this is for the iframe
			qcString = '';
			$.each(this.qc, function(index, value) {
				//c(index + ' : ' + value);
				qcString += '|' + value;
			});
			qcString = qcString.substr(1);
			
			
			if (rf) {
				//write_iframe_tag();
				
				// document.write iframe tag
				
				
				
				// requires :
				// size
				// quantcast?
				// position! (sort of new)
				// article id! (new)
				// zone
				
				
				
				if (size == '214x92') {
					pos21492++;
					//afAd.setParam('pos', pos21492);
				}
				
				
				
				
				
				iframeSrcUrl = '/sites/all/modules/sikad/js/sikad-rf.html?sz=' + size + '&zone=' + this.zone + '&pos=' + pos21492 + '&articleid=' + this.artId + '&qc=' + qcString;
				
				
				
				sizeArr = size.split('x');
				
				document.write('<iframe src="' + iframeSrcUrl + '" width="' + sizeArr[0] + '" height="' + sizeArr[1] + '" scrolling="no" frameborder="0" marginwidth="0" marginheight="0"></iframe>');
				
				
				
				
				
				
				
			} else {
				//write_dart_tag();
				sizeArr = size.split('x');
				afAd = adFactory.getAd(sizeArr[0], sizeArr[1]);
				if (size == '214x92') {
					pos21492++;
					//c('pos21492 : ' + pos21492);
					afAd.setParam('pos', pos21492);
				}
				afAd.write();
			}
		}, // sik.ad.load()
		
		refresh_game: function() {
			// this is called somewhere externally
			rf_game = true;
		}  // sik.ad.refresh_game()
		
		
		
		
	
	};
}(); // sik.ad

