(function($){	
	$(document).ready(function() {
		//Add target="_blank" to all external links
		//Add page tracker to all external links
		//^((?!channeladvisor\.).)*$/
		var externalLink = RegExp("^http:\/\/((?!" + document.domain + ").)*$");
		//console.log(document.domain);
		$('a').each(function() {
			//console.log(externalLink.test($(this).attr('href')) + " | " + $(this).attr('href'));
			if (externalLink.test($(this).attr('href'))) {
				$(this).attr('target','_blank');
				$(this).live('click', function() {
					pageTracker._link($(this).attr('href'));
					return false;
				});
			}
		});
		
		// Promo Ad shouldn't open in a new window, but the regex above seems to catch it
		$('#promo-ad a').attr('target','');
		
		//  We want all links to pdfs to open in a new window
		$('a[href$=\\.pdf]').attr('target','_blank');
		
		//Add WMODE=transparent to all youtube videos
		//"iframe[scr*='youtube']"
		$("iframe").each(function() {
			var url = $(this).attr('src');
				if (url.indexOf('youtube') > -1) {
				//if there are no parameters then add it
				if (url.indexOf('?') == -1) {
					url += '?wmode=transparent';
				
				//else add it to the query string
				} else {
					url += '&wmode=transparent';
				}
				
				$(this).attr('src', url);
			}
		});
	});	
})(jQuery);
