/*
	tt.makeClickable.js
	
	Version: 	0.1 
	Author: 	Matt Kersley
	
	---------------------------------------------------------------------------------------
	
	DESCRIPTION:
		This plugin turns any element into a clickable link.
	
	---------------------------------------------------------------------------------------
	
	USAGE:
		$('#elementID').makeClickable({
			href:			'http://www.yourdomain.com',
			target:			'popup',
			popupOptions:	'height=500,width=600,scrollbars=yes',
			cusor:			'pointer'
		});

	---------------------------------------------------------------------------------------
	
	PARAMETERS:
		href		: [string] - url for the link to point to
		target		: [string] - target window (set to 'popup' if you require a popup window)
		popupOptions: [popup options string] - e.g. "height=500,width=600,scrollbars=yes" 
		cursor		: values can be found @ http://www.w3schools.com/CSS/pr_class_cursor.asp

	---------------------------------------------------------------------------------------
	
	NOTES:
		This plugin needs the [href] option to work.
		
		Providing only the [href] option will open the link in the same tab/window.
		
		Providing the [href] and a [target] (as long as it isn't 'popop') will open the link in
		a new tab/window.
		
		Providing the [href], a [target] of 'popup' and the [options] will cause the window to
		open as a popup.
	
		This is a jQuery plugin, please make sure it is called AFTER jQuery has been
		included in the page.
	
*/

(function($) {
	$.fn.makeClickable = function(options) {

		//default options/settings
		var settings = $.extend({
			href: '',
			target: '',
			options: '',
			cursor: 'pointer'
		}, options || {});

		//if settings.href is empty, alert user
		if (settings.href === '') { alert('makeClickable needs an href setting'); }

		//otherwise make the element clickable
		else {

			//set cursor and click event using settings above
			$(this).css('cursor', settings.cursor).bind('click', function(e) {

				//if there is no target, or popup is not set, open link in same window
				if (settings.target === '' && settings.target !== 'popup') {
					window.location.href = settings.href;
				}

				//if a target is provided, but popup is not set, open in a new window
				if (settings.target !== '' && settings.target !== 'popup') {
					window.open(settings.href, settings.target);
				}

				//if popup is set open a new window with the popupOptions
				if (settings.target === 'popup') {
					window.open(settings.href, settings.target, settings.options);
				}

			});

		}
		
		return false;

	};
})(jQuery);
