var capwiz_plugin_6441 = {
	id: '6441',
	post_url: '',
    type: 'alert',
	json: {"width":"auto","plugin":{"fg":"#000000","font":{"primary":"sans-serif","fallback":"sans-serif"},"bg":"#FFFFFF","size":13},"alerts":[],"intro":"Read our Action Alerts and let your elected representatives know what you think. Easy, fast and it gets results!","name":"HOT ALERTS! TAKE ACTION NOW!","show_on_remote":"1","target":"capwiz_plugin_6441","text":"Read our Action Alerts and let your elected representatives know what you think. Easy, fast and it gets results!","empty_text":"There are no items presently associated with this plugin.","empty":"There are no items presently associated with this plugin.","plugin_width_type":"auto","items_per_page":"20","button":{"text":"Click to Take Action","fg":"#fa0505","font":{"primary":"sans-serif","fallback":"sans-serif"},"size":12,"bg":"#FFFFFF"},"header":{"fg":"#FFFFFF","font":{"primary":"sans-serif","fallback":"sans-serif"},"size":16,"bg":"#f23030"}}
}

var capwiz_init = 0; //run flag (so we only run initialize once)
var cwquery_loadtime_max = 10;

/* END: Capwiz plugin vars */

/*
 * On DOM ready
 * See: http://www.javascriptkit.com/dhtmltutors/domready.shtml
 */

var already_run_flag = 0;

if (document.addEventListener) { //Firefox and Opera
	document.addEventListener('DOMContentLoaded', function(){ already_run_flag = 1; if(capwiz_init == 0) init_capwiz_plugins(); }, false);
} else if (document.all && !window.opera) { //Internet Explorer
	document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>');
	var contentloadtag = document.getElementById("contentloadtag");
	contentloadtag.onreadystatechange = function() {
		if (this.readyState=="complete") { already_run_flag = 1; if(capwiz_init == 0) init_capwiz_plugins(); }
	}
}

window.onload = function() { setTimeout('if (!already_run_flag && !capwiz_init) init_capwiz_plugins()', 0); } //Fallback

/* END: On DOM ready */

/*
 * Initialize Capwiz Plugins
 */

if(typeof init_capwiz_plugins != 'function') {

	function init_capwiz_plugins() {
	
		//Set flag so we don't run again
		capwiz_init = 1;			
		
		//Load cwQuery
		load_cw_query();
		
		//Pass control to function that checks if cwQuery has loaded
		check_cwquery_loaded();	
	}

}

/* END: On DOM ready */

/*
 * Load cwQuery
 */

if(typeof load_cw_query != 'function') {

	function load_cw_query() {
	
		//Create script element
		var head = document.getElementsByTagName('head')[0];
		var cwQueryElement = document.createElement('script');
			
		//Set script to load cwQuery from ffs
		cwQueryElement.type = 'text/javascript';
		cwQueryElement.src = 'https://secureffs.capwiz.com/DHTML/cwquery.min.js';
		
		//Apend to head
		head.appendChild(cwQueryElement);
	
	}

}

/*
 * Check that cwQuery is loaded before continuing
 */

if(typeof check_cwquery_loaded != 'function') {

	function check_cwquery_loaded() {	
		
		//If load time has exceeded, exit
		if(cwquery_loadtime_max < 0) return;
	
		if(!window.cwQuery) { //Keep trying periodically (every 0.5 secs)
			t = setTimeout('check_cwquery_loaded()', 500);
		} else { //Continue with plugin build
		
			cwquery_noconflict();
			render_capwiz_plugin();
		}
		
		//Decrease loadtime counter
		cwquery_loadtime_max--;
	
	}

}

/* END: cwQuery check */

/* END: Load cwQuery */

/*
 * Set noconflict for cwQuery
 */

if(typeof cwquery_noconflict != 'function') {

	function cwquery_noconflict() {
	
		var head = document.getElementsByTagName('head')[0];
		var cwquery_noconflict = document.createElement('script');
		
		//Set noconflict directive
		cwquery_noconflict.type = 'text/javascript';
		cwquery_noconflict.text = '$cwQ = cwQuery.noConflict();';
		
		//Append to head
		head.appendChild(cwquery_noconflict);
	
	}

}

/* END: Load cwQuery */

/*
 * Render plugins
 */

if(typeof render_capwiz_plugin != 'function') {

	function render_capwiz_plugin() {			

		//Get all capwiz plugin elements
		$plugins = $cwQ('div[id^="capwiz_plugin_"]');
		
		$plugins.each(function(i) {
		
			//Get unique id
			var plugin_id = $cwQ(this).attr('id').split('_')[2];
			
			//Get unique id
			var this_plugin = window['capwiz_plugin_' + plugin_id];

			//Create plugin
			switch(this_plugin.type) {
				case 'alert':
					capwiz_alert_plugin($cwQ(this), this_plugin);
					break;
				case 'register':
					capwiz_register_plugin($cwQ(this), this_plugin);
					break;
				default:
					alert('No type specified');
					break;
			}
			
		});
		
	}

}

/* END: Render plugins */


/*
 * Alerts plugin
 */
 
if(typeof capwiz_alert_plugin != 'function') {

	function capwiz_alert_plugin($container, plugin_obj) {
		
		//Get attributes for plugin
		var plugin = plugin_obj.json;
		
		//Create CSS styles			
		var css = {
			
			reset: 'margin:0;padding:0;text-transform:none;font-weight:400;list-style:none;text-decoration:none;font-size:1em;line-height:1.25em;position:static',
			base: {
				wrapper: '',
				header: 'padding:1em 10px;font-weight:700;border:1px solid #ccc',
				content: {
					wrapper: 'padding:1em 10px;border:1px solid #ccc;border-top:0',
					intro: 'margin-bottom:1em;',
					button: 'font-weight:700;padding:5px;display:inline-block;-moz-border-radius: 3px;-webkit-border-radius: 3px;border-radius: 3px',
					alert: {
						h2: 'font-weight:700',
						li: 'padding-bottom: 1em;',
						p: 'margin: 0.25em 0'
					},
					pagination: {
						wrapper: 'padding-top:1em',
						li: 'display:inline;margin-right:2px',
						link: 'display:inline-block;padding:1px 3px;background:#69747C;color:#fff;font-weight:700'
					}
				},
				footer: ''
			}
			
		};
		
		//Create blank HTML structure
		var html = {
			
			wrapper: '',
			header: '',
			content: {
				wrapper: '',
				intro: '',
				alerts: {
					wrapper: '',
					list: '',
					pagination: ''
					}
				},
			footer: '',
			close: ''
		};
			
		//Add px unit to width and make sure we are wider than 100
		if(plugin.width != 'auto') {
			if(plugin.width < 100) plugin.width = 100;
			plugin.width += 'px';
		}
			
		//Styles for plugin wrapper
		var wrapper_css =
			'width:'		+ plugin.width;
			
		//Styles for plugin content
		var content_css =
			'background:'	+ plugin.plugin.bg + ';' +
			'color:'		+ plugin.plugin.fg + ';' +
			'font-family:'	+ plugin.plugin.font.primary + ',' + plugin.plugin.font.fallback + ';' +
			'font-size:'	+ plugin.plugin.size + 'px';
			
		//Styles for header
		var header_css =
			'background:'	+ plugin.header.bg + ';' +
			'color:'		+ plugin.header.fg + ';' +
			'font-family:'	+ plugin.header.font.primary + ',' + plugin.header.font.fallback + ';' +
			'font-size:'	+ plugin.header.size + 'px';
			
		//Styles for button
		var button_css =
			'background:'	+ plugin.button.bg + ';' +
			'color:'		+ plugin.button.fg + ';' +
			'font-family:'	+ plugin.button.font.primary + ',' + plugin.button.font.fallback + ';' +
			'font-size:'	+ plugin.button.size + 'px';
		
		//Build HTML for alerts plugin
		html.wrapper				= '<div class="capwiz-plugin-wrapper" style="' + css.reset + ';' + wrapper_css + ';' + css.base.wrapper + '">';
		html.header					= '<div class="capwiz-plugin-header" style="' + css.reset + ';' + header_css + ';' + css.base.header + '">' + plugin.name + '</div>';
		html.content.wrapper		= '<div class="capwiz-plugin-content" style="' + css.reset + ';' + content_css + ';' + css.base.content.wrapper + '">';
		html.content.intro			= (plugin.intro != null) ? '<p class="capwiz-plugin-intro" style="' + css.reset + ';' + content_css + ';' + css.base.content.intro + '">' + plugin.intro + '</p>' : '';
		html.content.alerts.wrapper = '<ul class="capwiz-plugin-list" style="' + css.reset + ';' + content_css + '">';
		html.close					= '</ul></div></div>';
			
		//If we have alerts
		if(plugin.alerts.length > 0) {
		
			//Loops for alerts
			for(var x = 0;x < plugin.alerts.length;x++) {
						
				html.content.alerts.list += '<li style="' + css.reset + ';' + content_css + ';' + css.base.content.alert.li + '">';
				html.content.alerts.list += '<h2 style="' + css.reset + ';' + content_css + ';' + css.base.content.alert.h2 + '">' + plugin.alerts[x].title + '</h2>';
				html.content.alerts.list += '<p style="' + css.reset + ';' + content_css + ';' + css.base.content.alert.p + '">' + plugin.alerts[x].subtitle + '</p>';
				html.content.alerts.list += '<p style="' + css.reset + ';' + content_css + '"><a href="' + plugin.alerts[x].url + '" style="' + css.reset + ';' + button_css + ';' + css.base.content.button + '">' + plugin.button.text + '</a></p>';
				html.content.alerts.list += '</li>';
			
			}
		
		} else { //Display empty list message
		
			html.content.alerts.wrapper = '<p style="' + css.reset + ';' + content_css + '"><i>' + plugin.empty_text + '</i></p>';
		
		}			
			
		//Form final plugin html
		var plugin_html = html.wrapper + html.header + html.content.wrapper + html.content.intro + html.content.alerts.wrapper + html.content.alerts.list + html.close;
			
		//Render plugin
		$container.attr('style',css.reset).html(plugin_html);
			
		//Create pagination
		capwiz_plugin_pagination($container.find('.capwiz-plugin-list'), plugin.items_per_page, css);
		
	}
	
}

/*
 * Build Pagination
 */
 
if(typeof capwiz_plugin_pagination != 'function') {
 
	function capwiz_plugin_pagination($list, per_page, css) {

		//Convert per_page value to int
		per_page = parseInt(per_page);
		
		//Get number of children elements
		var children = $list.children('li').length;
		
		//Calculate how many pages
	    var pages = Math.ceil(children / per_page);
	    
	    //If we have more than 1 page
	    if (pages > 1) {
	    
	    	//Show first page of results
	        $list.find('> li').hide().slice(0, per_page).show();
	        
	        //Create pagination wrapper
	        $cwQ('<div class="capwiz-plugin-pagination" style="' + css.reset + ';' + css.base.content.pagination.wrapper + '"><ul style="' + css.reset + '"></ul></div>').insertAfter($list);
	        
	        //Save pagination ul for reference
	        var pagination_wrapper = $list.next('div.capwiz-plugin-pagination').find('> ul');
	        
	        //Loop through pages to create pagination links
	        for (var d = 1; d <= pages; d++) {
	        
	        	//Create link and attach click functionality
	            $cwQ('<li style="' + css.reset + ';' + css.base.content.pagination.li + '"><a href="#" style="'+ css.reset + ';' + css.base.content.pagination.link + '">' + d + '</a></li>')
	            	.attr('rel', 'p' + d)
	            	.appendTo(pagination_wrapper)
	            	.find('a').click(function (e) {
	                
	                	//Calculate page to show
	                	var j = $cwQ(this).html() - 1;
	                	var i = j * per_page;
	                	var h = i + per_page;
	                
	                	//Show correct page
	                	$list.find('> li').hide().slice(i, h).show();
	                
	                	//Reset all link bg to default
	                	pagination_wrapper.find('a').css('background','#69747C');
	                
	                	//Set this link background color as active
	                	$cwQ(this).css('background','#333');
	                
	                	//Prevent default href
	                	e.preventDefault();
	                	
	            	});
	            	
	        }
	        
	        //Set first pagination link as active
	        pagination_wrapper.each(function() {
	            $cwQ(this).find("li:first a").css('background','#333');
	        });
	        
	    }
	
	}
	
}
