function createRequestObject() {
	var ro;
	var browser = navigator.appName;
	if (browser == "Microsoft Internet Explorer") {
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		ro = new XMLHttpRequest();
	}
	return ro;
}
var http = createRequestObject();

function search_terms(id, sezione) {
	search_request = "";
	if (1) {
		http.onreadystatechange = function () {
			if (http.readyState == 3) {
				document.getElementById("search_result_container").innerHTML = "Ricerca in corso...";
			}
			if (http.readyState == 4) {
				if (http.responseText == "") {
					document.getElementById("search_result_container").innerHTML = "Nessuna corrispondenza"
				} else document.getElementById("search_result_container").innerHTML = http.responseText;
			}
		};
		gruppo_di_ricerca = new Array();
		for (x = 0; x < document.forms['se_form'].search_section.length; x++) {
			if (document.forms['se_form'].search_section[x].checked == true) {
				gruppo_di_ricerca.push(document.forms['se_form'].search_section[x].value);
			}
		}
		colonne_di_ricerca = new Array();
		for (x = 0; x < document.forms['se_form'].search_columns.length; x++) {
			if (document.forms['se_form'].search_columns[x].checked == true) {
				colonne_di_ricerca.push(document.forms['se_form'].search_columns[x].value);
			}
		}
		http.open('post', 'include/search_engine.php');
		http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		search_request += "group=" + gruppo_di_ricerca;
		search_request += "&columns=" + colonne_di_ricerca;
		search_request += "&term=" + document.getElementById("term").value;
		search_request += "&cane=cane";
		search_request += '&action=search';
		
		if(document.getElementById("term").value.length >2){
				http.send(search_request);
		}else
		{	//alert(document.getElementById("term").value.length);
			document.getElementById("search_result_container").innerHTML ="Parola chiave troppo corta. Inserire almeno tre caratteri";
			}	
	}
}
$(document).ready(function () {
	$(".switcher_wrap").hover(function () {
		if ($("#links").is(":hidden")) {
			$("#links").slideDown();
		} else {
			$("#links").slideUp();
		}
	});
	$(".switcher_wrap").hover(function () {},
	function () {
		$("#links").slideUp();
	});
	$("#search_area").click(function () {
		if ($("#search_form").is(":hidden")) {
			$("#search_form").slideDown();
		} else {}
	});
	$("#search_close").click(function () {
		if ($("#search_form").is(":hidden")) {
			$("#search_form").slideDown();
		} else {
			$("#search_form").slideUp();
		}
	});
	active = "true";
	setTimeout(sfuma, 3000);
	function sfuma() {
		if (active == "true") $("#consigliati_slider").fadeOut("slow", sali);
	}
	order_slider = 1;
	numero_di_slider = document.getElementById("consigliati_slider").getElementsByTagName("div").length;
	function sali() {
		numero = 390 * order_slider;
		if (order_slider >= $(".eventi_consigliati").length) {
			numero = 0;
			order_slider = 0;
		}
		$("#consigliati_slider").animate({
			marginTop: "-" + numero + "px"
		},
		500, "swing", rimostra);
		order_slider++;
	}
	function rimostra() {
		if (active == "true") {
			$("#consigliati_slider").fadeIn("slow");
			$("#consigliati_slider").animate({
				fontSize: "3em"
			},
			3000, "swing", sfuma)
		}
	}
	slide_amount = 170;
	contatore = 0;
	objects = $(".pill_box").length;
	$("#next_slide").click(function () {
		next_pos();
	});
	$("#prev_slide").click(function () {
		prev_pos();
	});
	function slida(toPosition) {
		$('#slider_sliding').animate({
			marginTop: "-" + toPosition
		},
		200, "swing", function () {});
	}
	function next_pos() {
		contatore++;
		if (contatore == objects) {
			posizione = 0;
			contatore = 0;
		} else {
			posizione = contatore * slide_amount;
		}
		slida(posizione);
		slida_indicator(contatore);
	}
	function prev_pos() {
		contatore--;
		if (contatore < 0) {
			contatore = objects - 1;
			posizione = slide_amount * contatore;
		} else {
			posizione = contatore * slide_amount;
		}
		slida(posizione);
		slida_indicator(contatore);
	}
	function slider_create_indicator() {
		for (x = 1; x <= objects; x++) {
			$("#slider_indicator").append('<a href="javascript:void(0);" id="indicator_' + x + '" >' + x + '</a>');
		}
		slida_indicator(0);
	}
	function slida_indicator(contatore) {
		$("#slider_indicator a").each(function (index) {
			$(this).removeClass("selected");
			if (index == contatore) {
				$(this).toggleClass("selected")
			}
		});
	}
	slider_create_indicator();
});
function aggiusta() {
	var elementi = 0;
	aggiusta.mioarray = new Array();
	for (x = 0; x < document.getElementById("hl_slide").childNodes.length; x++) {
		if (document.getElementById("hl_slide").childNodes[x].className == "hl_box") {
			elementi++;
			aggiusta.mioarray.push(document.getElementById("hl_slide").childNodes[x])
		}
	}
	aggiusta.cont = ++aggiusta.cont || 1;
	var valore = 176;
	if (aggiusta.cont == elementi) {
		aggiusta.cont = 0;
		sposta_oggetto.contatore = 1;
	}
	spostamento = -(valore * aggiusta.cont);
	aggiusta.int_spot = setInterval(sposta_oggetto, 20, document.getElementById("hl_slide"), spostamento);
}
function sposta_oggetto(ele, quanto) {
	if (sposta_oggetto.contatore == undefined) {
		sposta_oggetto.contatore = 1
	};
	ele.style.marginTop = -sposta_oggetto.contatore * 20 + "px";
	sposta_oggetto.contatore++;
	if ( - sposta_oggetto.contatore * 20 < quanto) {
		clearInterval(aggiusta.int_spot);
		ele.style.marginTop = quanto + "px";
	}
}
function faipartireiltimer() {
	window.intervallo = setInterval(aggiusta, 5000);
}
function fermailtimer() {
	if (window.intervallo != undefined) {
		clearInterval(window.intervallo);
	}
}
function elementExists(id) {
	var el = document.getElementById(id);
	if (el != null) {
		return true;
	} else {
		return false;
	}
}
$(document).ready(function () {
	if (elementExists("h1_slide")) {
		faipartireiltimer();
	}
	$('#hl_slide').mouseout(function () {
		faipartireiltimer();
	});
	$('#hl_slide').mouseover(function () {
		fermailtimer();
	});
	$('#eventiconsigliati_container').mouseover(function () {
		active = "false";
	});
	$('#eventiconsigliati_container').mouseout(function () {
		active = "true";
	});
});
function show_more_info(object_number) {
	if ($("#more_info" + object_number).is(":hidden")) {
		$("#more_info" + object_number).slideDown();
	} else {
		$("#more_info" + object_number).slideUp();
	}
}
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i = 0; i < anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank";
	}
}
function getget(name) {
	var q = document.location.search;
	var i = q.indexOf(name + "=");
	if (i == -1) {
		return false;
	}
	var r = q.substr(i + name.length + 1, q.length - i - name.length - 1);
	i = r.indexOf("&");
	if (i != -1) {
		r = r.substr(0, i);
	}
	return r.replace(/\+/g, " ");
}
$(document).ready(function () {
	if (getget("staff_girl") != -1) {
		staff_girl = getget("staff_girl");
		show_more_info(staff_girl);
	}
	return false;
});

function pulisci_testo(stringa) {
	//alert(stringa);
	stringa = stringa.replace(/"à"/g, "&agrave;");
	stringa = stringa.replace(/"à"/g, "&agrave;");
	stringa = stringa.replace(/"è"/g, "&egrave;");
	stringa = stringa.replace(/"é"/g, "&acute;");
	stringa = stringa.replace(/"ì"/g, "&igrave;");
	stringa = stringa.replace(/"ò"/g, "&ograve;");
	stringa = stringa.replace(/"ù"/g, "&ugrave;");
	stringa = stringa.replace(/\+/g, "+");
	stringa = stringa.replace(/"/g, "&quot;");

	//caratteri di escape
	stringa = stringa.replace(/&/g, "&amp;");
	stringa = stringa.replace(/&/g, "&");
	stringa = stringa.replace(/:/g, ":");
	stringa = stringa.replace(/;/g, ";");

	stringa = stringa.replace(/=/g, "=");

	stringa = stringa.replace(/&/g, "&");
	stringa = stringa.replace(/"/g, "&quot;");
	stringa = stringa.replace(/..\/..\/..\/public/g, "../../public");

	return stringa;

}

function get_recaptcha_data() {

}

insert_new_comment = function (id, sezione) {

	param = 'a457js534=dfrekrl2313bcv';

	comment_name = pulisci_testo(document.getElementById("comment_name").value);
	param = param + '&comment_name=' + comment_name;

	comment_surname = pulisci_testo(document.getElementById("comment_surname").value);
	param = param + '&comment_surname=' + comment_surname;

	comment_text = pulisci_testo(document.getElementById("comment_text").value);
	param = param + '&comment_text=' + comment_text;

	comment_mail = pulisci_testo(document.getElementById("comment_mail").value);
	param = param + '&comment_mail=' + comment_mail;

	//istanza del mio fck

	if (1) {
		//alert("era un nuovo elemento da inserire")
		param = param + '&action=insert_comment&id=' + id + '&section=' + sezione;
		// alert(foto);
	}

	//document.getElementById("interview").innerHTML = param;
	http.onreadystatechange = gestisci_risposta;
	http.open('POST', 'include/comments/server_comments.php');
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	//http.setRequestHeader("Content-Type","application/x-javascript; charset=UTF-8");
	//application/x-javascript; charset=utf-8
	//alert(param);
	http.send(param);
}

function gestisci_risposta() {

	if (http.readyState == 4) {

		alert(http.responseText);

	}
}




/**per la visualizzazione dello zoom dell'immagine
*/
function detail_image(anchor,id){
		
		posizione_larg =  $(window).width()/2-200+"px";
		posizione_top = $(window).height()/2-200+'px';

		var txt = $(anchor).text();
		var imgsrc = $('#thumb_'+id).attr('src');
		
		var $detail = '<div id="bg"><div id="zoomed"><img style="width:400px; height:400px;" src="'+imgsrc +'" /><h2>'+txt +'</h2><a onclick="show_toggle()" title="Chiudi questa finestra" id="close">chiudi</a></div></div>';
				
		$('#bg').remove();		
		$('body').append($detail);
		$("#zoomed").css("top", posizione_top);
		$("#zoomed").css ("left", posizione_larg);
		$("#zoomed").css ("position", "absolute");
		$("#bg").css ("position", "fixed");
		$("#bg").css ("height", $(window).height()+55);
		$("#bg").css ("width", $(window).width());
		$("#bg").css ("top", "0px");
		$("#bg").css ("left", "0px");
		$("#bg").css ("display", "none");
		show_toggle();
}

function show_toggle(){
				
		$("#bg").toggle(200);
		
}

