﻿//global js



function getAbsolutePos(el)
{
	var r = { left: el.offsetLeft, top: el.offsetTop };
	if (el.offsetParent)
	{
		var tmp = getAbsolutePos(el.offsetParent);
		r.left += tmp.left;
		r.top += tmp.top;
	}

	r.left -= 0;
	r.top += 10;

	return r;
}



//global variables

var politSrchIsShow=true;

//global functions

function togglePolitSrc(obj)
{
 var m_className='politSrchBl';
 var m_block='.politSrch';
 var m_time=200;
 
 
    if(politSrchIsShow)
    {
        $('.'+m_className).hide(m_time);
        obj.src=HOST+"/img/closed.gif";
        $(m_block).css({'background':' url('+HOST+'/img/srchbg.gif) repeat-x'});
    }
    else
    {
        $('.'+m_className).show(m_time);
        obj.src=HOST+"/img/up.gif";
        $(m_block).css({'background':' url('+HOST+'/img/bg_menu2.png) repeat-x'});
    }
    
    politSrchIsShow=!politSrchIsShow;


}



var MonthArr=new Array('Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь');
var monthArr=new Array('январь','февраль','март','апрель','май','июнь','июль','август','сентябрь','октябрь','ноябрь','декабрь');

//popupinfo
var pInfo;
function popupInfo()
{
	this.links = new Array();
	this.element = ".originalNewsText";
	this.links_ids = new Array();
	this.json_action = HOST + "/index/json-persone/";
	this.popWindow = "#popInfo";
	this.start = function()
	{
		t = this;
		$(t.element + " a").each(function(i){
			_tString = new String();
			_tString = $(t.element + " a").eq(i).attr("href");
			
			if(_tString.indexOf("dossier/persone/id/") != -1)
			{
					t.links.push($(t.element + " a").eq(i));
					t.links_ids.push((t.getIdFromString($(t.element + " a").eq(i).attr("href"))));
					t.setAttributes(t.links.length-1);	

					
			}
			
			
		});		
	
	};
	this.getIdFromString = function(_str){
		return _str.substring(_str.indexOf("/id/")+4,_str.length);
	};
	this.setAttributes = function(index)
	{
		
		$(this.links[index]).attr("onMouseOver","pInfo.showWindow("+ index + ")");
		$(this.links[index]).attr("id","jsactivelinks"+index);
		$(this.links[index]).attr("onMouseOut","pInfo.closeWindow()");
		
		if( $.browser.msie ){
			var tmpHTML = $("body").html();
			$("body").html(tmpHTML);
		}

	};
	this.showWindow = function(index){
		this.getJSONdata(this.links_ids[index] , index);

	
	};
	this.closeWindow = function(){
		$(this.popWindow).remove();
	
	};
	this.getJSONdata = function(_id , index){
		t = this; 
		$.getJSON(this.json_action,{id: _id},function(data){
			if(data)
				t.buildHTMLpopup(data,index);
		});
	
	};
	this.buildWindow = function(index)
	{	
		this.closeWindow();
		offset = $(this.links[index]).offset();
		if( $.browser.msie ){
			offset = getAbsolutePos(document.getElementById('jsactivelinks'+index));
			
		}
		$(this.element + " *").eq(0).append("<div id='popInfo' style='border: 1px solid silver; border-top: 2px solid #AB0830; border-bottom:2px solid silver; background-color: White; padding: 10px; position: absolute; left: " + offset.left + "px; top: " + (offset.top + $(this.links[index]).height()) + "px;'></div>");
		
	}
	this.buildHTMLpopup = function(data,index){
		this.buildWindow(index);

		for(i = 0 ; i < data.length ; ++i)
		{
			$(this.popWindow).html(("<div  style='z-index:100; width: 250px;'><img  style='margin-top:0px; margin-right:5px; float: left;' src=\""+FILES + "" + data[i].dir + "/small_prev_" + data[i].file_name + "\" /> <span style='vertical-align: top;  line-height: 12px;' class='newsSource'><strong style='color: black;'> " + data[i].lastname + " " + data[i].name + " " + data[i].fathername + "</strong><br /><span style='display: inline-block; margin: 5px 0;'> (" +  data[i].birth_date.__attributes.day + " " + data[i].birth_date.__attributes.monthname + " " + data[i].birth_date.__attributes.year + ")</span><br />"  + data[i].description + "</span></div>"));	
		}
		

	}


}



  $(document).ready(function(){
	      pInfo   = new popupInfo();
	        pInfo.start();
	      });
      


