/*
 * Scripts
 *
 */
jQuery(function($) {
 
	var Engine = {
		utils : {
			links : function(){
				$('a[rel*=external]').click(function(e){
					e.preventDefault();
					window.open($(this).attr('href'));						  
				});
			},
			mails : function(){
				$('a[href^=mailto:]').each(function(){
					var mail = $(this).attr('href').replace('mailto:','');
					var replaced = mail.replace('/at/','@');
					$(this).attr('href','mailto:'+replaced);
					if($(this).text() == mail) {
						$(this).text(replaced);
					}
				});
			},
			compactLabels : function(){
				$('#newsletter-form label, #search-form label').each(function(index, item){
					var label = $(this),
						input = $('#'+ label.attr('for'));
					input.focus(function(){ 	//fetch related field, on focus hide label if field is empty
						label.hide();
					}).blur(function(){			//on blur show label if field is empty			
						if (input.val() === '') {
							label.show();
						}
					});
										
					window.setTimeout(function(){ //hide label if browser autofills the field
						if (input.val() !== '') {
							label.hide();
						}
					},50);
				});
			}
		}
	};

	Engine.utils.links();
	Engine.utils.mails();
	
	Engine.utils.compactLabels();
});
