/**
 * Configuration setttings for the Gossip Widget
 * @returns A widgetSettings object
 * @type widgetSettings
 */
function configureGossipWidget(){
    ws = new widgetSettings();
    ws.widgetName="gossipWidget";
    ws.wtype="DynamicXSLTWidget";
    ws.xsl="../mngi/widgets/config/mngi/widgets/xsl/DynamicXSLT.xsl";
    ws.xml="http://extras.mnginteractive.com/live/xml/gossipwidget/gossip_feed.xml";
    ws.numberItems="5";
    ws.includeDescriptions="";
    ws.boxStyles="width: 279px !important; *width: 291px !important; padding: 5px !important; border: 1px solid rgb(153, 51, 0) !important;";
    ws.linkStyles="text-decoration: none !important; color: 993300 !important; font-family: arial; font-size: 12px !important; line-height: 1.231 !important;";
    ws.imageStyles="border: 0 !important; width: 60px !important; *height: 50px !important; float: left !important; margin-right: 5px !important; margin-bottom: 5px !important;";
    ws.headerLeftURL="http://extras.mnginteractive.com/live/media/widgets/gossip/TopHeader.gif";
    ws.headerLeftStyles="width: 291px !important; display: block !important; cursor: pointer !important;";
    ws.headerLeftALT="Gossip";
    ws.headerLeftClickURL="http://www.la.com/celebs_and_gossip";
    ws.headerRightURL="http://extras.mnginteractive.com/live/media/widgets/gossip/BottomHeader.gif";
    ws.headerRightStyles="width: 291px !important; display: block !important; cursor: pointer !important;";
    ws.headerRightALT="LA.com";
    ws.headerRightClickURL="http://www.la.com";    
    ws.addToMyStyles="margin-left: 98px !important; color: 3399ff !important; padding-right: 5px !important; font: bold 13px arial, helvetica, sans-serif !important;";
    ws.feedURLLink="http://extras.mnginteractive.com/live/xml/gossipwidget/gossip_feed.xml";
    ws.source="gossipWidget";
    
    return ws;
}

/**
 * Configuration settings for the Gossip Widget 160px Width Widget
 * @returns A widgetSettings object
 * @type widgetSettings
 */
function configureGossip160Widget(){
    ws = new widgetSettings();
    ws.widgetName="gossip160Widget";
    ws.wtype="DynamicXSLTWidget";
   	ws.xsl="../mngi/widgets/config/mngi/widgets/xsl/DynamicXSLT.xsl";
    ws.xml="http://extras.mnginteractive.com/live/xml/gossipwidget/gossip_feed.xml";    
    ws.numberItems="5";
    ws.boxStyles="width: 148px !important; *width: 160px !important; padding: 5px !important; border: 1px solid rgb(153, 51, 0) !important; display: block !important";
    ws.linkStyles="text-decoration: none !important; color: 993300 !important; font-family: arial, helvetica, sans-serif !important; font-size: 12px !important; line-height: 1.231 !important";
    ws.imageStyles="display: none !important;";
    ws.headerLeftURL="http://extras.mnginteractive.com/live/media/widgets/gossip/TopHeader160.gif";
    ws.headerLeftStyles="width: 160px !important; height: 21px !important; border: 0 !important; padding: 0 !important; display: block !important; cursor: pointer !important;";
    ws.headerLeftALT="Gossip - LA.com";
	ws.headerLeftClickURL="http://www.la.com/celebs_and_gossip";
	ws.headerRightURL="http://extras.mnginteractive.com/live/media/widgets/gossip/BottomHeader160.gif";
    ws.headerRightStyles="width: 160px !important; height: 19px !important; border: 0 !important; padding: 0 !important; display: block !important; cursor: pointer !important;";
    ws.headerRightALT="LA.com";
    ws.headerRightClickURL="http://www.la.com";
	ws.addToMyStyles="color: 3399ff !important; padding-right: 5px !important; font: bold 13px arial, helvetica, sans-serif !important;";
    ws.feedURLLink="http://extras.mnginteractive.com/live/xml/gossipwidget/gossip_feed.xml";
    ws.source="gossipWidget";
    
    return ws;
}


/**
 * Configuration setttings for the Breaking News Widget
 * @returns A widgetSettings object
 * @type widgetSettings
 */
function configureBreakingNewsWidget(){
    ws = new widgetSettings();
    ws.widgetName="breakingnewsWidget";
    ws.wtype="DynamicXSLTWidget";
    ws.xsl="../mngi/widgets/config/mngi/widgets/xsl/DynamicXSLT.xsl";
    ws.xml="http://feeds.mercurynews.com/mngi/rss/CustomRssServlet/568/200734.xml";
    ws.numberItems="5";
    ws.includeDescriptions="";
    ws.boxStyles="width: 279px !important; *width: 291px !important; padding: 5px !important; margin-bottom:7px !important; border: 1px solid rgb(7, 74, 141) !important;";
    ws.linkStyles="text-decoration: none !important; color: 074a8d !important; font-family: arial; font-size: 12px !important; line-height: 1.231 !important;";
    ws.imageStyles="display: none !important;";
    ws.headerLeftURL="http://extras.mnginteractive.com/live/media/widgets/breaking/GenericTopHeader.gif";
    ws.headerLeftStyles="width: 291px !important; display: block !important; cursor: pointer !important;";
    ws.headerLeftALT="Breaking News";
    ws.headerLeftClickURL="";
    ws.headerRightURL="http://extras.mnginteractive.com/live/media/widgets/breaking/GenericBottomHeader.gif";
    ws.headerRightStyles="width: 291px !important; display: block !important; cursor: pointer !important;";
    ws.headerRightALT="Breaking News";
    ws.headerRightClickURL="";    
    ws.addToMyStyles="margin-left: 98px !important; color: 074a8d !important; padding-right: 5px !important; font: bold 13px arial, helvetica, sans-serif !important;";
    ws.feedURLLink="";
	ws.source="breakingnewsWidget";
   
    return ws;
}


/**
 * Configuration setttings for the Breaking News 160px Widget
 * @returns A widgetSettings object
 * @type widgetSettings
 */
function configureBreakingNews160Widget(){
    ws = new widgetSettings();
    ws.widgetName="breakingnews160Widget";
    ws.wtype="DynamicXSLTWidget";
    ws.xsl="../mngi/widgets/config/mngi/widgets/xsl/DynamicXSLT.xsl";
    ws.xml="http://feeds.mercurynews.com/mngi/rss/CustomRssServlet/568/200734.xml";
    ws.numberItems="5";
    ws.includeDescriptions="";
    ws.boxStyles="width: 148px !important; *width: 160px !important; padding: 5px !important; margin-bottom:7px !important; border: 1px solid rgb(7, 74, 141) !important;";
    ws.linkStyles="text-decoration: none !important; color: 074a8d !important; font-family: arial; font-size: 12px !important; line-height: 1.231 !important;";
    ws.imageStyles="display: none !important;";
    ws.headerLeftURL="http://extras.mnginteractive.com/live/media/widgets/breaking/TopHeader160.gif";
    ws.headerLeftStyles="width: 160px !important; display: block !important; cursor: pointer !important;";
    ws.headerLeftALT="Breaking News";
    ws.headerLeftClickURL="";
    ws.headerRightURL="http://extras.mnginteractive.com/live/media/widgets/breaking/BottomHeader160.gif";
    ws.headerRightStyles="width: 160px !important; display: block !important; cursor: pointer !important;";
    ws.headerRightALT="Breaking News";
    ws.headerRightClickURL="";    
    ws.addToMyStyles="font-family: arial, helvetica, sans-serif !important; font-size: 12px !important; color: 074a8d !important; font-weight: bold !important; padding-right: 27px !important";
	ws.feedURLLink="";
	ws.source="breakingnews160Widget";
   
    return ws;
}


/**
 * Configuration settings for the DNC Widget
 * @returns A widgetSettings object
 * @type widgetSettings
 */
/*function configureDNCWidget(){
    ws = new widgetSettings();
    ws.widgetName="dncWidget";
    ws.wtype="DynamicXSLTWidget";
    ws.xsl="http://extras.mnginteractive.com/live/xsl/widget/dynxslt/DynamicXSLT.xsl";
    ws.xml="http://rss.denverpost.com/mngi/rss/CustomRssServlet/36/207301.xml";    
    ws.numberItems="8";
    ws.boxStyles="padding: 5px !important; border: 1px solid rgb(7, 74, 141) !important; display: block !important";
    ws.linkStyles="text-decoration: none !important; color: 074a8d !important; font-family: arial, helvetica, sans-serif !important; font-size: 12px !important; line-height: 1.231 !important";
    ws.imageStyles="display: none !important; border: 0 !important; width: 60px !important; height: 50px !important; float: left !important; margin-right: 5px !important; margin-bottom: 5px !important;";
    ws.headerLeftURL="http://extras.mnginteractive.com/live/media/widgets/dnc/TopHeader.gif";
    ws.headerLeftStyles="width: 291px !important; border: 0 !important; padding: 0 !important; display: block !important; cursor: pointer !important";
    ws.headerLeftALT="News from the Democratic National Convention";
    ws.headerLeftClickURL="http://www.politicswest.com";
    ws.headerRightURL="http://extras.mnginteractive.com/live/media/widgets/dnc/BottomHeader.gif";
    ws.headerRightStyles="width: 291px !important; border: 0 !important; padding: 0 !important; display: block !important; cursor: pointer !important";
    ws.headerRightALT="News from the Democratic National Convention";
    ws.headerRightClickURL="http://www.politicswest.com";    
    ws.addToMyStyles="font-family: arial, helvetica, sans-serif !important; font-size: 12px !important; color: 074a8d !important; font-weight: bold !important; padding-right: 5px !important";
    ws.feedURLLink="http://rss.denverpost.com/mngi/rss/CustomRssServlet/36/207301.xml";
    ws.source="dncWidget";
    
    return ws;
}*/

/**
 * Configuration settings for the DNC 160px Width Widget
 * @returns A widgetSettings object
 * @type widgetSettings
 */
/*function configureDNC160Widget(){
    ws = new widgetSettings();
    ws.widgetName="dnc160Widget";
    ws.wtype="DynamicXSLTWidget";
    ws.xsl="http://extras.mnginteractive.com/live/xsl/widget/dynxslt/DynamicXSLT160.xsl";
    ws.xml="http://rss.denverpost.com/mngi/rss/CustomRssServlet/36/207301.xml";    
    ws.numberItems="8";
    ws.boxStyles="padding: 5px !important; border: 1px solid rgb(7, 74, 141) !important; display: block !important";
    ws.linkStyles="text-decoration: none !important; color: 074a8d !important; font-family: arial, helvetica, sans-serif !important; font-size: 12px !important; line-height: 1.231 !important";
    ws.imageStyles="display: none !important; border: 0 !important; width: 60px !important; height: 50px !important; float: left !important; margin-right: 5px !important; margin-bottom: 5px !important;";
    ws.headerLeftURL="http://extras.mnginteractive.com/live/media/widgets/dnc/TopHeader160.gif";
    ws.headerLeftStyles="width: 160px !important; border: 0 !important; padding: 0 !important; display: block !important; cursor: pointer !important";
    ws.headerLeftALT="News from the Democratic National Convention";
    ws.headerLeftClickURL="http://www.politicswest.com";
    ws.headerRightURL="http://extras.mnginteractive.com/live/media/widgets/dnc/BottomHeader160.gif";
    ws.headerRightStyles="width: 160px !important; border: 0 !important; padding: 0 !important; display: block !important; cursor: pointer !important";
    ws.headerRightALT="News from the Democratic National Convention";
    ws.headerRightClickURL="http://www.politicswest.com";    
    ws.addToMyStyles="font-family: arial, helvetica, sans-serif !important; font-size: 12px !important; color: 074a8d !important; font-weight: bold !important; padding-right: 27px !important";
    ws.feedURLLink="http://rss.denverpost.com/mngi/rss/CustomRssServlet/36/207301.xml";
    ws.source="dncWidget";
    
    return ws;
}*/

/**
 * Configuration settings for the NYD - DNC Widget
 * @returns A widgetSettings object
 * @type widgetSettings
 */
/*function configureNYDWidget(){
    ws = new widgetSettings();
    ws.widgetName="nydWidget";
    ws.wtype="DynamicXSLTWidget";
    ws.xsl="http://extras.mnginteractive.com/live/xsl/widget/dynxslt/DynamicXSLT.xsl";
    ws.xml="http://rss.denverpost.com/mngi/rss/CustomRssServlet/36/207301.xml";    
    ws.numberItems="8";
    ws.boxStyles="width: 288px !important; padding: 5px !important; border: 1px solid rgb(7, 74, 141) !important; display: block !important";
    ws.linkStyles="text-decoration: none !important; color: 074a8d !important; font-family: arial, helvetica, sans-serif !important; font-size: 12px !important; line-height: 1.231 !important";
    ws.imageStyles="display: none !important; border: 0 !important; width: 60px !important; height: 50px !important; float: left !important; margin-right: 5px !important; margin-bottom: 5px !important;";
    ws.headerLeftStyles="display: none !important";
    ws.headerRightStyles="display: none !important";
    ws.addToMyStyles="font-family: arial, helvetica, sans-serif !important; font-size: 12px !important; color: 074a8d !important; font-weight: bold !important; padding-right: 5px !important";
    ws.feedURLLink="http://rss.denverpost.com/mngi/rss/CustomRssServlet/36/207301.xml";
    ws.source="dncWidget";
    
    return ws;
}*/


/**
 * Configuration settings for the RNC Widget
 * @returns A widgetSettings object
 * @type widgetSettings
 */
/*function configureRNCWidget(){
    ws = new widgetSettings();
    ws.widgetName="rncWidget";
    ws.wtype="DynamicXSLTWidget";
    ws.xsl="http://extras.mnginteractive.com/live/xsl/widget/dynxslt/DynamicXSLT.xsl";
    ws.xml="http://origin.feeds.twincities.com/mngi/rss/CustomRssServlet/569/206209.xml";    
    ws.numberItems="8";
    ws.boxStyles="padding: 5px !important; border: 1px solid rgb(7, 74, 141) !important; display: block !important";
    ws.linkStyles="text-decoration: none !important; color: 074a8d !important; font-family: arial, helvetica, sans-serif !important; font-size: 12px !important; line-height: 1.231 !important";
    ws.imageStyles="display: none !important; border: 0 !important; width: 60px !important; height: 50px !important; float: left !important; margin-right: 5px !important; margin-bottom: 5px !important;";
    ws.headerLeftURL="http://extras.mnginteractive.com/live/media/widgets/rnc/TopHeader.gif";
    ws.headerLeftStyles="width: 291px !important; border: 0 !important; padding: 0 !important; display: block !important; cursor: pointer !important";
    ws.headerLeftALT="News from the Republican National Convention";
    ws.headerLeftClickURL="http://www.twincities.com/rnc";
    ws.headerRightURL="http://extras.mnginteractive.com/live/media/widgets/rnc/BottomHeader.gif";
    ws.headerRightStyles="width: 291px !important; border: 0 !important; padding: 0 !important; display: block !important; cursor: pointer !important";
    ws.headerRightALT="News from the Republican National Convention";
    ws.headerRightClickURL="http://www.twincities.com/rnc";    
    ws.addToMyStyles="font-family: arial, helvetica, sans-serif !important; font-size: 12px !important; color: 074a8d !important; font-weight: bold !important; padding-right: 5px !important";
    ws.feedURLLink="http://origin.feeds.twincities.com/mngi/rss/CustomRssServlet/569/206209.xml";
    ws.source="rncWidget";
    
    return ws;
}*/

/**
 * Configuration settings for the RNC 160px Width Widget
 * @returns A widgetSettings object
 * @type widgetSettings
 */
/*function configureRNC160Widget(){
    ws = new widgetSettings();
    ws.widgetName="rnc160Widget";
    ws.wtype="DynamicXSLTWidget";
    ws.xsl="http://extras.mnginteractive.com/live/xsl/widget/dynxslt/DynamicXSLT160.xsl";
    ws.xml="http://origin.feeds.twincities.com/mngi/rss/CustomRssServlet/569/206209.xml";    
    ws.numberItems="8";
    ws.boxStyles="padding: 5px !important; border: 1px solid rgb(7, 74, 141) !important; display: block !important";
    ws.linkStyles="text-decoration: none !important; color: 074a8d !important; font-family: arial, helvetica, sans-serif !important; font-size: 12px !important; line-height: 1.231 !important";
    ws.imageStyles="display: none !important; border: 0 !important; width: 60px !important; height: 50px !important; float: left !important; margin-right: 5px !important; margin-bottom: 5px !important;";
    ws.headerLeftURL="http://extras.mnginteractive.com/live/media/widgets/rnc/TopHeader160.gif";
    ws.headerLeftStyles="width: 160px !important; border: 0 !important; padding: 0 !important; display: block !important; cursor: pointer !important";
    ws.headerLeftALT="News from the Republican National Convention";
    ws.headerLeftClickURL="http://www.twincities.com/rnc";
    ws.headerRightURL="http://extras.mnginteractive.com/live/media/widgets/rnc/BottomHeader160.gif";
    ws.headerRightStyles="width: 160px !important; border: 0 !important; padding: 0 !important; display: block !important; cursor: pointer !important";
    ws.headerRightALT="News from the Republican National Convention";
    ws.headerRightClickURL="http://www.twincities.com/rnc";    
    ws.addToMyStyles="font-family: arial, helvetica, sans-serif !important; font-size: 12px !important; color: 074a8d !important; font-weight: bold !important; padding-right: 27px !important";
    ws.feedURLLink="http://origin.feeds.twincities.com/mngi/rss/CustomRssServlet/569/206209.xml";
    ws.source="rncWidget";
    
    return ws;
}*/

/**
 * Configuration settings for the NYD - RNC Widget
 * @returns A widgetSettings object
 * @type widgetSettings
 */
/*function configureNYDRNCWidget(){
    ws = new widgetSettings();
    ws.widgetName="nydrncWidget";
    ws.wtype="DynamicXSLTWidget";
    ws.xsl="http://extras.mnginteractive.com/live/xsl/widget/dynxslt/DynamicXSLT.xsl";
    ws.xml="http://origin.feeds.twincities.com/mngi/rss/CustomRssServlet/569/206209.xml";    
    ws.numberItems="8";
    ws.boxStyles="width: 288px !important; padding: 5px !important; border: 1px solid rgb(7, 74, 141) !important; display: block !important";
    ws.linkStyles="text-decoration: none !important; color: 074a8d !important; font-family: arial, helvetica, sans-serif !important; font-size: 12px !important; line-height: 1.231 !important";
    ws.imageStyles="display: none !important; border: 0 !important; width: 60px !important; height: 50px !important; float: left !important; margin-right: 5px !important; margin-bottom: 5px !important;";
    ws.headerLeftStyles="display: none !important";
    ws.headerRightStyles="display: none !important";
    ws.addToMyStyles="font-family: arial, helvetica, sans-serif !important; font-size: 12px !important; color: 074a8d !important; font-weight: bold !important; padding-right: 5px !important";
    ws.feedURLLink="http://origin.feeds.twincities.com/mngi/rss/CustomRssServlet/569/206209.xml";
    ws.source="rncWidget";
    
    return ws;
}*/


/**
=======
>>>>>>> .r1684
 * Startup JavaScript to execute when this JS is included
 *
 */
var scripts = document.getElementsByTagName('script');
var slen = scripts.length;

for(s=0; s<slen; s++){
   var thisScript = scripts[s];
   if(thisScript.src && thisScript.src.indexOf("Servlet") == -1 && thisScript.src.indexOf("mngiWidget")!= -1){
      var prev = get_previoussibling(thisScript);
      if(prev && prev.src && prev.src.indexOf("Servlet")>-1)
         continue;
      else
      {
         var queryString = thisScript.src.replace(/^[^\?]+\??/,'');
         var params = parseQuery(queryString);
         if(params['mngiWidget']){
            genScriptTag(thisScript, params['mngiWidget']);
         }
      }
   }
}

/**
 * widgetSettings is a class to hold settings for a widget
 * @constructor
 */
function widgetSettings(){
    this.widgetName="";
    this.wtype="";
    this.xsl="";
    this.xml="";
    this.numberItems="";
    this.includeDescriptions="";
    this.boxStyles="";
    this.linkStyles="";
    this.imageStyles="";
    this.headerLeftURL="";
    this.headerLeftStyles="";
    this.headerLeftALT="";
    this.headerLeftClickURL="";
    this.headerRightURL="";
    this.headerRightStyles="";
    this.headerRightALT="";
    this.headerRightClickURL="";    
    this.addToMyStyles="";
    this.feedURLLink="";
    this.source="";

    /**
     * Get the current widget settings
     * @returns A string representing the widget settings, separated with ampersands
     * @type String
     */
    this.getWidgetSettings = function(){
        return this.wtype+"&"+
        "widgetName="+this.widgetName+"&"+
        "xsl="+this.xsl+"&"+
        "xml="+this.xml+"&"+
        "numberItems="+this.numberItems+"&"+
        "includeDescriptions="+this.includeDescriptions+"&"+
        "boxStyles="+this.boxStyles+"&"+
        "linkStyles="+this.linkStyles+"&"+
        "imageStyles="+this.imageStyles+"&"+
        "headerLeftURL="+this.headerLeftURL+"&"+
        "headerLeftStyles="+this.headerLeftStyles+"&"+
        "headerLeftALT="+this.headerLeftALT+"&"+
        "headerLeftClickURL="+this.headerLeftClickURL+"&"+
        "headerRightURL="+this.headerRightURL+"&"+
        "headerRightStyles="+this.headerRightStyles+"&"+
        "headerRightALT="+this.headerRightALT+"&"+
        "headerRightClickURL="+this.headerRightClickURL+"&"+        
        "addToMyStyles="+this.addToMyStyles+"&"+
        "feedURLLink="+this.feedURLLink+"&"+
        "source="+this.source;   
    };
}

/**
 * Get the previous sibling of the provided node
 * @param {Node} n A node in the DOM (element)
 * @returns A node representing the previous sibling of the provided
 * @type Node (element) 
 */
function get_previoussibling(n)
{
   x=n.previousSibling;
   while (x && x.nodeType!=1)
   {
      x=x.previousSibling;
   }
   return x;
}

/**
 * Generate and insert the script tag for this widget
 * @param {Node} insPoint The point at which to insert the widget
 * @param {String} wtype The type of widget to insert
 * @returns Nothing
 */
function genScriptTag(insPoint, wtype){
   //Instantiate and configure the widget
   try{
      eval("var widget = new configure"+wtype);
   }
   catch(e){
      return;
   }
   
   //Insert the widget
   var script = document.createElement("script");
   script.src = "http://widgets.mnginteractive.com/mngi/servletDispatch/GetWidgetServlet.dyn?widget="+widget.getWidgetSettings();   
   insPoint.parentNode.insertBefore(script, insPoint);
}

/**
 * Parse a query string and return the results as an object
 * @param {String} The query to parse
 * @returns An Object representing the params in the query string
 * @type Params
 */
function parseQuery (query) {
   var Params = new Object ();
   if (!query) return Params; // return empty object
   var Pairs = query.split(/[;&]/);
   for (var i = 0; i<Pairs.length; i++){
      var KeyVal = Pairs[i].split('=');
      if (!KeyVal || KeyVal.length != 2 ) continue;
      var key = unescape(KeyVal[0]);
      var val = unescape(KeyVal[1]);
      val = val.replace(/\+/g,' ');
      Params[key] = val;
   }
   return Params;
}




