"use strict";
(function ($) {
    rsswidget = {
    init : function () {
        rsswidget.show();
        if($.browser.msie) 
		rsswidget.loadsrc();
	
	else
		setTimeout("rsswidget.loadsrc()",5000);
		
        },

    show : function () {

        $('iframe.rsswidget').load(function() {
	    var iframeId = this.id;
        var divId = $("#" + this.id).attr("divId");
        var htmlstr ="";
        var hasChild = $("#" + this.id).attr("hasChild");
        var postProcess = $("#" + this.id).attr("postProcess");
        var feedUrl = $("#" + this.id).attr("feedUrl");
        var xslurl = $("#" + this.id).attr("xslurl");
	    var viewAll = $("#" + this.id).attr("viewAll");		
        $.get(xslurl, function(data){
            var iframeEl = document.getElementById(iframeId);
            var nofeedmsg = escape($("#" + divId).find("div.nofeedmsg").html());
		    nofeedmsg = (nofeedmsg != "" && nofeedmsg != "undefined") ? nofeedmsg : "Either information is unavailable for this product or JavaScript is disabled in your browser.";
		    divId = (hasChild == "true") ? $("#" + divId).find("div").attr("id",divId + "content-panel").get(0).id : divId;
            var htmlstr = escape($("#" + divId).html());
		    document.domain = "intel.com";
            $("#" + divId).html("");
		    iframeEl.contentWindow.rss_proxy.setUrl(feedUrl,data,divId);
            rsswidget.postProcessing(divId,postProcess,htmlstr,viewAll,nofeedmsg);
 	        }); 
        });
     },
     loadsrc : function () {
        $("iframe.rsswidget").each(function (i) {
		    $('#'+this.id).attr('src', "http://inside.intel.com/static/portal/FeedFrame.htm");
		     
         });
     },
    postProcessing : function (divId,postProcess,htmlstr,viewAll,nofeedmsg){     
     
		if ($("#" + divId).html() != "")
		 {		
			//Intel.mod.multiOpenPaginatePostFeed.init();  -- Pagination stuff
			var retvalue = eval('(' + $("#" + divId).find("div[id='postback']").html() + ')');	

			if (parseInt(retvalue.rowcount)== 0)
				$("#" + divId).html(unescape(nofeedmsg));
				if (postProcess == "true")
					$("#" + divId.replace("content-panel","")).find(retvalue.elementtype + "." + retvalue.classname).html(retvalue.value);
		
				if (viewAll != "" && viewAll != "undefined")
				{
					$("#" + divId).find("a.view-all-link").attr("href",viewAll);
					setViewAll(divId);  
				}  
				if (retvalue.elementtype == "blogs")
					Intel.mod.tickerSelect();

			return; 
		}
		else
		{	   
			//console.log("Set Timeout called");
			setTimeout( "rsswidget.postProcessing('" + divId + "','" + postProcess + "','" + htmlstr + "','" + viewAll + "','" + nofeedmsg + "')",1000);	
		}    

	}

    };

}(jQuery));

jQuery(document).ready(function () {
    setTimeout("rsswidget.init()",1000);
	    
		 
});

