function DESemail(emailname,emailserver) {
	document.write("<a href='mailto:" + emailname + "@" + emailserver +"'>");
	document.write(emailname + "@" + emailserver); 
	document.write("</a>"); 
}

// Accessible Pop Ups
function DESopen(url,width,height,toolbar,scroll) {
	window.open(url, "", "scrollbars="+scroll+",toolbar="+toolbar+",height="+ height +",width="+width);
	return false;
}



$(document).ready(function(){
	
	$("#subscribe_email")
		.focus(
			function() { $(this).addClass("focused"); }
		).blur(
			function() { $(this).removeClass("focused"); }
		).one("click",function() {
			var sqVal = $(this).val();
			if (sqVal == 'Enter email here to join mailing list' || sqVal == 'Tanysgrifio i\'r cylchlythyr') {
				$(this).val("");
			}
		});
	
	$("#sub_submit").hover(
		function() { $(this).addClass("hovered"); },
		function() { $(this).removeClass("hovered"); }
	);

	$("#search_term")
		.focus(
			function() { $(this).addClass("focused"); }
		).blur(
			function() { $(this).removeClass("focused"); }
		).one("click",function() {
			var sqVal = $(this).val();
			if (sqVal == 'Search listings...' || sqVal == 'tanysgrifiwch i\’r cylchlythyr') {
				$(this).val("");
			}
		});

	$("#newsletter_subscribe").submit(function() {
		var emailVal = $("#subscribe_email").val();
		if (emailVal=='Enter email here to join mailing list' || emailVal=='Tanysgrifio i\'r cylchlythyr' || emailVal=='') {
			alert('Please enter your email first');
			return false;
		}
	});

	// Ajax Home Events
	$("#home_events")
		.find("a")
			.click( function() {
				var eventID = $(this).attr("rel");
				var langId = $(this).attr("class");

				$("#right")
					.html('<img src="/img/design/spinner.gif" width="43" height="11" id="spinner" />')
					.load("/incs/ajax/home-event.php?eventID="+eventID+"&language="+langId);
				return false;
			});

//	twitter_user  = 'clwbiforbach';
	var twitter_user = $("#twitter_user").attr("rel");
	twitter_count = 5;

	twitter_url = "http://twitter.com/status/user_timeline/" + twitter_user + ".json?count=" + twitter_count + "&callback=?";

	$.getJSON(twitter_url, function(data) {
		$.each(data, function(i, item) {
			var txt = item.text
				.replace(/(https?:\/\/[-a-z0-9._~:\/?#@!$&\'()*+,;=%]+)/ig, '<a href="$1">$1</a>')
				.replace(/@+([_A-Za-z0-9-]+)/ig, '<a href="http://twitter.com/$1">@$1</a>')
				.replace(/#+([_A-Za-z0-9-]+)/ig, '<a href="http://search.twitter.com/search?q=$1">#$1</a>');

			$('<li>' + txt + '</li>').appendTo('ul.tweets');
		});
	});

}); // End jQuery