////////////////////////////////////////////////
////////////////////////////////////////////////
/////////////        Made       ////////////////
/////////////         by        ////////////////
/////////////       Coposu      ////////////////
////////////////////////////////////////////////
////////////////////////////////////////////////

//pozitia curenta a scroll-ului: IE => document.documentElement.scrollTop , MOZ/Opera => window.pageYOffset
//inaltimea totala a ferestrei: IE/MOZ/Opera => document.documentElement.clientHeight
//inaltimea totala a paginii: IE/MOZ/Opera => document.documentElement.scrollHeight
if(navigator.appName=="Microsoft Internet Explorer")
{
	var curr_transp=0;
	var i=100;
	var j=0;
	var curr_width=100;
	var curr_height=100;
	var layer_mare=" ";
	var layer_mic=" ";
}
else
{
	var curr_transp=0;
	var i=1;
	var j=0;
	var curr_width=100;
	var curr_height=100;
	var layer_mare=" ";
	var layer_mic=" ";
}
var t=" ";
var s=" ";
var juma_de_W=" ";
var juma_de_H=" ";
var juma_de_W_ultimaValoare=" ";
var juma_de_H_ultimaValoare=" ";
var stare="stare_initiala";
var span=" ";
var locatie_poza=" ";
var nume_poza=" ";
var width_poza=" ";
var height_poza=" ";
var new_width_poza=" ";
var new_height_poza=" ";
var new_layW=new Number();
var new_layH=new Number();
var imgTarget=" ";

function getImg_Safari()
{
	if(navigator.userAgent.match("Safari"))
	{
		imgTarget = event.target.getAttribute('src');
	}
}

document.onclick=getImg_Safari;

function fade(actiune,locatie)
{
	
	var nDiv=document.createElement('div');
	nDiv.setAttribute('id','Layer1');
	nDiv.setAttribute('style','position:fixed; z-index:1; visibility: hidden; overflow: hidden; background-color:#000000; width:100%; height:100%; left: 0; top: 0;');
	document.body.appendChild(nDiv);
	
	var nDivMic=document.createElement('div');
	nDivMic.setAttribute('id','cel_redim');
	nDivMic.setAttribute('style','position:fixed; z-index:2; width:100px; height:100px; overflow:visible; background-color:#333333; visibility: hidden;');
	nDivMic.innerHTML='<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td height="25" align="right" valign="top"><a href="javascript:redim_tbl(\'stop\');"><img src="http://www.revenues.ro/ultimate_fade/mici/b_close_out.png" border="0" onMouseOver="this.src=\'http://www.revenues.ro/ultimate_fade/mici/b_close_over.png\';" onMouseOut="this.src=\'http://www.revenues.ro/ultimate_fade/mici/b_close_out.png\';"></a></td></tr><tr><td bgcolor="#333333" height="100%" align="center" style="padding-top:10px; padding-bottom:10px;"><span id="sp_imaginea"></span></td></tr></table>';
	document.body.appendChild(nDivMic);

	if(actiune=="")
	{
		if(!navigator.userAgent.match("Safari"))
		{
			imgTarget=document.activeElement.childNodes[0].getAttribute('src');
			var arr_img=imgTarget.split("/");
			nume_poza=arr_img[arr_img.length-1];
		}
		else
		{
			var arr_img=imgTarget.split("/");
			nume_poza=arr_img[arr_img.length-1];
		}
	
		sndReq('load_pic',locatie,nume_poza);
	}
	
	if(navigator.appName=="Microsoft Internet Explorer")
	{
		layer_mare=document.getElementById("Layer1");
		layer_mic=document.getElementById("cel_redim");
		
		docH=document.documentElement.scrollHeight;
		docW=document.documentElement.scrollWidth;
		currScrollPozY=document.documentElement.scrollTop;
		winH=document.documentElement.clientHeight;
		winW=document.documentElement.clientWidth;
	}
	else
	{
		layer_mare=document.getElementById("Layer1");
		layer_mic=document.getElementById("cel_redim");
	
		docH=document.documentElement.scrollHeight;
		docW=document.documentElement.scrollWidth;
		currScrollPozY=window.pageYOffset;
		winH=document.documentElement.clientHeight;
		winW=document.documentElement.clientWidth;
	}
	
	switch(actiune)
	{
		case 'start':
			if(navigator.appName=="Microsoft Internet Explorer")
			{
				layer_mare.style.display='';
				layer_mare.style.filter='alpha(opacity="'+curr_transp+'")';
			}
			else
			{
				layer_mare.style.opacity=''+curr_transp+'';
			}	
			layer_mare.style.height=docH+'px';
			layer_mare.style.width=docW+'px';
			layer_mare.style.visibility='visible';
			fade_in();
		break;
		
		case 'stop':
			layer_mic.style.visibility='hidden';
			fade_out();
		break;
	}
}
function fade_in()
{
	if(navigator.appName=="Microsoft Internet Explorer")
	{
		curr_transp=curr_transp+10;
		layer_mare.style.filter='alpha(opacity="'+curr_transp+'")';
		if(curr_transp<60)
		{
			t=setTimeout("fade_in();",0.01);
		}
		else
		{
			clearTimeout(t);
			curr_transp=60;
			redim_tbl('start');
		}
	}
	else
	{
		curr_transp+=0.10;
		layer_mare.style.opacity=''+curr_transp+'';
		if(curr_transp<0.6)
		{
			t=setTimeout("fade_in();",0.01);
		}
		else
		{
			clearTimeout(t);
			curr_transp=0.6;
			redim_tbl('start');
		}
	}
}
function fade_out()
{
	if(navigator.appName=="Microsoft Internet Explorer")
	{
		curr_transp-=10;
		layer_mare=document.getElementById("Layer1");
		layer_mare.style.filter='alpha(opacity="'+curr_transp+'")';
		if(curr_transp>0)
		{
			t=setTimeout("fade_out();",0.01);
		}
		else
		{
			clearTimeout(t);
			curr_transp=0;
			layer_mare.style.display='none';
			stare="stare_initiala";
		}
	}
	else
	{
		curr_transp-=0.10;
		layer_mare.style.opacity=''+curr_transp+'';
		if(curr_transp>0)
		{
			t=setTimeout("fade_out();",0.01);
		}
		else
		{
			clearTimeout(t);
			curr_transp=0;
			layer_mare.style.visibility='hidden';
			stare="stare_initiala";
		}
	}
}
function redim_tbl(ce)
{
	layer_mic.style.visibility='visible';
	layer_mic.style.width=curr_width+"px";
	layer_mic.style.height=curr_height+"px";
	if(stare=="stare_initiala")
	{				
		juma_de_W=(winW/2)-40;
		juma_de_H=(winH/2)-40;
		
		stare="stare_secundara";
	}

	if(width_poza>(winW-70) || height_poza>(winH-100))
	{
		if(width_poza>height_poza)
		{
			var procent=100-(((winW-70)*100)/width_poza);
			var diffW=Math.round(width_poza-((width_poza*(procent))/100));
			var diffH=Math.round(height_poza-((height_poza*(procent))/100));
			if(diffH>(winH-100))
			{
				var procentFinal=100-(((winH-100)*100)/height_poza);
				new_width_poza=Math.round(width_poza-((width_poza*(procentFinal))/100));
				new_height_poza=Math.round(height_poza-((height_poza*(procentFinal))/100));
			}
		}
		else
		{
			var procent=100-(((winH-100)*100)/height_poza);
			new_width_poza=Math.round(width_poza-((width_poza*(procent))/100));
			new_height_poza=Math.round(height_poza-((height_poza*(procent))/100));
		}

		new_layW=new_width_poza+20;
		new_layH=new_height_poza+35;
	}
	else
	{
		new_width_poza=Math.round(width_poza);
		new_height_poza=Math.round(height_poza);
		new_layW=new_width_poza+20;
		new_layH=new_height_poza+35;
	}

	layer_mic.style.left=juma_de_W+"px";
	layer_mic.style.top=juma_de_H+"px";

	if(ce=='start')
	{
		clearTimeout(t);		
		
		if(width_poza>height_poza)
		{
			if(curr_height<(parseInt(new_height_poza)-10))
			{
				curr_height=curr_height+20;
				juma_de_H=juma_de_H-10;
				juma_de_H_ultimaValoare=juma_de_H-40;
				s=setTimeout("redim_tbl('start');",0.01);
			}
			else
			{
				curr_height=new_layH;
				if(juma_de_H>juma_de_H_ultimaValoare)
				{
					juma_de_H=juma_de_H-40;
				}
				clearTimeout(s);
			}
			
			if(curr_width<new_width_poza)
			{
				curr_width=curr_width+20;
				juma_de_W=juma_de_W-10;
				juma_de_W_ultimaValoare=juma_de_W-20;
				s=setTimeout("redim_tbl('start');",0.01);
			}
			else
			{
				curr_width=new_layW;
				if(juma_de_W>juma_de_W_ultimaValoare)
				{
					juma_de_W=juma_de_W-20;
				}
				clearTimeout(s);

				if(navigator.appName=="Microsoft Internet Explorer")
				{
					document.getElementById(span).innerHTML = '<img src="'+locatie_poza+'/'+nume_poza+'" width="'+new_width_poza+'" height="'+new_height_poza+'" />';
				}
				else
				{
					document.getElementById(span).innerHTML = '<img src="'+locatie_poza+'/'+nume_poza+'" width="'+new_width_poza+'" height="'+new_height_poza+'" />';
				}
			}
		}
		else
		{
			if(curr_width<new_width_poza)
			{
				curr_width=curr_width+20;
				juma_de_W=juma_de_W-10;
				juma_de_W_ultimaValoare=juma_de_W-20;
				s=setTimeout("redim_tbl('start');",0.01);
			}
			else
			{
				curr_width=new_layW;
				if(juma_de_W>juma_de_W_ultimaValoare)
				{
					juma_de_W=juma_de_W-20;
				}
				clearTimeout(s);
			}
			
			if(curr_height<(parseInt(new_height_poza)-10))
			{
				curr_height=curr_height+20;
				juma_de_H=juma_de_H-10;
				juma_de_H_ultimaValoare=juma_de_H-40;
				s=setTimeout("redim_tbl('start');",0.01);
			}
			else
			{
				curr_height=new_layH;
				if(juma_de_H>juma_de_H_ultimaValoare)
				{
					juma_de_H=juma_de_H-40;
				}
				clearTimeout(s);
				
				if(navigator.appName=="Microsoft Internet Explorer")
				{
					document.getElementById(span).innerHTML = '<img src="'+locatie_poza+'/'+nume_poza+'" width="'+new_width_poza+'" height="'+new_height_poza+'">';
				}
				else
				{
					document.getElementById(span).innerHTML = '<img src="'+locatie_poza+'/'+nume_poza+'" width="'+new_width_poza+'" height="'+new_height_poza+'">';
				}
			}
		}
	}
	else
	{
		if(navigator.appName=="Microsoft Internet Explorer")
		{
			document.getElementById(span).innerHTML = '';
		}
		else
		{
			document.getElementById(span).innerHTML = '';
		}
		clearTimeout(s);
		if(width_poza>height_poza)
		{
			if(curr_height>100)
			{
				curr_height=curr_height-10;
				juma_de_H=juma_de_H+5;
				t=setTimeout("redim_tbl('stop');",0.1);
			}
			else
			{
				fade('stop');
				curr_height=100;
				clearTimeout(t);
			}
			
			if(curr_width>100)
			{
				curr_width=curr_width-10;
				juma_de_W=juma_de_W+5;
				t=setTimeout("redim_tbl('stop');",0.1);
			}
			else
			{
				fade('stop');
				curr_width=100;
				clearTimeout(t);
			}
		}
		else
		{
			if(curr_width>100)
			{
				curr_width=curr_width-10;
				juma_de_W=juma_de_W+5;
				t=setTimeout("redim_tbl('stop');",0.1);
			}
			else
			{
				fade('stop');
				curr_width=100;
			}
			
			if(curr_height>100)
			{
				curr_height=curr_height-10;
				juma_de_H=juma_de_H+5;
				t=setTimeout("redim_tbl('stop');",0.1);
			}
			else
			{
				fade('stop');
				curr_height=100;
			}
		}
	}
}


function createRequestObject()
{
	var ro;
	var browser = navigator.appName;
	
	if(browser == "Microsoft Internet Explorer")
	{
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		ro = new XMLHttpRequest();
	}
	return ro;
}

var http = createRequestObject();

function sndReq(action,arg,link_id)
{
	if(action=="load_pic")
	{
		http.open('get', 'http://www.revenues.ro/ultimate_fade/load_pic.php?action='+action+'&locatie='+encodeURIComponent(arg)+'&nume_poza='+encodeURIComponent(link_id));
		http.onreadystatechange = handleResponse;
		http.send(null);
	}
}

function handleResponse()
{
    if(http.readyState == 4)
	{
        var response = http.responseText;
		var continut=""+response+"";
		var tot_textu=response.split('~~~');
		//alert(response);
        var update = new Array();
		
		for(i=0;i<tot_textu.length-1;i++)
		{
			if(tot_textu[i].indexOf('|' != -1))
			{
				update = tot_textu[i].split('|');
				restul_valorilor=update[1];
				var arr_infPoza=update[1].split('###');
				span=update[0];
				locatie_poza=arr_infPoza[0];
				width_poza=arr_infPoza[2];
				height_poza=arr_infPoza[3];
				fade('start');
			}
		}
    }
}
