ZiteFeed = {
	VERSION : 1
	, DAYS : ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
	, MONTHS : ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
	, init : function(defaultOptions) {
		this.defaultOptions = this._extend({title: "Get FREE Product Updates"},this._adjustOptions(defaultOptions));
		this.host = this.defaultOptions.host;
		this._setIds(this.defaultOptions.zfid);
		this.buttonTemplates = this._extend({
			yahoo: '<a href="http://add.my.yahoo.com/rss?url=${url}"><img src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif" width="91" height="17" border="0" alt="Add to My Yahoo!"><'+'/a>'
			, google: '<a href="http://fusion.google.com/add?source=atgs&feedurl=${url}"><img src="http://buttons.googlesyndication.com/fusion/add.gif" border="0" alt="Add to Google"><'+'/a>'
			, aol: '<a target="_blank" href="http://favorites.my.aol.com/ffclient/AddFeed?url=${url}" onclick="window.open('+"'http://favorites.my.aol.com/ffclient/AddFeed?url=${url}','aolAddFeed1224437773853','scrollbars=0,resizable=1,width=756,height=492,directories=0,menubar=0,location=0,status=0,toolbar=0'"+'); return false;" style="outline: none;"><img src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en_US/aol/images/myAOLButtonSmall.gif" alt="Add to myAOL" width="92" height="18" border="0"/><'+'/a>'
			, bloglines: '<a href="http://www.bloglines.com/sub/${url}"><img src="http://static.bloglines.com/images/sub_modern10.gif" border="0" alt="Subscribe with Bloglines" /><'+'/a>' 
			, netvibes: '<a href="http://www.netvibes.com/subscribe.php?url=${url}"><img src="http://www.netvibes.com/img/add2netvibes.gif" width="91" height="17" alt="Add to netvibes" /><'+'/a>'
			, newsgator: '<a href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=${url}"><img runat="server" src="http://www.newsgator.com/images/ngsub1.gif" alt="Subscribe in NewsGator Online" border="0" /><'+'/a>'
			, live: '<a href="http://www.live.com/?add=${url}"><img border="0" src="http://tkfiles.storage.msn.com/x1pHd9OYNP16fmmfqJHji7qY0yYomKrFzGROBps3O6qHF0JRlVV8xH6X4cfsptw0fftk5oJYFpTKP6I-i91-se8TaoO7R9oiPVoxDEG_LEZW_XhegHxASvHJYsSxNjf526t" style="width: 92px; height: 17px;"/><'+'/a>'
			, generic: '<a href="${url}"><img src="${host}/images/widgets/generic_feed_subscribe_button.gif" border="0" alt="Subscribe in your Feed Reader"><'+'/a>'
		},this.defaultOptions.buttonTemplates)
		this.lteIE6 = this._isLTEIE6();
		var cThis = this;
		this._observe(document.body,"click",function(evt){cThis._handleBodyClick(evt);});
		this._visibleWidgets = {}
	}
	, open : function(eLink,event,args) {
		event = this._normalizeEvent(event||window.event);
		event.stop();
		args = this._extend(this._extend(this._extend({},this.defaultOptions),{url:eLink.href}),args);
		if(eLink._ziteFeedWidgetId) {
			var eWidget = document.getElementById(eLink._ziteFeedWidgetId);
		} else {
			var eWidget = this._newSubscribeWidget(args);
			document.body.appendChild(eWidget);
			this._prepareSubscribeWidget(eWidget);
			eLink._ziteFeedWidgetId = eWidget.id;
		}
		this._showWidget(eLink,eWidget);
	}
	, hideVisibleWidgets : function() {
		for(var id in this._visibleWidgets) {
			if(this._visibleWidgets[id]) {
				this._hideWidget(id);
			}
		}
	}
	, _handleBodyClick : function(evt) {
		var element = evt.target;
		while(element) {
			if(/zitefeed_sub_widget/.test(element.className)) {
				return;
			}
			element = element.parentNode;
		}
		this.hideVisibleWidgets();
	}
	, _hideWidget : function(id) {
		document.getElementById(id).style.left = "-10000px";
		var ie6Shim = document.getElementById(id+"_shim");
		if(ie6Shim) {
			ie6Shim.style.left = "-10000px";
		}
		this._visibleWidgets[id] = false;
	}
	, _showWidget : function(eLink,eWidget) {
		var oOffset = this._bodyOffset(eLink);
		eWidget.style.top=(oOffset.top+eLink.offsetHeight+1)+"px";
		eWidget.style.left = (oOffset.left+2)+"px"; 
		if(document.getElementById(eWidget.id+"_shim")) {
			var ie6Shim = document.getElementById(eWidget.id+"_shim");
			ie6Shim.style.left = eWidget.style.left;
			ie6Shim.style.top = eWidget.style.top;
		}
		this._visibleWidgets[eWidget.id] = true;			
	}
	, _newSubscribeWidget : function(args) {
		var sUrl = args.url 
		var eWidget = document.createElement("div");
		eWidget.id = "zitefeed_sub_widget_"+(new Date().getTime());
		eWidget.className = "zitefeed_sub_widget";
		this._setStyle(eWidget,{left:"-10000px",position:"absolute",width:"210px",zIndex:"10000"});
		var sInner = "";
		sInner += '<div class="zitefeed_sub_widget_shadow" style="background-color:#000;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=20);height:100%;left:4px;opacity:0.2;position:absolute;top:4px;width:100%;"></div>'
		var buttonOpts = {host:'http://'+args.host,url:sUrl};
		sInner += '<div class="zitefeed_sub_widget_inner" style="position:relative;">'
			+ '<div class="zitefeed_sub_widget_heading"><strong>'+args.title+'</strong></div>'
			+ '<div class="zitefeed_sub_widget_content"><table>'
			+ '<tr>'+this._newButton("yahoo",buttonOpts) 			+ this._newButton("google",buttonOpts)+'<'+'/tr>'
			+ '<tr>'+this._newButton("aol",buttonOpts) 				+ this._newButton("live",buttonOpts)+'<'+'/tr>' 
			+ '<tr>'+this._newButton("bloglines",buttonOpts)	+ this._newButton("netvibes",buttonOpts)+'<'+'/tr>'
			+ '<tr>'+this._newButton("newsgator",buttonOpts)	+ this._newButton("generic",buttonOpts)+'<'+'/tr>'
			+ '</table></div>'
			+ '<div class="zitefeed_sub_widget_footer" style="background-image:url(http://'+args.host+'/images/ui/logo_tiny.gif?zfid='+(args.zfid||'')+')">Feeds By <a href="http://www.zitefeed.com">ZiteFeed</a></div>';
		eWidget.innerHTML = sInner;
		return eWidget;
	}
	, _prepareSubscribeWidget : function(eWidget) {
		if(this._isIE()) {
			if(this.lteIE6) {
				var ie6Shim = document.createElement('<div>')
				ie6Shim.innerHTML = '<iframe name="'+eWidget.id+'_shim" id="'+eWidget.id+'_shim" class="zitefeed_sub_widget_shim" style="border:none;height:'+eWidget.offsetHeight+'px;left:-10000px;position:absolute;width:'+eWidget.offsetWidth+'px;" frameborder="0" src="javascript:void();"></iframe>';
				document.body.appendChild(ie6Shim);					
			}
			var arrChildren = eWidget.getElementsByTagName("div");
			arrChildren[0].style.height = arrChildren[1].offsetHeight+"px";
		}
	}
	, _newButton : function(name,values) {
		sTemplate = this.buttonTemplates[name];
		if(sTemplate) {
			for(name in values) {
				sTemplate = sTemplate.replace(new RegExp("\\${"+name+"}","g"),values[name]);
			}
		}
		return '<td><span class="zitefeed_sub_button">'+sTemplate+'</span></td>';
	}
	, _isLTEIE6 : function() {
		if(window.attachEvent && !window.opera) {
			var matches = window.navigator.userAgent.match(/MSIE (\d+)/);
			if(matches && matches.length >= 2) {
				return parseInt(matches[1]) <= 6;
			}
		}
		return false;
	}
	, _isIE : function() {
		return window.attachEvent && !window.opera && /MSIE/.test(window.navigator.userAgent);
	}
	, _stopEvent : function(event) {
		if(event.preventDefault) event.preventDefault();
    if(event.stopPropagation) event.stopPropagation();
		event.returnValue = false;
		event.cancelBubble = true;
	}
	, _observe : function(element,name,handler) {
		var cThis = this;
		var fWrapper = function(evt){
			handler(cThis._normalizeEvent(evt||window.event));
		}
    if (element.addEventListener) {
      element.addEventListener(name, fWrapper, false);
    } else {
      element.attachEvent("on" + name, fWrapper);
    }			
	}
	, _bodyOffset : function(element) {
    var valueT = 0, valueL = 0;
    do {
      valueT += element.offsetTop  || 0;
      valueL += element.offsetLeft || 0;
      element = element.offsetParent;
    } while(element);
    return {left: valueL, top: valueT};
	}
	, _setStyle : function(element,styles) {
		this._extend(element.style,styles)
	}
	, _extend : function(target, extension) {
		if(extension) {
			for(key in extension) {
				target[key] = extension[key]
			}
		}
		return target;
	}
	, _normalizeEvent : function(evt) {
		if(typeof evt.target == 'undefined' && evt.srcElement) {
			evt.target = evt.srcElement;
		}
		evt._stopEvent = this._stopEvent;
		evt.stop = function() { this._stopEvent(this); }
		return evt;
	}
	, _setIds : function(zfid) {
		if(zfid) {
			match = zfid.match(/(\d+)_(\d+)/);
			if(match && match.length == 3) {
				this.accountId = parseInt(match[1]);
				this.siteId = parseInt(match[2]);
			}
		}
	}
	, trackConversion : function(value) {
		var params = "v="+this.VERSION+"&t="+encodeURIComponent(this._rfc822Date(new Date()));
		params += (typeof value != 'undefined' ? "&value="+encodeURIComponent(value) : '');
		var sUrl = window.location.protocol+"//"+this.host+"/accounts/"+this.accountId+"/sites/"+this.siteId+"/feeds/tracking/conversion.gif?"+params;
		var convImg = new Image(1,1);
		convImg.src = sUrl;
	}
	, _rfc822Date : function(date) {
		return this.DAYS[date.getUTCDay()]+', '+this._pad(date.getUTCDate())+' '+this.MONTHS[date.getUTCMonth()]+' '+date.getUTCFullYear()+' '
			+this._pad(date.getUTCHours())+':'+this._pad(date.getUTCMinutes())+":"+this._pad(date.getUTCSeconds())+' +0000'
	}
	, _pad : function(num) {
		return num > 0 && num < 10 ? '0'+num : num; 
	}
	, _adjustOptions : function(options) {
		if(window.location.protocol == 'https:') {
			options.host = 'www.zitefeed.com'
		}
		return options;
	}
};
(function() {
	document.write(
	'<style type="text/css">'
	+".zitefeed_sub_widget{\n background: #EEE;\n border: solid 1px #CCC;\n color: #222;\n font-family: Arial,sans-serif;\n font-size: 10px;\n font-style: normal;\n text-align: left;\n}\n"
	+".zitefeed_sub_widget a {\n color: #036;\n}\n"
	+".zitefeed_sub_widget a img{\nborder: none;\n}\n"
	+".zitefeed_sub_widget_heading{\n border-bottom: solid 1px #CCC;\n background: #EEE;\n font-size: 12px;\n padding: 1px;\n}\n"
	+".zitefeed_sub_widget_content{background: #FFF;\n padding: 5px 0;\n}\n"
	+".zitefeed_sub_widget_content table{\n border-collapse:collapse;\n}\n"
	+".zitefeed_sub_widget_content table td{\n padding:0;\n}\n"
	+".zitefeed_sub_widget_content .zitefeed_sub_button{\n padding: 1px 3px;\n }\n"
	+".zitefeed_sub_widget_footer{\n background: #EEE top right no-repeat;\n border-top: solid 1px #CCC;\n color: #222;\n font-size: 8pt;\n height: 14px;\n padding: 1px 30px 1px 1px;\n text-align: right;\n }\n"
	+"</style>"
	);
	var eScripts = document.getElementsByTagName("script");
	for(var i=0; i<eScripts.length; i++) {
		var match = eScripts[i].src.match(/:\/\/([^\/]*).*\/subscribe\.js\?zfid=(\d+_\d+)/);
		if(match && match.length == 3) {
			var host = match[1];
			var zfid = match[2];
			break;
		}
	}
	ZiteFeed.init({host:host,zfid:zfid});
})();
