// JavaScript Document
(function($){


	$.fn.open_external_page_url = function(config) {
		if (typeof(config) == 'string') {
			var options = { remoteScript: config };
		} else if (typeof(config) == 'object') {
			var options = config;
		} else {
			return $(this); // need to have a remote script to do anything; abort if we don't have one
		}
	
		// you can override the defaults by passing a configuration object when calling the plugin.
		// for example:
		//
		//		$('a.clicktrack').clicktrack({remote_script: 'write.php', sendOnce: false});
		//
		// this will send the clicktrack to the server every time the link is clicked, rather than sending it once
	
		var defaults = {
			remoteScript: '',	// the location of the remote script on your server;
										// this can also be passed as a string argument (see above)
	
			prefix: 'ct_',			// the prefix for additional class names that should be passed to the server
			extraData: null,		// extra data to be sent to the remote script
			callback: function() {},	// a callback function to be executed when the remote script succeeds
			dataType: 'json',			// the format of the data you expect to get back from the remote script
			sendOnce: false,			// whether clicktracks should be sent once (true) or for every click (false)
			preventDefault: false	// whether clicks on clicktrack links should be prevented from taking the user to another page 				(true) or be followed as expected (false)
	
		};
	
		var settings = $.extend(defaults,options,true);
		var source = document.location.toString();
		return $(this).click(function(e) {
			if (settings.preventDefault) { e.preventDefault(); }
				var $this = $(this);
			if (! $this.hasClass('js_no_clicktrack')) {
				if (settings.sendOnce) { $this.addClass('js_no_clicktrack'); }
					

					
					var externalurl      	=  $this.attr('externalurl');
					
					var classNames = $this.attr('class').split(' ');
					var classArray = [];
					$.each(classNames, function(i,v){
					if (v.match(settings.prefix)){
						classArray.push(v);
					}
	
				});
			}
			
			if (settings.preventDefault) { return false; }
			//alert(href);
			var newhref = externalurl;
			
			//alert(newhref);
			//location.href = newhref;
			window.open(newhref);
			return false;
		})
	
	
	
	}

})(jQuery)


