var prethis, preid, preeff, f=0;

function mouseclick2(idd,iff) {
if (iff==1){
		document.getElementById(idd).style.display = "none";
	} else {
		document.getElementById(idd).style.display = "block";
	}
}

function $_(n){
	if(!n) return false;
	if(!document.getElementById(n)) return false;
	return document.getElementById(n)
}

function bubbling_no(e){
	e = bubbling_ie(e); /* for ie */
	if (!e.cancelBubble) e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
	return false;
}

function bubbling_ie(e){
	if (!e) var e = window.event;
	return e;
}

function bounds(el){
	var left = el.offsetLeft;
	var top = el.offsetTop;
	for (var parent = el.offsetParent; parent; parent = parent.offsetParent) {
		left += parent.offsetLeft;
		top += parent.offsetTop;
	}
	return { left: left, top: top, width: el.offsetWidth, height: el.offsetHeight };
}



function toggle_hide(_this, id, typ, eff){
	switch (eff){
		case "fade": $("#"+id).fadeOut("fast");	break;
		case "none": $("#"+id).css({ display:"none"}); break;
		default: $("#"+id).slideUp("fast");
	}
	if (typ!='change1') $(_this).removeClass("click-active");
        if (typ=='news') document.getElementById("next-"+id).style.display='inherit';
	if (typ=='change') document.getElementById("next-"+id).style.display='inherit';

}

function toggle(e, _this, id, typ, eff){
	if ((preid != undefined) && (preid!=id)) toggle_hide(prethis, preid, typ, preeff);
	prethis = _this;
	preid = id;
	preeff = eff;
	bubbling_no(e);
	if ($_(id))
	{
		if (_this.className.indexOf("click-active") == -1){
			$(_this).addClass("click-active");
			switch (eff){
				case "fade":
					$("#"+id).fadeIn("fast");

				break;
				default:
					$("#"+id).slideDown("fast");  //Разворачивает
			}
			$("#"+id).click(function(e) {	bubbling_no(e);	});
			if (typ=='news') document.getElementById("next-"+id).style.display='none';
		} else {
			toggle_hide(_this, id, typ, eff);   //Сворачивает
		}
		$(document).click(function() { toggle_hide(_this, id, typ, eff);	});
	}
}

function toggle1(e, _this, id, typ, eff){
	if ((preid != undefined) && (preid!=id)) toggle_hide(prethis, preid, typ, preeff);
	prethis = _this;
	preid = id;
	preeff = eff;
	bubbling_no(e);
	if ($_(id))
	{
		if (typ=='change1'){
			document.getElementById("next-"+id).style.display='none';
			switch (eff){
				case "fade":
					$("#"+id).fadeIn("fast");

				break;
				default:
					$("#"+id).slideDown("fast");  //Разворачивает
			}
			$("#"+id).click(function(e) {	bubbling_no(e);	});
		} else {
			toggle_hide(_this, id, typ, eff);   //Сворачивает
		}
		$(document).click(function() { toggle_hide(_this, id, typ, eff);	});
	}
}

function cl(id){
      document.getElementById(id).onclick();

}

function loading_set(id){
	var w = $_(id).offsetWidth + "px";
	var h = $_(id).offsetHeight + "px";
	$("#"+id+" div.loading-overlay").css({ width:w, height:h });
}

function loading_show(id){
	$("#"+id).prepend("<div class=\"loading-overlay\"></div>");
	$("#"+id).prepend("<div class=\"loading\"><div>Loading&hellip;</div></div>");
	loading_set(id);
	$(window).resize(function() {
		loading_set(id);
	});
}

function load_page(id, url, _this) {
	var data = _this ? $(_this).serialize() : "";
	$.ajax({
		type: "get",
		url: url,
		data: data,
		beforeSend: function(){
			loading_show(id);
		},
		success: function(html) {
			$("#"+id).html(html);
		}
	});
}


function simple_tooltip(target_items, name){
 	$(target_items).each(function(i){
 		$("body").append("<div class='"+name+"' id='"+name+i+"'><p>"+$(this).attr('title')+"</p></div>");
 		var my_tooltip = $("#"+name+i);

 		$(this).removeAttr("title").mouseover(function(){
 			my_tooltip.css({opacity:0.8, display:"none"}).fadeIn(400);
 		}).mousemove(function(kmouse){
 				 my_tooltip.css({left:kmouse.pageX-215, top:kmouse.pageY+20});
 			}).mouseout(function(){
 					my_tooltip.fadeOut(400);
 			}).click(function(){my_tooltip.fadeOut(400);});
	 });

}

function changeText(id, text){
	document.getElementById(id).innerHTML = text;
}

