Cufon.replace('nav li');

function addslashes(str) {
    // From PHP.js
    return (str+'').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
}

function stripslashes(str) {
	// From PHP.js
    return (str+'').replace(/\\(.?)/g, function (s, n1) {
        switch (n1) {
            case '\\':
                return '\\';
            case '0':
                return '\u0000';
            case '':
                return '';
            default:
                return n1;
        }
    });
}


function setFormFocus() {
	$('.form input, .form textarea, .form select').focus(function(e) {
		$(this).closest('li').addClass('focus');
	});

	$('.form input, .form textarea, .form select').blur(function(e) {
		$(this).closest('li').removeClass('focus');
	});
}


function _popup(page,largeur,hauteur,options) {
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}

function openWebcam() {
	_popup("/webcam.html",680,550,"menubar=no,scrollbars=no,statusbar=no");
}

$(document).ready(function(evt) {
	$('a[rel=external]').click(function(e) {
		e.preventDefault();
		window.open($(this).attr('href'));
	});
	
	setFormFocus();
	

	$('.machines-types img').click(function(e) {
		var type = $(this).attr('title');
		$('.machines-types img').css('opacity', 0.3);
		$(this).css('opacity', 1);
		$('#machine-type-selection span').text(type.toLowerCase());
		$('#machine-type-selection').show();
		$('#machine-type-id').val($(this).attr('id').slice(13));
		$('#machine-type').val(type);
		$('#machine-type-submit').removeAttr('disabled');
	});
	
	
	//$('#weather-status').not('.unknow').tipTip({maxWidth: "auto", edgeOffset: 10, content: $('#weather-tooltip-contents').html() });
	$('#weather-status').tipTip({maxWidth: "auto", edgeOffset: 10, content: $('#weather-tooltip-contents').html() });
	
	$('#webcam').click(openWebcam);
});



