﻿$.ZoomAction = function(options){  
	// настройки по умолчанию  
//	var options = $.extend({showPanel:'animate',testvsr:12}, options);
//а здесь указываем, что нужно обработать переменную options неработает в IE6

		// вызов функции $("table.cClass").zgaction({bgEven: "#CC66CC", bgOdd: "#E6ACE6"});
		// вызов переменных осуществляется так options.bgEven
	
	AllicoZoom = $(options);
	
$("#ConteinerZoom").click(
	function(){$(this).hide("fast");}
	);

AllicoZoom.blur(function(){
	tID = $("*").index(this)+"Big";
	$("#"+tID).hide("fast");});
	
AllicoZoom.click(function(){
	var tBI = $(this).attr("href");
		 tID = $("*").index(this)+"Big";
		oID = $(this);
	
		NFShow = $("#"+tID)
				
		if ($("#"+tID).length==0) {
					
			$("#ConteinerZoom").clone(true).attr("id",tID).appendTo("body");
				
			$("#"+tID).find(".WinBord").append("<img src=" + tBI + " class='DNone'/>");
			
			$("#"+tID).find("img").load(function(){
				$("#"+tID).find(".LoadBar").addClass("DNone");
				$(this).removeClass('DNone');
				//alert(tID);
				PopUpPos($(oID), $("#"+tID));}
				);
			}
			
			PopUpPos($(oID), $("#"+tID));
			
			$("#"+tID).show("fast", function () {
				PopUpPos($(oID), $(this))});
			
		return false;}, 
		function(){
			//tID = $("*").index(this)+"Big"; $("#"+tID).hide("fast");
			});
			
		function PopUpPos(OverID, ShowID)
		{
		var
			WidthP = ShowID.outerWidth();
			HeightP = ShowID.outerHeight();
			leftP = OverID.offset().left;
			topP = OverID.offset().top-HeightP/2+OverID.outerHeight()/2;
								
			if (document.body.scrollTop>topP+10)
				{topP = document.body.scrollTop;}
				else
				{if (document.body.scrollTop+document.body.clientHeight<topP+HeightP+10)
					{topP = document.body.scrollTop+document.body.clientHeight-HeightP;}
				}
				
			if (leftP+WidthP+40>document.body.clientWidth)
				//{leftP = leftP-WidthP+OverID.outerWidth();}
				{leftP = document.body.clientWidth-WidthP-40;}
			
			//ShowID.append("HeightP="+HeightP+"____scrollTop = "+document.body.scrollTop);
			
			cssObj = {'top' : topP,
			'left':leftP}
			ShowID.css(cssObj);	
		}
// Окончание скрипа для увеличения картинки
}

$.ActSelectors=function(options, MultiSel){
//MultiSel - если true то при клике на список текст будет добавлятся. Иначе просто заменятся
AllSelectors = $(options); //ArMidDw  - OfficialCurrency

//Назначаем для подокон событие клик и блюр
AllSelectors.each(function(){
	var THolderName = $(this);
	$("#"+$(this).attr("id")+"SubM").find("li").click(function(){
			if (MultiSel)
				{THolderName.find("input").attr("value", $(this).find("input").attr("value")+", "+$(this).text());}
				else
				{$(this).parents("ul:first").find("li").removeClass("grayBg");
					THolderName.find("input").attr("value", $(this).text());}
					
				$(this).toggleClass("grayBg");
			ActNoActSlector($(this));	
			ShowHideClick ($(this),$(this).find("a"),"ArMidUp");
		return false;});
});

AllSelectors.find("a").click(function(){
	ActNoActSlector($(this).parents(".OneSelector"));
	ShowHideClick ($(this).parents(".OneSelector"),$(this),"ArMidUp");
	return false;});

//AllSelectors.find("a").blur(function(){ShowHideClick ($(this).parents(".OneSelector"),$(this),"ArMidUp");});

AllSelectors.find("input").dblclick(function(){
	ActNoActSlector($(this).parents(".OneSelector"));
	ShowHideClick ($(this).parents(".OneSelector"),$(this).parents(".OneSelector").find("a"),"ArMidUp");
	return false;});
}

//Скрипт для прятанья предыдущего селектора
function ActNoActSlector(NameOfSH)
	{
		if ( tActivSelector!="" && tActivSelector.attr("id")!=NameOfSH.attr("id") )	
			{	$(tActivSelector).find("a:first").toggleClass("ArMidUp");
				PosBlock(tActivSelector, $("#"+$(tActivSelector).attr("id")+"SubM"));
				tActivSelector="";
				}
			
		if (tActivSelector==""){tActivSelector=$(NameOfSH);} else {tActivSelector="";}
	}

//Функция показывани и прятанья подменюхи. 
//NameOfSH - передаем айди блока в котором распологается селектор.
//NameOfArr - передаем то на что нажали тоесть на стрелку
//StyleName - передаем стиль стрелки активной
function ShowHideClick(NameOfSH, NameOfArr, StyleName)
	{
//Получаем имя раскрывушки
var NFShow = $("#"+$(NameOfSH).attr("id")+"SubM");

		if (StyleName!="") {$(NameOfArr).toggleClass(StyleName);}
		PosBlock(NameOfSH, NFShow);
	}
	
function PosBlock(NameOfSH, NFShow, HowHide){
	var leftP = $(NameOfSH).offset().left;
			topP = $(NameOfSH).offset().top;
			WidthP = NFShow.outerWidth();
			HeightP = NFShow.outerHeight();
			
		if (HowHide=="DBlock")
			{NFShow.toggleClass("DBlock");}
			else
			{NFShow.animate({"height": "toggle", "opacity": "toggle"}, 100);}
		
			if (document.body.scrollTop+document.body.clientHeight-HeightP-20<topP)
				{topP = topP-HeightP-$(NameOfSH).outerHeight()}
			
			if (document.body.clientWidth<leftP+WidthP)
				{leftP = $(NameOfSH).offset().left-WidthP+$(NameOfSH).outerWidth();}
			
			cssObj = {'top' : topP+$(NameOfSH).outerHeight(),
			'left':leftP}
			//cssObjShad = {'top' : topP+$(NameOfSH).outerHeight(),'left':leftP+4,'width':WidthP,'height':HeightP}
		NFShow.css(cssObj);
}

//закрывалка
function BodyClickHider(options){

	//Закрытие селектора
		if( !options.parents(".OneSelector:first").is("#"+$(tActivSelector).attr("id")) && (tActivSelector!="") )
			{ShowHideClick(tActivSelector, $(tActivSelector).find("a"), "ArMidUp");
			tActivSelector="";}
		
	//Закрытие Миниокон
		if( !options.parents(".SubWin:first").is("#"+$(tActivSubWin).attr("id")+"SubM") && (tActivSubWin!="") )
			{ShowHideClick(tActivSubWin, tActivSubWin, "");
			tActivSubWin="";}
}


//Скрипт тултипов

this.tooltip = function(){
/* CONFIG */
	xOffset = 10;
	yOffset = 5;
// these 2 variable determine popup's distance from the cursor
// you might want to adjust to get the right result
/* END CONFIG */
var AllTitle = $("*[title!='']");

$(AllTitle).hover(function(e){
	this.t = this.title;
	this.title = "";
	
	$("body").append("<p id='tooltip'>"+ this.t +"</p>");
	
	topP = $(this).offset().top + $(this).outerHeight() + yOffset;
	leftP = $(this).offset().left + $(this).outerWidth()/2 - $("#tooltip").outerWidth()/2;
	
	if (document.body.scrollTop+document.body.clientHeight-$("#tooltip").outerHeight()*2<topP)
		{topP = $(this).offset().top - $("#tooltip").outerHeight() - yOffset;}
		
		//alert(leftP-$("#tooltip").outerWidth()/2);
	if (document.body.clientWidth<leftP+$("#tooltip").outerWidth())
		{	leftP = document.body.clientWidth - $("#tooltip").outerWidth() - xOffset;}
		else
		{if (leftP +$(this).outerWidth()/2 - $("#tooltip").outerWidth()/2<10)
			{leftP = xOffset;}}
	
	$("#tooltip")
	.css("top",topP + "px")
	.css("left",leftP + "px")
	.fadeIn("fast");
},
function(){
	this.title = this.t;
	$("#tooltip").remove();
});

};
