var old_id;
var c_name = false;
var c_email = false;
var c_text = false;


function resize(id_arr, mnoznik){
with (Math){
	for(i=0; i<id_arr.length; i++){
	id = id_arr[i];
	w = round(parseInt($("#" + id).css("width")) * mnoznik);
	h = round(parseInt($("#" + id).css("height")) * mnoznik);
	$("#" + id).css("height", h);
	$("#" + id).css("width", w); 
	}
}
}

function get_img(id, image_id){
$.ajax({
	type: 'GET',
	url: 'php_files/base64.php',
	data: "id="+id,
	success: function(responseText) { 
			//return responseText;
            alert(image_id);
            $('#' + image_id).attr('src', responseText);
            }
	}); 
}

function get_project(id,show_submenu){
	if(id != 0){
		$.ajax({
			type: 'GET',
			url: 'php_files/show_project.php',
			data: "id="+id,
			success: function(responseText) { 
				project = responseText.split("--||--||--");
				if(project[3].length > 0){
					$("#top_main").html(project[1]);
					$("#main").html(project[2]);
					with(Math){
						hm = round(parseInt(project[0])/663);
						new_height = hm * 663;
						if(new_height < parseInt(project[0]) +parseInt($("#top_main").height()) - 190) new_height += 663;
						$("#left").css("height", new_height);
						if(show_submenu) {
							$("#sub_m1").css("display","none");
							$("#sub_m2").css("display","none");
							$("#sub_m3").css("display","none");
							$("#sub_" + project[3]).css("display","block");
						}
						$("#"+old_id).css("font-weight","normal");
						$("#"+id).css("font-weight","bold");
						old_id = id;
						//window.location.hash = "#id="+id;
					}
				}
			}
		}); 
	}
}

function about(){
$.ajax({
		type: 'GET',
		url: 'php_files/about.php',
				success: function(responseText) { 
						project = responseText.split("--||--||--");
						if(project[3].length > 0){
						$("#top_main").html(project[1]);
						$("#main").html(project[2]);
						with(Math){
						hm = round(project[0]/325);
						new_height = hm * 325;
						if(new_height < project[0] + $("#top_main").height()) new_height += 325;
						$("#left").css("height", new_height);
						$("#sub_m1").css("display","none");
						$("#sub_m2").css("display","none");
						$("#sub_m3").css("display","none");
                        /*
						$("#"+old_id).css("font-weight","normal");
						$("#"+id).css("font-weight","bold");
						old_id = id;*/
						}}
		}
		}); 
}

function clear_contact(id){
    switch(id){
	case "name_text":
	if(!c_name){
		c_name = true;
		$("#" + id).val("");
		}
	break;
	case "email_text":
	if(!c_email){
		c_email = true;
		$("#" + id).val("");
	}
	break;
	case "message_text":
	if(!c_text){
		c_text = true;
		$("#" + id).val("");
	}
	break;
	}
}

function email_validate(src) 
{
  var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
  return regex.test(src);
}

function validate(){
if(!email_validate($("#email_text").val())) alert($("#err_email").val()); else 
  if($("#name_text").val().length < 3) alert($("#err_name").val()); else 
    if($("#message_text").val().length < 3) alert($("#err_text").val()); else {
	$("#loader").css("display","");
	$.ajax({
		type: 'POST',
		url: 'php_files/send_email.php',
		data: "email_to="+$("#send_email").val() + "&email_from="+$("#email_text").val() + "&name=" + $("#name_text").val() + "&text=" + $("#message_text").val(),
				success: function(responseText) { 
					$("#send_message").html(responseText);	
					$("#loader").css("display","none");
				}
		});
	}
}

