/**
 * ehhrWidget
 *
 * Creates a div where the script tags exist
 * within the host page. This div uses an onclick
 * function to write an overlay div into the host
 * page. The Overlay div can be given settings
 * of an image URL and and alt tag for the image.
 * The overlay contains a button to remove itself
 * from the host page.
 *
 * @function		ehhrWidget
 * @author			Start Creative
 * @creator			Matthew Lane
 * @copyright		Start Creative, 2008
 */
	function closeWidget(){
		//getElementById("ehhr-widget").style.display == "none";
		$("#ehhr-widget").remove();
	}

var ehhrWidget = {
	/**
	 * @var Object
	 */
	options: null,
	/**
	 * init
	 * 
	 * Create options object. JQuery's extend method
	 * takes the first parameter and overwrites any
	 * duplicate keys with values from the second paramater
	 * 
	 * @param	settings	Object
	 * @return	Void
	 */
	init: function(settings) {
		options = jQuery.extend({
			src:	"",
			link:	"",
			ident: "&ident=downloaded",
			buttonWidth: "200"
		}, settings);
		
		// Private options
		options.width 		= "420";
		options.height 		= "560";
		options.iframeSrc	= "http://www.everyhumanhasrights.org/widget/sign_up_step_one/?";
		// Create a div within the DOM with the id of "ehhr-widget-button"
		
		var id = "ehhr-widget-button";
		//document.write('<div id="' + id + '" style="width:100%;background:#C60C30;cursor:pointer;"></div>');
		
		// Get the new DOM element via standard DOM call and wrap in jQuery
		//var root = document.getElementById(id);
		
		
		//var widget_button = $(root);
		var widget_button = $("#ehhr-widget-holder");
		
		var hostname = location.hostname;
		
		
		if(options.buttonWidth < 201){
			// Write the HTML content into "ehhr-widget-button"
			widget_button.html(
				// Inline styles are used to avoid conflicts with host page
				'<div style="padding:10px 10px 0 10px;background:#C60C30;cursor:pointer;border-bottom:10px solid #C60C30;#border-bottom:20px solid #C60C30"><img src="http://www.everyhumanhasrights.org/images/common/widget_ehhr_logo_large.jpg" width="180" height="228" alt="Every Human Has Rights" style="margin-bottom:10px;" /><p style="color:#FEFBF2;font-size:100%;font-weight:bold;padding:20px 10px 20px 10;">2008 is the 60th anniversary of the Declaration of Human Rights. Pledge to embrace its values and goals today.</p><img src="http://www.everyhumanhasrights.org/images/common/sign_up.gif" width="98" height="29" alt="Sign up now" style="display: block;float:right;margin:0 20px 20px 0" /><br style="clear:both;" /></div>'
			);
		} else if(options.buttonWidth > 201){
			widget_button.html(	
				// Inline styles are used to avoid conflicts with host page
				'<div style="padding:10px 10px 0 10px;background:#C60C30;cursor:pointer;border-bottom:10px solid #C60C30;#border-bottom:20px solid #C60C30"><img src="http://www.everyhumanhasrights.org/images/common/widget_ehhr_logo.jpg" width="108" height="136" alt="Every Human Has Rights" style="float:left;display:inline;#margin-bottom:10px;" /><p style="color:#FEFBF2;font-size:100%;font-weight:bold;padding:20px 10px 20px 128px;">2008 is the 60th anniversary of the Declaration of Human Rights. Pledge to embrace its values and goals today.</p><img src="http://www.everyhumanhasrights.org/images/common/sign_up.gif" width="98" height="29" alt="Sign up now" style="display: block;float:right;margin:0 20px 20px 0" /><br style="clear:both;" /></div>'
			);
		}
		

		// Onclick write in the div and iframe into the documents body
		widget_button.click(function(){
			if(!$("#ehhr-widget").length) {
				$("body").append('<div id="ehhr-widget" style="position: absolute; top: 30%; left: 0; z-index: 100; width:  100%; height: 550px;"><p><a href="#" id="close" style="background: url() 100% 3px no-repeat; color: #000000; font-size: 0.8em; text-decoration: none; position: relative; top: 50px; left: 160px;" onclick="javascript:closeWidget()">Close<img src="http://www.everyhumanhasrights.org/images/common/widget_close.gif" style="padding: 0 0 0 5px" /></a></p><iframe src="' + options.iframeSrc + "src=" + options.src + "\&link=" + options.link + "\&ident=" + options.ident + "\&decl=" + options.ident +"\&hostname="+ hostname + '" name="ehhr-iframe" style="z-index:100;" scrolling="no" height="' + options.height + 'px" width="' + options.width + 'px" frameborder="0"></iframe></div>');
			}
		});
	}
}

// <script type="text/javascript">$("#close").click(function(){ $("#ehhr-widget").remove();return(false); });</script>