function GetWindowScrollSize()
	{
		var width, height;
		var	pDoc = document;
		if ( (pDoc.compatMode && pDoc.compatMode == "CSS1Compat"))
		{   
			width = pDoc.documentElement.scrollWidth;
			height = pDoc.documentElement.scrollHeight;
		}
		else
		{   
			if (pDoc.body.scrollHeight > pDoc.body.offsetHeight)
				height = pDoc.body.scrollHeight;
			else
				height = pDoc.body.offsetHeight;

			if (pDoc.body.scrollWidth > pDoc.body.offsetWidth || 
				(pDoc.compatMode && pDoc.compatMode == "BackCompat") ||
				(pDoc.documentElement && !pDoc.documentElement.clientWidth)
			)
				width = pDoc.body.scrollWidth;
			else
				width = pDoc.body.offsetWidth;
		}
		return {w : width, h : height};
	}

function Wins()
{	
	var contents = {};	
	var current;
	var overlay,wcont,wtitle,wclose,wpopup=false;
	var loadingimg = new Image();        
	var overss;
     var taghtml=document.getElementsByTagName('html')[0];
	var crehtml=document.createElement('div');
	crehtml.innerHTML='<div id="overlay" class="hidden"></div><div id="window" class="hidden"><div id="window_top"><div id="window_top1"><img src="/wp-content/themes/areal/images/trans.gif" alt="" width="1" height="1"/></div><div id="window_top2"></div></div><div id="window_bg"></div><div id="window_title"><div></div></div><div id="window_close"><a href="#" title="Закрыть"><img src="/wp-content/themes/areal/images/close.gif" alt="X"/></a></div><div id="window_cont"></div><div id="window_text"></div></div>';

	function init()
	{
		document.body.appendChild(crehtml.cloneNode(true));
		delete crehtml;
		overlay = document.getElementById('overlay');
		wpopup=document.getElementById('window');
		wp1=document.getElementById('window_cont');
		wp2=document.getElementById('window_bg');
		wtitle=document.getElementById('window_title');
		wcont=document.getElementById('window_text');
		wclose=document.getElementById('window_close').getElementsByTagName('a')[0];

		updateOverlaySize();
		window.onresize = updateOverlaySize;
	
		loadingimg.src='/wp-content/themes/areal/images/loading.gif';

		

		wclose.onclick = overlay.onmousedown = function(){ contents[current].close(); toggleWindow(); wpopup.className='hidden'; return false};
	}
	function updateOverlaySize()
	{
		overss = GetWindowScrollSize();
		overlay.style.width=overss.w + 'px';
		overlay.style.height=overss.h + 'px';
	}      

	this.clearContent = function(){ contents[current].cleardata(); delete contents[current]; wcont.innerHTML=''; }
	
	this.open = function(opts)
	{		
		if(!wpopup) init();
		if(opts.width) {
                        if(opts.width>taghtml.clientWidth) opts.width = taghtml.clientWidth;
			wpopup.style.width=opts.width + 'px';   
				wp1.style.width=parseInt(opts.width-8) + 'px';
				wp2.style.width=parseInt(opts.width-2) + 'px';
				wcont.style.width=parseInt(opts.width-28) + 'px';
			wpopup.style.marginLeft= '-' + parseInt(opts.width/2) + 'px';
		}
		if(opts.height) {
                        if(opts.height>taghtml.clientHeight) opts.height = taghtml.clientHeight;
			wpopup.style.height=opts.height + 'px';
				wp1.style.height=parseInt(opts.height-22) + 'px';
				wp2.style.height=opts.height + 'px';
				wcont.style.height=parseInt(opts.height-42) + 'px';
			wpopup.style.marginTop= '-' + parseInt(opts.height/2) + 'px';
			wcont.style.overflow = "hidden";                        
		}

		var id = opts.ajaxfile?opts.ajaxfile:opts.fromdivid;
		
		if(!contents[id]) contents[id] = new Content(opts);
		else
		{
			wcont.innerHTML='';
			toggleWindow();
			contents[id].show();			
		}
		current = id;
	}
				
	function toggleSelects(doc)
	{
		var selects = doc.getElementsByTagName('select');
		for(var i=0; i<selects.length; i++)
			if(selects[i].className.match('on-modal-show'))
				selects[i].className=selects[i].className.replace('on-modal-show','');
			else 
				selects[i].className+='on-modal-show';
	}

	function toggleWindow()
	{
		toggleSelects(document.body);		
		overlay.className = overlay.className=='hidden'?'':'hidden';
		wpopup.className = overlay.className;
	}	

	function Content(opts)
	{		
		var title = opts.title?opts.title:'';
		var beforeclose = false, aftershow = false;
		var data;
		if(opts.beforeclose) beforeclose = opts.beforeclose;
		if(opts.aftershow) aftershow = opts.aftershow;
		if(opts.ajaxfile) load();
		else if(opts.fromdivid) fromdiv();

		this.cleardata = function(){ data = false; }
		this.close = function(){ if(beforeclose) beforeclose(); }
		function fromdiv()
		{
			onloading();
			if(opts.fromdivid.constructor==String)
				data = document.getElementById( opts.fromdivid ).cloneNode(true);
			else
				data = opts.fromdivid.cloneNode(true);
			var tmp = data.getElementsByTagName('select');
			for(var i=0;i<tmp.length;i++)
				if(tmp[i].className.match('on-modal-show')) tmp[i].className = tmp[i].className.replace('on-modal-show','');
			show();
		}
		
		function show()
		{			
			wtitle.innerHTML = '<div></div>' + title;

			wcont.innerHTML=data.innerHTML;
			if (wcont.scrollHeight > wcont.offsetHeight)
				wcont.style.overflow = "auto";
			if(aftershow) aftershow();
		}

		this.show = show;

		function afterloading(xml)
		{
			data = document.createElement('div');
			data.innerHTML = xml.responseText;
			show();
		}

		function load()
		{
			onloading();
			var xml = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
			xml.open("GET", opts.ajaxfile, true);			
			xml.setRequestHeader("X-Requested-With", "XMLHttpRequest");
			xml.setRequestHeader("Accept","*/*");
			xml.onreadystatechange = function(){
				if ( xml.readyState == 4 ) 
					if ( xml.status == 200)
						afterloading(xml);
			}			
			xml.send(null);	
		}

		function onloading()
		{			
			wtitle.innerHTML='Loading... ' ;
			wcont.innerHTML='';			
		    wcont.appendChild(loadingimg);
		    toggleWindow();
		}				
	}
}

function setMailBoxes()
{
	var as=document.getElementsByTagName('a'), dmn, nm;
	for(var i=0;i<as.length;i++)
		if(as[i].className=='e-mail')
			{
				dmn=as[i].href.substr(as[i].href.search('#')+1);
				nm=as[i].title;
				as[i].href='mailto:'+nm+'@'+dmn;
				as[i].title='Написать письмо';
				if(!as[i].innerHTML) as[i].innerHTML=nm+'@'+dmn;
			}
}


/*(function addCheckform()
{
	document.getElementsById('sendbutton').onclick = function()
	{
		var tmp = document.getElementById('cf_uploadfile-8').value + document.getElementById('cf_uploadfile-11').value;
		if(!tmp)
		{
			alert(' ਪ९  1 䠩.');
			return false;
		}
		return false;
	}
})();*/

function cTip()
{
	var box=false, p;

	function where (obj) {
		var pos = {
			x: obj.offsetLeft,
			y: obj.offsetTop
		};
	
		while (obj = obj.offsetParent) {
			pos.x += obj.offsetLeft;
			pos.y += obj.offsetTop;
	   	}
	
		return pos;
	}

	function init()
	{
		box = document.body.appendChild(document.createElement('div'));
		box.id = 'tip';		
		box.style.zIndex='10000';
		box.innerHTML='<div><em><b></b><i></i><span></span></em><ul><li><p></p></li></ul><span><b></b><i></i><em></em></span></div>';
		p = box.getElementsByTagName('p')[0];
		box.style.display='none';
	}

	this.show = function(obj, txt)
	{
		if(!box) init();
		
		p.innerHTML = txt;
		var pos = where(obj);
		box.style.left = parseInt(pos.x) + 'px';
		
		//parseInt(pos.y) + 'px';
		box.style.display = '';
		box.style.top = parseInt(pos.y - box.offsetHeight) + 'px';
//		alert(box.offsetHeight);
		
		if(!obj.onmouseout)
			obj.onmouseout=hide;
	}

	function hide()
	{
		box.style.display='none';
	}
}

function showBigImage(href,obj,w,h,ih)
{
	var d = document.getElementById('bigImage');
	var v = document.getElementById('video');
	w = w?w:900;
	h = h?h:700;

	title = '';
	imgs = obj.getElementsByTagName("img");
	if(imgs[0])
		title = imgs[0].alt;
	title = title?title:obj.title;

	if(!d) 
	{
		d = document.body.appendChild(document.createElement('div'));
		d.id='bigImage';
		d.style.display='none';
	}	
	d.innerHTML = '<img src="'+href+'" '+(ih?'height="'+ih+'" ':'')+'/>';
	if(v) v.style.visibility='hidden';
	wins.open({fromdivid:'bigImage', width:w, height:h,		
		beforeclose:function(){ wins.clearContent(); if(v) v.style.visibility=''; },
		title:title});
	return false;
}

setMailBoxes();
wins=new Wins();
tips=new cTip();
scr_sh = new Screenshots();

/***********************************************************************************/
function initflash(id, url, image, w, h)
{
	var axo, a = document.getElementById(id);
	w = w?w:167;
	h = h?h:223;
	if(navigator.plugins && navigator.mimeTypes.length && navigator.plugins["Shockwave Flash"] && navigator.plugins["Shockwave Flash"].description)
		axo = true;
	else
		try{axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");} catch(e){}
	if(axo)
		a.innerHTML='<embed src="/video/mediaplayer.swf?file='+url+'&image='+image+'&autostart=false" wmode="opaque" allowfullscreen="true" width="'+w+'" height="'+h+'" type="application/x-shockwave-flash"></embed>';
}       
