// jquery.openwindow-1.0.min.js
(function(i,o){var q=0;i.openWindow=function(h,a){a=i.extend({width:"60%",height:"60%",top:"middle",left:"center",location:1,menubar:0,toolbar:0,bookmarks:0,status:0,resizable:1,scroll:1,gui:40,name:"jQuery_popUp",nu:0,focus:1},a);var b=[],m=a.nu?a.name+q++:a.name,j=o.screen,e=j.height,k=j.width,f=a.width,g=a.height,c=a.left,d=a.top,r=a.gui;j=["location","menubar","toolbar","bookmarks","status","resizable","scroll"];var p=j.length,n=Math.round,l=function(s,t){return n(t*s.replace("%","")/100)};if(f.indexOf)if(f.indexOf("%"))f=
l(f,k);b.push("width="+f);if(g.indexOf)if(g.indexOf("%"))g=l(g,e);b.push("height="+g);if(c.indexOf)if(c.indexOf("%")!==-1)c=l(c,k);else switch(c){case "center":c=n((k-f)/2);break;case "left":c=0;break;case "right":c=k-f}b.push("left="+c);if(d.indexOf)if(d.indexOf("%")!==-1)d=l(d,e);else switch(d){case "middle":d=n((e-g)/2)-r;break;case "top":d=0;break;case "bottom":d=e-g}for(b.push("top="+d);p--;){e=j[p];b.push(e+"="+(a[e]?"yes":"no"))}h=o.open(h,m,b.join(","));a.focus&&h.focus();return h};i.fn.openWindow=
function(h){return this.each(function(){var a=this,b=a.href;b&&i(a).click(function(m){m.preventDefault();i.openWindow(b,h)})})}})(jQuery,window);
/*

	jQuery Omniture Tracking Plugin
	Eaily attach click tracking to any link.
	
	Dependencies:
	- Omniture H Code (s_265 object)
	- jQuery 1.4.2
	
	Usage:
	
	$("#my-link").omniTrack({
		suite: "aolshare", // Suite the click should roll into.
		channel: "channel_id", // Channel the click should roll into.
		name: "AOL Share by E-mail" // Name describing the click event.
	});
	

	If you want to globally configure common settings for
	the plugin, here's how to globally config:
	
	$.omniTrack({
		suite: "aolshare", // Suite the click should roll into.
		channel: "channel_id" // Channel the click should roll into.
	});
	
	Then you can call the function on links and assume it 
	inherits the global defaults:
	$("#my-link").omniTrack({
		name: "AOL Share by E-mail" // Name describing the click event.
	});
	
*/
/*
function linkCode(obj){
	var s=s_gi('aolshare');   //AOLSHARE report suite only 
	s_265.linkTrackVars='none';
	s_265.linkTrackEvents='none';
	s_265.channel='channel ID';
	s_265.trackExternalLinks='true';
	var lt=obj.href!=null?s.lt(obj.href):"";
	if (lt=="") { s.tl(obj,'o','AOL Share Module Name'); } //the Link Name will provide the flexibility to incorporate future services 
}
*/
/*(function($, win){

var Omniture,
	omnitureInit,

	defaultOptions = {
		linkType: "o",
		namespace: "omnitrack"
	};

$.omniTrack = function( customOptions ){
	
	// If we were passed an element, we can get to work.
	if ( customOptions.elem ) {
		
		var options = $.extend( {}, defaultOptions, customOptions ),
			elem = customOptions.elem,
			$elem = $(elem),
			name = options.name || $elem.text(),
			
			fireOmniture = function(){					
				// Create an Omniture instance, fire the pixel.
				var omnitureInstance = s_gi( options.suite || win.s_account || "aolsvc" );
				omnitureInstance.tl( elem, options.linkType, name );
			};
		
		// Rig the anchor element with link tracking.
		$elem.bind("click." + options.namespace, function(){
														  
			// We initialize Omniture here in case 
			// it hasn't loaded yet (i.e. asynchronous loads)
			if ( omnitureInit ) {
				fireOmniture();
			} else {
				if ( Omniture = win.s_265 ) {
					Omniture.linkTrackVars = "none";
					Omniture.linkTrackEvents = "none";
					Omniture.trackExternalLinks = "true";	
					omnitureInit = 1;
					fireOmniture();
				}
			}
		});
		
	// Set global properties.	
	} else {
		
		$.extend( defaultOptions, customOptions );
		
	}

}

$.fn.omniTrack = function( customOptions ){
	
	return this.each(function(){
		
		customOptions.elem = this;
		$.omniTrack( customOptions );
	
	});
	
}

})(jQuery, window);
*/
/*
	jQuery AddThis Plugin 1.1
	@author David Artz (david.artz@corp.aol.com)

	Dependencies:
	* jquery-1.4.2.js
	* jquery.getjs.js
	* jquery.inlinecss.js
	
	Code History
	7/29/2010 - David Artz (david.artz@corp.aol.com)
	* Increased UI delay to 500ms.
	* Incorporated asynch load and init functionality.
*/
(function($, win, doc){ 

// Global variable that should disable AddThis' CSS from loading.
//addthis_conf = { xcs: 1 };
// Default options across all instances of AddThis on the page.
var defaultOptions = {
		
		// Standard HTML for each service
		html: {
			'email': '<a class="aol-share-email" href="{{emailUrl}}?pu={{url}}&pt={{title}}&pd={{desc}}" title="Email"><span>Email</span></a>',
			'print': '<a class="aol-share-print" href="javascript:window.print();" title="Print">Print this page</a>',
			'facebook': '<a class="aol-share-facebook" href="http://www.facebook.com/sharer.php?u={{url}}&amp;t={{title}}" target="_blank" title="Share on Facebook">Share on Facebook</a>',
			'twitter': '<a class="aol-share-twitter" href="http://twitter.com/share?url={{url}}&amp;text={{title}}&amp;via=AOL" target="_blank" title="Share on Twitter">Share on Twitter</a>',
			'digg': '<a class="aol-share-digg" href="http://digg.com/submit?url={{url}}&amp;title={{title}}&amp;description={{desc}}"  target="_blank" title="Share on Digg">Share on Digg</a>',
			'lifestream': '<a class="aol-share-lifestream" href="http://lifestream.aol.com/share/?url={{url}}&amp;title={{title}}&amp;description={{desc}}"  target="_blank" title="Share on Lifestream">Share on Lifestream</a>',
			'separator': '<span class="separator">|</span>'
		},
		
		// default order and list of services
		services: [ "print", "separator", "email", "facebook", "twitter", "digg", "lifestream" ],

		// default styles
		css: ['.aol-share {',
					'height:19px;',
					'font:12px Arial;',
					'position:relative;',
				'}',
					'.aol-share a {',
						'background:url(http://o.aolcdn.com/os/aol/aol-share.png) no-repeat scroll 0 0 transparent;',
						'display:inline;',
						'float:left;',
						'margin-right:10px;',
						'width:19px;',
						'height:19px;',
						'overflow:hidden;',
						'text-indent:-99em',
					'}',
					'.aol-share span {',
						'float:left;',
						'height:16px;',
						'padding-top:2px;',
						'padding-left:19px;',
						'cursor:pointer;',
					'}',
					'.aol-share span.separator {',
						'float:left;',
						'padding-right:10px;',
						'padding-left:0;',
					'}',
					'a.aol-share-email{background-position:0 -19px;padding-left:4px;text-indent:0;width:auto}',
					'a.aol-share-facebook{background-position:0 -38px;}',
					'a.aol-share-twitter{background-position:0 -57px;}',
					'a.aol-share-digg{background-position:0 -76px;}',
					'a.aol-share-lifestream{background-position:0 -95px;}'
			].join(''),
			
			emailUrl:"http://share.aol.com/sendmail/aolshare"
	},
	
	// If we loaded in the CSS or not.
	cssLoaded = 0,
	
	// Legacy Addthis: HTML html if it exists.
	addthisHTML,
	addthisShare;

// Globally set addthis configuration because it does not work 
// per instance (i.e. email link doesn't work. 
// Something to whine to their CTO about. :(

$.aolShare = $.addthis = function( customOptions ){
	
	// Legacy Addthis:
	// We need to detect if users override default addthis HTML
	// in which case need to adjust our services to compact
	// or international mode.
	if ( ( addthisHTML = customOptions.html ) && addthisHTML.length ) {
		// Check for compact mode.
		if ( $( addthisHTML ).find("a").length < 3 ) {
			customOptions.services = ["email", "separator", "facebook"];
		}
		// Map over the Addthis HTML with AOL Share HTML object.
		customOptions.html = defaultOptions.html;
	}
	
	// If we have no element, we want to save 
	// the custom options as the new defaults.
	if ( !customOptions.elem ) {
		
		$.extend( defaultOptions, customOptions );
		
	// Otherwise, we want to render the widget.
	} else {
		
		// Grab a copy of the current defaults and
		// merge them with custom options.
		var options = $.extend( {}, defaultOptions, customOptions ),
			elem = options.elem,
//			elemHTML = elem.innerHTML,  // Not used.
			$elem = $(elem),
			divHtml = ["<div>"], /*,  
				" class=\"",
				elem.className || "",
				"\">"],*/
			$div,
			desc = elem.rel ? elem.rel : "", //check rel attribute for description 
			title = doc.title, // If not provided, revert to the current page title.
			href = location.href, // If not provided, revert to the current page href.
			services = options.services,
			param,
			encode = encodeURIComponent,
			bodyIndex,
			prefix = "a_dgi=",
			i, l;
		
		// Legacy Addthis Support	
		if ( addthisShare = customOptions.addthis_share ) {
			href = addthisShare.url || href;
			title = addthisShare.title || title;
		} else {
			if ( elem.href ) {
				href = elem.href;
				
				bodyIndex = href.indexOf("&amp;body=");
				if ( bodyIndex === -1 ) {
					bodyIndex = href.indexOf("&body=");
				}
				if ( bodyIndex === -1 ) {
					bodyIndex = 0;
				} else {
					bodyIndex += 6;
				}
				href = href.substring( bodyIndex, href.length );
			}
			title = elem.title || title;
		}
		
		// Squirt in the CSS.
		if ( !cssLoaded ) {
			$.inlineCSS( options.css );
			cssLoaded = 1;
		}
		
		param = href.indexOf("?") === -1 ? "?" : "&";

		for ( i = 0, l = services.length; i < l; i++ ) {
			divHtml.push(
				options.html[ services[i] ]
					.replace('{{emailUrl}}', options.emailUrl ) 
					// Test to see if our prefix exists before appending.
					.replace('{{url}}', encode( href + param + ( href.indexOf( prefix === -1 ) ? prefix + "aolshare_" + services[i] : "" ) ) )
					.replace('{{title}}', encode( title ) )
					.replace('{{desc}}', encode( desc ) ) //  desc !== "" ? ( options.services[i] !== 'email' ? '&amp;description=' + encode( desc ) : encode( desc ) ) :  "" )
			);
		}

		divHtml.push('</div>');
		$div = $( divHtml.join("") );
		
		$div.find("a.aol-share-email")
			.openWindow({
				width: 382,
				height: 528,
				location: false,
				name: "aolShareEmail", // This can't have anything fancy (dashes, periods, etc. choke IE6)
				resizable: false,
				scroll: 0,
				location: 0
			});
		
		$div.addClass("aol-share");
				
		// Custom tracking beacon from Richard Thurman
		$div.delegate("a", "click", function(evt) {
			if ( win.s_265 ) {
				var elem = this,
					name = elem.className.replace("aol-share-", "aolshare_"),
					
					now = new Date(),
					nowYear = now.getYear(),
					
					locationHref = location.href,
					
					// Custom time stamp using Richard Thurman's algo.
					timeStamp = [ now.getDate(),
						"/",
						now.getMonth(),
						"/",
						( nowYear < 1900 ? (nowYear + 1900) : nowYear ),
						" ",
						now.getHours(),
						":",
						now.getMinutes(),
						":",
						now.getSeconds(),
						" ",
						now.getDay(),
						" ",
						now.getTimezoneOffset() ].join(""),
						
					// timeStamp = tm.getTime(),	 //timestamp using usual method
					
					url = [ "http",
						location.protocol === "http:" ? "://o" : "s://s",
						".sa.aol.com",
						"/b/ss/aolshare/1/H.21/s",
						Math.round( Math.random() * 100000000000000 ),
						"?AQB=1&ndh=1&t=",
						encode( timeStamp ),
						"&ns=aolllc&cl=63072000&pageName=aol_share_toolbar&g=",
						encode( locationHref ),
						"&c12=",
						encode( locationHref.replace( /[#?].*/g, "" ) ),
						"&c16=",
						encode( s_265.pageName ),
						"&ch=",
						encode( s_265.channel ),
						"&events=event1",
						"&c1=",
						encode( s_265.prop1 ),
						"&c2=",
						encode( s_265.prop2 ),
						"&c17=",
						name,
						"&c18=",
						encode( href.replace( /[#?].*/g, "" ) ),
						"&pe=lnk_o&pev2=",
						name,
						"&AQE=1" ].join(""),
	
					img = new Image();
				
				// Fires the beacon.
				img.src = url;
			}			
		});
		
		
		// Using OmniTrack Library
		// Bind Omniture click tracking.
/*
		$div.find("a").each(function(){
			var elem = this;
			$(elem).omniTrack({
				name: elem.className.replace("aol-share-", "aolshare_"), // Format: aolshare_facebook
				namespace: "aolshare"
			});
		});
*/

		if ( $elem[0].nodeName === "DIV" ) { // Legacy AddThis Implementation
			$elem.html("") // Clear out the <div>
				.append( $div );
		} else {
			$elem.replaceWith( $div );
		}

	}
};

$.fn.aolShare = $.fn.addthis = function( customOptions ){
	
	return this.each(function(){
		customOptions = customOptions || {};
		customOptions.elem = this;
		$.aolShare( customOptions );
	});

};

})(jQuery, window, document);
