/*
 * THIS IS FREE SCRIPT BUT LEAVE THIS COMMENT IF
 * YOU WANT USE THIS CODE ON YOUR SITE
 * 
 * Made by Wilq32, wilq32@gmail.com, Wroclaw, Poland, 01.2009
 * 
 */

if (typeof Wilq32 == "undefined") 
    Wilq32 = {Author:"Wilq32"}
	
Wilq32._IE =/MSIE ([0-9]{1,}[\.0-9]{0,})/.test(navigator.userAgent) ? true : false;

  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}


  
Wilq32.ClientWidth=myWidth;
Wilq32.ClientHeight=myHeight;



Wilq32.ImageEffects = function()
{
	
	var images=document.getElementsByTagName('img');

	for (var i=0,j=images.length;i<j;i++)
	{
		var match;

		if (match = images[i].className.match(/Wilq32.ImageEffects\(([^,]+){0,1}\,{0,1}([^,]+){0,1}\,{0,1}([^,]+){0,1}\)/)) 
			{
				Wilq32.ImageEffects.attachEffects(images[i],match[1],match[2],match[3])
			}
	}
}

Wilq32.ImageEffects.attachEffects = function(element,arg1,arg2,arg3)
{
	element.ImageEffects={}
	element.ImageEffects.smallImage=element.src;
	element.ImageEffects.bigImage=arg1;
	element.ImageEffects.fx=new Fx.Morph(element);
	$(element).setStyles({
			position: "relative",
			top: 0,
			left: 0
		});
	if (element.width>0)
	{
		element.ImageEffects.width=element.width;
		element.ImageEffects.height=element.height;	
	}
	element.onload=function()
	{
		this.ImageEffects.width=this.width;
		this.ImageEffects.height=this.height;
	}

	element.onmouseover=function()
	{
		this.ImageEffects.fx.cancel();
		this.ImageEffects.fx.start({
				width: this.ImageEffects.width + 10,
				height: this.ImageEffects.height + 10,
				top: "-5px",
				left: "-5px"
			});
	}
	element.onmouseout = function()
	{

		this.ImageEffects.fx.cancel();
		this.ImageEffects.fx.start({
				width: this.ImageEffects.width,
				height: this.ImageEffects.height,
				top: "0px",
				left: "0px"
			});
	}
	element.onclick= function()
	{
		var self=this;
		var tempImage=new Image();
		$(self).setStyles({opacity:0.5});
		tempImage.src=this.ImageEffects.bigImage;
		document.body.appendChild(tempImage);
		$(tempImage).setStyles({display:"none"});
		tempImage.onload=function()
		{
				$(self).setStyles({opacity:1});
				var temp=document.createElement('div');
				var pos=Wilq32.ImageEffects.FindPos(self);
				document.body.appendChild(temp);
				$(temp).setStyles({position:"fixed",top:0,left:0,width:"100%",height:"100%"});
				temp.appendChild(tempImage);
				var sizes=[this.width,this.height];
				$(tempImage).setStyles({backgroundColor:"white",position:"absolute",top:pos[1]-f_scrollTop(),left:pos[0]-f_scrollLeft(),display:"block",width:self.ImageEffects.width+10,height:self.ImageEffects.height+10});
				self.ImageEffects.fx.cancel();
				new Fx.Morph(tempImage,{link:"chain"}).start({
						width: sizes[0],
						height: sizes[1],
						top:Wilq32.ClientHeight/2 - sizes[1]/2,
						left: Wilq32.ClientWidth/2 - sizes[0]/2
					}).start({
							border: ["0px black solid", "3px black solid"],
							padding: '10px',
							margin: '-10px'
						});//.complete(function(){alert('test');});
				temp.onclick = function()
					{
						document.body.removeChild(this);
					}
		}
		if (Wilq32._IE) if (tempImage.complete) tempImage.onload();
	}
}
Wilq32.ImageEffects.FindPos = function(obj)
	{
		var curleft = 0, curtop = 0;
		if (obj.offsetParent) 
			{
				do 
					{
						curleft += obj.offsetLeft;
						curtop += obj.offsetTop;
					}
				while (obj = obj.offsetParent);
				return [curleft, curtop];
			}
	}
Wilq32.ImageEffects();

