/*if(typeof eventId == "undefined") {
    var eventId = 11736;
}*/
if(typeof eventId != "undefined") {
    if(eventId == 23390) { // hack for fox sports tiger wood's event (http://msn.foxsports.com/golf/story/10455648)
        var useAkamai   = true;
        var enableMedia = false;
    }
    if(eventId == 176748) { // hack for msnbc health care event (http://www.msnbc.msn.com/id/35563300)
        var useAkamai   = true;
        var enableMedia = true;
        var tab1fn = '5682';
        var tab2fn = '5683';
        var tab3fn = '6022';
        var shareLink = false;
        var enableTrendsOnly = true;
    }
    if(eventId == 228001) {
        var useAkamai = true;
    }
}
if(typeof publisherId == "undefined") {
    var publisherId = 0;
}
if(typeof width == "undefined") {
    var width = 300;
}
if(typeof height == "undefined") {
    var height = 600;
}
if(typeof baseStyle == "undefined") {
    var baseStyle = "black";
}
if(typeof interactionBox == "undefined") {
    var interactionBox = "bottom";
}
if(typeof showTitle == "undefined") {
    var showTitle = false;
}
if(typeof shareLink == "undefined") {
    var shareLink = true;
}
if(typeof refreshLink == "undefined") {
    var refreshLink = true;
}
if(typeof twitterLogo == "undefined") {
    var twitterLogo = true;
}
if(typeof enableMedia == "undefined") {
    var enableMedia = true;
}
if(typeof enableTrendsOnly == "undefined") {
    var enableTrendsOnly = false;
}
if(typeof enableNews == "undefined") {
    var enableNews = false;
}
if(typeof mediaHeight == "undefined") {
    var mediaHeight = 160;
}
if(typeof enableEventSelector == "undefined") {
    var enableEventSelector = false;
}
if(typeof bottomInfo == "undefined") {
    var bottomInfo = false;
}
if(typeof roundCorners == "undefined") {
    var roundCorners = false;
}
if(typeof brandLogo == "undefined") {
    var brandLogo = "";
}
if(typeof hashTag == "undefined") {
    var hashTag = "";
}
if(typeof bgImage == "undefined") {
    var bgImage = "";
}
if(typeof bgColor == "undefined") {
    var bgColor = "";
}
if(typeof paneBgColor == "undefined") {
    var paneBgColor = "";
}
if(typeof fontColor == "undefined") {
    var fontColor = "";
}
if(typeof linkColor == "undefined") {
    var linkColor = "";
}
if(typeof interactionBoxColor == "undefined") {
    var interactionBoxColor = "";
}

if(typeof useTabs == "undefined") {
    var useTabs = false;
}
if(typeof defaultTab == "undefined") {
    var defaultTab = 1;
}
if(typeof tab1 == "undefined") {
    var tab1 = "";
}
if(typeof tab1fn == "undefined") {
    var tab1fn = "all";
}
if(typeof tab1group == "undefined") {
    var tab1group = "";
}
if(typeof tab2 == "undefined") {
    var tab2 = "";
}
if(typeof tab2fn == "undefined") {
    var tab2fn = "featured";
}
if(typeof tab2group == "undefined") {
    var tab2group = "";
}
if(typeof tab3 == "undefined") {
    var tab3 = "";
}
if(typeof tab3fn == "undefined") {
    var tab3fn = "";
}
if(typeof tab3group == "undefined") {
    var tab3group = "";
}
if(typeof tab4 == "undefined") {
    var tab4 = "";
}
if(typeof tab4fn == "undefined") {
    var tab4fn = "";
}
if(typeof tab4group == "undefined") {
    var tab4group = "";
}
if(typeof tab5 == "undefined") {
    var tab5 = "";
}
if(typeof tab5fn == "undefined") {
    var tab5fn = "";
}
if(typeof tab5group == "undefined") {
    var tab5group = "";
}
if(typeof tab6 == "undefined") {
    var tab6 = "";
}
if(typeof tab6fn == "undefined") {
    var tab6fn = "";
}
if(typeof tab6group == "undefined") {
    var tab6group = "";
}

if(typeof subtab1 == "undefined") {
    var subtab1 = "All";
}
if(typeof subtab1fn == "undefined") {
    var subtab1fn = "all";
}
if(typeof subtab2 == "undefined") {
    var subtab2 = "Photos";
}
if(typeof subtab2fn == "undefined") {
    var subtab2fn = "photos";
}
if(typeof subtab3 == "undefined") {
    var subtab3 = "Videos";
}
if(typeof subtab3fn == "undefined") {
    var subtab3fn = "videos";
}
if(typeof subtab4 == "undefined") {
    var subtab4 = "Trends";
}
if(typeof subtab4fn == "undefined") {
    var subtab4fn = "trends";
}
if(typeof clickThroughURL == "undefined") {
    var clickThroughURL = "";
}
if(typeof useAkamai == "undefined") {
    var useAkamai = false;
}
if(typeof enableAd == "undefined") {
    var enableAd = false;
}
if(typeof enableExtraTrends == "undefined") {
    var enableExtraTrends = false;
}
if(typeof autoRefreshSpeed == "undefined") {
    var autoRefreshSpeed = 7000;
}
if(typeof eventCategory == "undefined") {
    var eventCategory = "";
}
if(typeof skipInitialVideo == "undefined") {
    var skipInitialVideo = false;
}
if(typeof topBox == "undefined") {
    var topBox = true;
}
if(typeof tabColor == "undefined") {
    var tabColor = "";
}
if(typeof selectedTabColor == "undefined") {
    var selectedTabColor = "";
}
if(typeof enableMap == "undefined") {
    var enableMap = false;
}
/*
 * Tracking Vars
 * 
  var appid = 0;
  var devid = 0;
  var mid = 0;
  var iid = 0;
  var pubid = 0;
  var pv = 0;
  var sess = 0;
  var idtype = "t";
  var adTile = 0;
  var refer = 0;
  var view = 0;
*/

var widgetReferrer = window.location.href;

var configvars = [ 'width', 'height', 'baseStyle', 'showTitle', 'useTabs', 'defaultTab',
 'shareLink','refreshLink','enableMedia', 'enableNews', 'mediaHeight', 'enableEventSelector', 'brandLogo', 'bottomInfo',
 'roundCorners', 'interactionBox', 'hashTag', 'bgImage', 'bgColor', 'paneBgColor',
 'fontColor', 'linkColor', 'publisherId', 'tab1', 'tab1fn', 'tab1group', 'tab2',
 'tab2fn', 'tab2group', 'tab3', 'tab3fn', 'tab3group','tab4', 'tab4fn', 'tab4group','tab5', 'tab5fn',
 'tab5group','tab6', 'tab6fn', 'tab6group', 'eventId', 'subtab1', 'subtab1fn',
 'subtab2', 'subtab2fn', 'subtab3', 'subtab3fn', 'subtab4', 'subtab4fn',
 'clickThroughURL', 'useAkamai', 'enableAd', 'akamaiUrl', 'apiUrl', 'autoRefreshSpeed', 'language',
 'appid', 'devid', 'mid', 'iid', 'pubid', 'pv', 'sess', 'idtype', 'adTile', 'refer', 'view', 'widgetId', 'eventCategory', 
 'enableExtraTrends', 'skipInitialVideo', 'topBox', 'interactionBoxColor', 'enableTrendsOnly',
 'tabColor', 'selectedTabColor','twitterLogo', 'widgetReferrer', 'enablePosts', 'enablePhotos', 'enableVideos', 'enableTrends', 'enableMap',
 'scrollTop', 'scrollBottom', 'scrollWidth', 'scrollBgColor', 'scrollBarColor','timeColor','mapBorderColor','mapLegendBgColor',
 'mapLegendBgImg','mapDensitySolidColor','mapDensityLightColor','selectedStateColor', 'enableSplashImg', 'splashImgTime',
 'splashImg','enableSmVideo', 'smVideo', 'paneTopMargin', 'paneBottomMargin', 'paneLeftMargin', 'paneRightMargin', 'paneBorderColor',
 'enableAuthorImgs', 'optionsTop', 'optionsRight', 'viewMapBtnLeft', 'viewMapBtnTop', 'showTitleImg', 'showCategoryName', 'customParam']


var gParams = '';
for (var i in configvars) {
    var name = configvars[i];
    if (typeof window[name] != "undefined") {
        if (gParams) gParams += '&';
        gParams += name +"="+encodeURIComponent(window[name]);
    }
}


var widgetHost = 'http://www4.tinker.com/standard/';

// DEBUG
//widgetHost = 'http://mapunit.tinker.com/'
//if(console.log) {console.log("ALERT:: widgetHost: " + widgetHost)}


if (enableMap) {
///////////////////////////////////
// IFRAME RESIZE CODE (FOR MAP) 
//////////////////////////////////
	var gResizeHeight;
	var gResizeWidth;
	
	function iframeResizeSetup() {
		if (window.addEventListener) {
			window.addEventListener('message', receiveMessage, false);
		} else { //IE 8
			window.attachEvent('onmessage', receiveMessage);
		}
	
		var initialHeight = height;
		var initialWidth = width;
		
		/* find image from this domain */
		var loc = window.location.href;
		var loc = loc.substring(0,loc.indexOf('/',8) + 1);
	
		for (var i=0;i<document.images.length;i++) {
			var image = document.images[i];
			if (image.src.indexOf('?') > -1) {
				continue;
			}
			var iloc = image.src;
			iloc = iloc.substring(0,iloc.indexOf('/',8) + 1);

			if (iloc == loc) {
				gParams += '&ifrImg=' + encodeURIComponent(image.src);
				continue;
			}
		}
		/* create glam widget Iframe */
		try {
			  var tempIFrame=document.createElement('iframe');
			  tempIFrame.setAttribute('id','glamIframe');
			  tempIFrame.setAttribute('name','glamIframe');
			  tempIFrame.setAttribute('src', widgetHost + 'widget_sm.html?' + gParams);
			  tempIFrame.setAttribute('allowTransparency','true');
			  tempIFrame.setAttribute('frameBorder', '0'); //IE is case-sensitive, need capital 'B'
			  tempIFrame.setAttribute('marginheight', '0');
			  tempIFrame.setAttribute('marginwidth', '0');
			  tempIFrame.setAttribute('hspace', '0');
			  tempIFrame.setAttribute('vspace', '0');
			  tempIFrame.setAttribute('scrolling', 'no');
			  tempIFrame.setAttribute('height', initialHeight);
			  tempIFrame.setAttribute('width', initialWidth);
			  tempIFrame.style.border = '0px';
			  tempIFrame.style.width = initialWidth + 'px';
			  tempIFrame.style.height = initialHeight + 'px';
			  var IFrameObj = document.getElementById('tinkerWidget');
			  IFrameObj.appendChild(tempIFrame);
		} catch(e) {
			//if (window.console) console.log(e);
		}	
		/* poll for helper iframe location if browser doesn't support postMessage */
		function pollIfr() {
			try {
				var hiddenIfr = window.frames.glamIframe.frames.rpcIframe;
				var ifr = document.getElementById('glamIframe');
				if (hiddenIfr && hiddenIfr.location.hash) {
					var resizeDim = hiddenIfr.location.hash.slice(1).split('x');
					gResizeWidth = parseInt(resizeDim[0]);
					gResizeHeight = parseInt(resizeDim[1]);
				} 
				var h = parseInt(ifr.style.height);
				var w = parseInt(ifr.style.width);
				if (gResizeHeight != h || gResizeWidth != w) {
					ifr.style.height = window.gResizeHeight + 'px';
					ifr.style.width = window.gResizeWidth + 'px';
				}
			} catch(e) {
				//if (window.console) console.log('Error = ' + e.description); 
			}
		}
		if (!window.postMessage) {
			var sizePoll = window.setInterval(pollIfr, 200);
		}
	}
	
	function receiveMessage(event) { //postmessage for more current browsers
		msgs = event.data.split(';'); //make sure we're not receiving a different postmessage
		if (msgs.length == 3 && msgs[0] == 'tinkerWidget') {
			window.gResizeHeight = msgs[1];
			window.gResizeWidth = msgs[2];
			document.getElementById('glamIframe').style.height = window.gResizeHeight + 'px';
			document.getElementById('glamIframe').style.width = window.gResizeWidth + 'px';
		}
	}
}
gParams += "&r=" + Math.random();

if (enableMap) {
	document.write('<div id="tinkerWidget"></div>');
	iframeResizeSetup();
} else { // no map
	document.write('<iframe src="'+widgetHost+'widget_sm.html?' + gParams + '" width="'+width+
    '" height="'+height+'" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowTransparency="true"></iframe>');
}


