$(document).ready(function(){
	// Open external link in a new window
	$('a[rel="external"]').click(function(clickEvent){
		clickEvent.preventDefault();
		
		try {
			var pageTracker = _gat._getTrackerByName();			
			pageTracker._trackEvent('External Links', this.href);
		} catch(err){}

		window.open(this.href);
	});
	
	// Decode base64 "mailto"
	$('a[rel="mailto"]').each(function(){
		var _base64 = $(this).text();
		$(this).attr('href', 'mailto:' + $(this).text($.base64Decode(_base64)).text());
	});
	
	$('form').each(function() {
		// Fix IE <button> bug
		$(this).ieFixButtons(); 

		// Display sample in forms
		className = 'hasExample';
		
		/*
		$(this).find('input[type="text"][title],textarea[title]').each(function(){
			$(this).focus(function(eventFocus){
				if($(this).hasClass(className)) {					
					$(this).val('');
					$(this).removeClass(className);
				}
			});
				
			$(this).blur(function(eventBlur){				
				if($(this).val() == '' || $(this).val() == $(this).attr('title')) {
					$(this).addClass(className);
					$(this).val($(this).attr('title'));
				}
			});
			
			$(this).change(function(eventChange){
				if ($(this).val() != '' && $(this).val() != $(this).attr('title')) {
					$(this).removeClass(className);
				}
			});
					
			if($(this).val() == '' || $(this).val() == $(this).attr('title')) {
				if(!$(this).hasClass(className)) {
					$(this).addClass(className);
					$(this).val($(this).attr('title'));
				}
			}
		});
		*/
		// "a" html entity to trigger form submission
		$(this).find('div.buttons a:not([rel="external"])').click(function(e){		
			e.preventDefault();
						
			// Set the 'rel' of the link to the hidden 'input[action]'
			$(this).parents('form').first().find('input[name="action"]').attr('value', $(this).attr('rel'));
			
			// Submit the parent form
			$(this).parents('form').trigger('submit');
		});
	
		$(this).submit(function(e){	
			// Remove any sample values for the form
			$('.' + className, this).val('');

			if($(this).val()) {
				$.colorbox({
					html:'<strong>hello</strong>',
					overlayClose:false,
					width:400
				});
			}
		});
	});
	
	jQuery.expr[':'].Contains = function(a,i,m){
		return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0;
	};
});
