var sitepath = 'http://www.mapwork.it/wp-content/themes/mapnew/';

function send(datastr){
	$.ajax({	
		type: "POST",
		url: sitepath+"sendmail.php",
		data: datastr,
		cache: false,
		success: function(html){
		$("#risposta").fadeIn("slow");
		$("#risposta").html(html);
		document.getElementById('contactform').reset();
		setTimeout('$("#risposta").fadeOut("slow")',2000);
	}
	});
}

function sendjob(datastr){
	$.ajax({	
		type: "POST",
		url: sitepath+"sendjob.php",
		data: datastr,
		cache: false,
		success: function(html){
		$("#result").fadeIn("slow");
		$("#result").html(html);
		document.getElementById('jobform').reset();
		setTimeout('$("#result").fadeOut("slow")',2000);
	}
	});
}
function isScrollbar(){
return $(document).find('#scrollbar1').attr('id');
}
$(document).ready(function(){
$('#uploadlabel').click(function(){
$('#jobcv').trigger('click');
});
$('#jobcv').change(function(){
$('#thefilename').empty().html($(this).val());
});
var counter = 1;
var contr = new Array();
var tuttititoli = new Array();
$("#creditscarousel li").each(function(){
tuttititoli.push($(this).attr('title'));
$("#creditsnavigator").append("<span id=\"page_"+counter+"\">"+counter+"</span>");
contr.push("#creditsnavigator #page_"+counter);
$(this).attr('value',counter);
counter++;
});
$("#creditsnavigator #page_1").addClass("selected");
$('#section strong').html(tuttititoli[0]);
$("#creditscarousel").jCarouselLite({
        speed: 1000,
        visible: 1,
        btnGo:	 contr,
        afterEnd: function(o){
        var titolo = $(o,this).attr("title");
        var indice = $(o,this).attr("value");
        $("#creditsnavigator span").removeClass("selected");
        $("#page_"+indice).addClass("selected");
        $('#section strong').html(titolo);
        }
});

$("h2, p").ieffembedfix();
$('#wrap').animate({opacity:1});
$('#scrollbar1').tinyscrollbar({ sizethumb: 8 });
$(document).pngFix();
	$('#navigation .page_item').hover(function(){
		$(this).animate( { color: '#fa0366' }, 'fast');
	});
	$('#navigation .page_item').mouseout(function(){
		$(this).animate( { color: '#eeeeee' }, 'fast');
	});
	$('#container.servizi .listaservizi li a').hover(function(){
		$(this).animate( { color: '#fa0366',paddingLeft:'5px' }, 'fast');
	});
	$('#container.servizi .listaservizi li a').mouseout(function(){
		$(this).animate( { color: '#000000',paddingLeft:'0px' }, 'fast');
	});
	$('#listanews h2 a').hover(function(){
		$(this).animate( { color: '#fa0366'}, 'fast');
	});
	$('#listanews h2 a').mouseout(function(){
		$(this).animate( { color: '#000000'}, 'fast');
	});
	var events = false;
	$('.musicplayerbutton').click(function(){
		if(!events){
		$('#musicplayer').animate({marginTop:'0px'},function(){
			events = true;
		});
		}else{
		$('#musicplayer').animate({marginTop:'-50px'},function(){
			events = false;
		});
		}
	});
	
	$("#sendcontactform").click(function(){
var nome = $("#nome").val();
var email = $("#email").val();
var messaggio = $("#messaggio").val();
var lingua = $("#lingua").val();	
    while (messaggio.indexOf("\n") != -1) {
        messaggio = messaggio.replace("\n", "<br/>");
    }


if (nome.length<1||messaggio.length<1) {
if(lingua=='it'){
stringa = 'Mancano informazioni necessarie al corretto invio della richiesta.';
}else{
stringa = 'Missing information';
}
	alert(stringa);
}
else if (!email.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
if(lingua=='it'){
stringa = 'Indirizzo e-mail assente o non valido';
}else{
stringa = 'Invalid E-mail address';
}
	alert(stringa);
}
else if($('#privacy').attr('checked') != true){
if(lingua=='it'){
stringa = 'Accettare i termini sulla privacy';
}else{
stringa = 'Agree the privacy policy';
}
alert(stringa);
}
else {
	var datastr ='nome=' + nome + '&email=' + email + '&messaggio=' + messaggio + '&lingua=' + lingua;
	$("#risposta").css("display", "block");
	if(lingua=='it'){
	var stringaInvio = "Invio in corso...";
	}else{
	var stringaInvio = 'Sending...';
	}
	$("#risposta").html('<img src=\"'+sitepath+'images/wpspin_light.gif\" width=\"16\" height=\"16\" alt=\"ajax-loader\"/> '+stringaInvio);
	$("#risposta").fadeIn("slow");
	setTimeout("send('"+datastr+"')",2000);
	
}
return false;
	});


$("#sendjob").click(function(){
var area = $("#jobarea").val();
var nome = $("#jobnome").val();
var cognome = $("#jobcognome").val();
var email = $("#jobmail").val();
var note = $("#jobnote").val();
var lingua = $("#lingua").val();
var curr = $("#jobcv").val();	
    while (note.indexOf("\n") != -1) {
       note = note.replace("\n", "<br/>");
    }


if (nome.length<1||nome=="Nome"||nome=="Name"||cognome.length<1||cognome=="Cognome"||cognome=="Surname") {
if(lingua=='it'){
stringa = 'Mancano informazioni necessarie al corretto invio della richiesta.';
}else{
stringa = 'Missing information';
}
	alert(stringa);
}
else if (!email.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
if(lingua=='it'){
stringa = 'Indirizzo e-mail assente o non valido';
}else{
stringa = 'Invalid E-mail address';
}
	alert(stringa);
}
else if($('#jobprivacy').attr('checked') != true){
if(lingua=='it'){
stringa = 'Accettare i termini sulla privacy';
}else{
stringa = 'Agree the privacy policy';
}
alert(stringa);
}
else if(curr.length<1){
if(lingua=='it'){
stringa = 'Allega un CV';
}else{
stringa = 'Attach CV';
}
alert(stringa);
}
else {
	document.jobform.submit();
	
}
return false;
	});
});

function place(id,valore){
	var element = $(id).val();
	if(element == valore){
	$(id).val("");
	$(id).css({"color":"#333"});
	}else{
	return false;
	}
}
function unplace(id,valore){
	 var element = $(id).val();
	if(element == ""){
	$(id).val(valore);
	$(id).css({"color":"#999"});
	}else{
	return false;
	}
}
