/*
 * jQuery Replace Mail link plugin 1.0
 *
 * http://valuedstandards.com/jquery-plugins/jquery-replace-mail/
 *
 * Copyright (c) 2009 - 2010 David Hund
 * Use it as you like: some link-love would be nice though :-)
 *
 * - Looks for elements with a classname and an alternative @-symbol
 * - .. then replaces those with a valid mail link
 */

if(typeof jQuery != 'undefined') {
	(function($) {
		jQuery.fn.replacemail = function(options) {
			// Default: <EL class="email">info [AT] this domain</EL>

			// OPTIONS:
			var defaults = {
				atSymbol: " (at) ", // Used to hide an email address in plain text
				altDomain: null, // An alternative domain: e.g. myothersite.com. If not used, current domain is used
				className: "email" // Extra classname added to created email links
			},
			options = $.extend(defaults, options);

			return this.each(function(){
				var textmail = $(this);
				var text1 = textmail.text().toLowerCase();
				var at = options.atSymbol.toLowerCase();
				if(text1.indexOf(at) > 0){
					var pre_at = text1.substring(0, text1.indexOf(at)).replace(/^\s+|\s+$/g,""); // Remove whitespace
					var post_at = text1.substring(text1.length, (text1.indexOf(at)+at.length)).replace(/^\s+|\s+$/g,"");
					var domain = (window.location.domain != undefined) ? window.location.domain : post_at; 
					var chosen_domain = (options.altDomain) ? options.altDomain : domain;
					var address = pre_at+"&#64;"+chosen_domain;
					var link = "<a href='mailto:"+address+"' class='"+options.className+"'>"+address+"</a>";
					textmail.replaceWith(link);
				}
			});
		};
	})(jQuery);
}


/*
Popupwindow plugin for jQuery.
by: Tony Petruzzi
homepage: http://rip747.wordpress.com
plugin download: http://rip747.wordpress.com/2007/03/02/the-return-of-popupwindow-jquery-plugin/
*/

jQuery.fn.popupwindow = function(p)
{

	var profiles = p || {};

	return this.each(function(index){
		var settings, parameters, mysettings, b, a;
		
		// for overrideing the default settings
		mysettings = (jQuery(this).attr("rel") || "").split(",");

		
		settings = {
			height:600, // sets the height in pixels of the window.
			width:600, // sets the width in pixels of the window.
			toolbar:0, // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
			scrollbars:0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
			status:0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
			resizable:1, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.
			left:0, // left position when the window appears.
			top:0, // top position when the window appears.
			center:0, // should we center the window? {1 (YES) or 0 (NO)}. overrides top and left
			createnew:1, // should we create a new window for each occurance {1 (YES) or 0 (NO)}.
			location:0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}.
			menubar:0 // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}.
		};

		// if mysettings length is 1 and not a value pair then assume it is a profile declaration
		// and see if the profile settings exists

		if(mysettings.length == 1 && mysettings[0].split(":").length == 1)
		{
			a = mysettings[0];
			// see if a profile has been defined
			if(typeof profiles[a] != "undefined")
			{
				settings = jQuery.extend(settings, profiles[a]);
			}
		}
		else
		{
			// overrides the settings with parameter passed in using the rel tag.
			for(var i=0; i < mysettings.length; i++)
			{
				b = mysettings[i].split(":");
				if(typeof settings[b[0]] != "undefined" && b.length == 2)
				{
					settings[b[0]] = b[1];
				}
			}
		}

		// center the window
		if (settings.center == 1)
		{
			settings.top = (screen.height-(settings.height + 110))/2;
			settings.left = (screen.width-settings.width)/2;
		}
		
		parameters = "location=" + settings.location + ",menubar=" + settings.menubar + ",height=" + settings.height + ",width=" + settings.width + ",toolbar=" + settings.toolbar + ",scrollbars=" + settings.scrollbars  + ",status=" + settings.status + ",resizable=" + settings.resizable + ",left=" + settings.left  + ",screenX=" + settings.left + ",top=" + settings.top  + ",screenY=" + settings.top;
		
		jQuery(this).bind("click", function(){
			var name = settings.createnew ? "PopUpWindow" + index : "PopUpWindow";
			window.open(this.href, name, parameters).focus();
			return false;
		});
	});

};

