/*--------------------------------------------------
	MENU BM
--------------------------------------------------*/
function menuBM(){
	var on = false;
	$("#ricerca ul li a").not($("#ricerca ul li li a")).mouseover(function(){
		$("#ricerca ul li a.on").removeClass("on").parent().find("ul").hide();
		$(this).addClass("on").parent().find("ul").show();
		on = true;
	});
	
	$("#ricerca *").mouseover(function(){
		on = true;
	}).mouseout(function(){
		on = false;
		chiudi();
	});
	
	function chiudi() {
		setTimeout(function(){
			if (!on) {
				$("#ricerca ul li a.on").removeClass("on").parent().find("ul").hide();
			}
		},500);
	}
	
	// menu imprese aperto in categoria imprese
	if ($("#menu_top li.imprese a").is(".on")) {
		$("#ricerca ul li a.on").removeClass("on").parent().find("ul").hide();
		$("#ricerca ul li.imprese a:first").addClass("on").parent().find("ul").show();
	}
}

/*--------------------------------------------------
	MENU BM NEW
--------------------------------------------------*/
function menuBM_new(){
	var on = false;
	$("#ricerca_new ul ul").hide().css({visibility:'visible'});
	$("#ricerca_new ul li a").not($("#ricerca_new ul li li a")).click(function(){
		$("#ricerca_new ul li a.on").removeClass("on").parent().find("ul").hide();
		$(this).addClass("on").parent().find("ul").show();
		on = true;
		return false;
	});
	
	$("#ricerca_new *").mouseover(function(){
		on = true;
	}).mouseout(function(){
		on = false;
		chiudi();
	});
	
	function chiudi() {
		setTimeout(function(){
			if (!on) {
				$("#ricerca_new ul li a.on").removeClass("on").parent().find("ul").hide();
			}
		},500);
	}
}


/*--------------------------------------------------
	SCROLL HP
--------------------------------------------------*/
function scrollHP(){
	if($(".scrollable").size()) {
		$(".scrollable").scrollable({"mousewheel":true,"circular":true,"speed":700}).autoscroll({interval:10000}); //
	}
}

/*--------------------------------------------------
	Fancy SELFBANK
--------------------------------------------------*/
function selfBank(){
	$('.accedi_self_famiglie').click(function(){
		var el = $(this);
		url = el.attr('href');
		if (GetCookie("SelfFamiglieFancy")==null) {
			SetCookie("SelfFamiglieFancy", "true");
			$.fancybox({
				href:'fancy_selfbak.html',
				type:'iframe',
				width:800,
				onClosed:function(){
					parent.window.location = url;
			}
			});
			setTimeout(
				$.fancybox.close
			,20000);
		} else {
			parent.window.location = url;
		}
		return false;
	});

	$('.accedi_self_imprese').click(function(){
		var el = $(this);
		url = el.attr('href');
		if (GetCookie("SelfImpreseFancy")==null) {
			SetCookie("SelfImpreseFancy", "true");		
			$.fancybox({
				href:'fancy_selfbak_imprese.html',
				type:'iframe',
				width:800,
				onClosed:function(){
					parent.window.location = url;
			}
			});
			setTimeout(
				$.fancybox.close
			,20000);
		} else {
			parent.window.location = url;
		}			
		return false;
	});
}

function viewPrivacy(){
	$(".view_privacy").click(function(){
		$(".cont_privacy").show();
		return false;
	});
	$(".chiudi").click(function(){
		$(".cont_privacy").hide();
		return false;
	});
}

/*--------------------------------------------------
	INIT
--------------------------------------------------*/
$(function(){
	//menuBM();
	menuBM_new();
	scrollHP();
	PulisciInput('.pulisci_input');
	viewPrivacy();
	//selfBank();
});


/*--------------------------------------------------
	PULISCI INPUT
--------------------------------------------------*/
function PulisciInput(arr_input) {
	$(arr_input).each(function(){
			if($(this).length){
				$(this)[0].tmp_input_val=$(this).val();
			}
			$(this).focus( function () {
										if (this.value==this.tmp_input_val) {
											this.value='';
										}
									}						  
						  );
			$(this).blur( function () {
								if (this.value=='') {
									this.value=this.tmp_input_val;
								}
							}
						  );
							   
		});
}


/*--------------------------------------------------
	Matteo
--------------------------------------------------*/
$(document).ready(function(){

	var actualTree
	actualTree="";
													 
	$(".brothersTitle").click(function(){
		var tree
		var html
		tree=$(this).attr("_tree_");

			$(".brothersTitle").removeClass("on");		
			$(this).addClass("on");
			
			if ($("#brothersContent_"+tree).is(":visible")) {
				$("#brothersContent_"+tree).slideUp();		
				$(this).removeClass("on");				
			} else {
				$(".brothersContent").slideUp();
				$("#brothersContent_"+tree).slideDown();			
			}
			
			if ($("#brothersContent_"+tree).html()=="") {
				$("#brothersContent_"+tree).append("<img src=\"images/ajax-loader.gif\" width=\"24\" height=\"24\" />");				
				$("#brothersContent_"+tree).css("height","auto");
				$.ajax({
					type: "GET",
					url: "getContent.asp",
					data: "tree="+tree,
					async: true,
					dataType: "html",
					contentType: "text/html; charset=iso-8859-1",				
					success: function (html) {
						$("#brothersContent_"+tree).html(html);	
						$("#brothersContent_"+tree+" .lancia_form_contatti").fancybox({type:'iframe', width:800, height:650});
						$("#brothersContent_"+tree+" a.fancy").fancybox({width:800});
						$("#brothersContent_"+tree+" .condizioni").fancybox({width:500,height:300});
						$("#brothersContent_"+tree+" a.fancy_video1").fancybox({width:500,height:450});
						$("#brothersContent_"+tree+" a.fancy_video3").fancybox({width:690,height:620});
						$("#brothersContent_"+tree+" a.fancy_video5").fancybox({width:459,height:300});
						$("#brothersContent_"+tree+" a.fancy_video6").fancybox({width:352,height:330});
						$("#brothersContent_"+tree+" a.fancy_video7").fancybox({width:810,height:470});
						$("#brothersContent_"+tree+" a.fancy_video8").fancybox({width:800,height:500});
						$("#brothersContent_"+tree+" a.fancy_home").fancybox({type:'iframe', width:497,height:249});
					}
				});		
			}
	})
	
	$("a.fancy").fancybox({width:800});
	$(".lancia_form_contatti").fancybox({type:'iframe', width:800, height:650});
	$(".condizioni").fancybox({type:'iframe', width:500, height:300});
	$("a.fancy_video1").fancybox({width:500,height:450});
	$("a.fancy_video3").fancybox({width:690,height:620});
	$("a.fancy_video5").fancybox({width:459,height:300});
	$("a.fancy_video6").fancybox({width:352,height:330});
	$("a.fancy_video7").fancybox({width:810,height:470});
	$("a.fancy_video8").fancybox({width:800,height:500});
	$("a.fancy_video9").fancybox({width:510,height:420});
	$("a.fancy_home").fancybox({type:'iframe', width:497,height:249});

	
})

/* STAMPA
	- - - - - - - - - - - - - - - - - - - - */
	function apri_popup(url_to,h,w) { 
winStats="toolbar=no,location=no,directories=no,resizable=yes,menubar=no,scrollbars=yes,width="+w+",height="+h
  if (navigator.appName.indexOf("Microsoft")>=0) {
     winStats+=',left=10,top=25'
  }else{
   winStats+=',screenX=10,screenY=25'
  }
floater=window.open(url_to,"",winStats)     
}

function open_doc(id) {
	window.location.href="viewdoc.asp?CO_ID="+id;
}

/* AZIONI BM
	- - - - - - - - - - - - - - - - - - - - */
function apri_popup(url_to,h,w) { 
winStats="toolbar=no,location=no,directories=no,resizable=yes,menubar=no,scrollbars=yes,width="+w+",height="+h
  if (navigator.appName.indexOf("Microsoft")>=0) {
     winStats+=',left=10,top=25'
  }else{
   winStats+=',screenX=10,screenY=25'
  }
floater=window.open(url_to,"",winStats)     
}
function open_doc(id) {
	window.location.href="viewdoc.asp?CO_ID="+id;
}

/* Funzioni per cookie
	- - - - - - - - - - - - - - - - - - - - */
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1) { endstr = document.cookie.length; }
  return unescape(document.cookie.substring(offset, endstr));
  }

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg) {
      return getCookieVal (j);
      }
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
    }
  return null;
  }

function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
  }

//function SetCookie (name,value,expires,path,domain,secure) {
function SetCookie (name,value,path,domain,secure) {	
	var today = new Date();
	//var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);	
	var expiry = new Date(today.getTime() + 24 * 60 * 60 * 1000);	
  	document.cookie = name + "=" + escape (value) +
    ((expiry) ? "; expires=" + expiry.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
  }	
