// JavaScript Document



function imgclick( obj, id , src )
{

	//var pop =  new PopBg( document.body );
	//	pop.setDisplay( true );
	
	
	var loading = new PopFrame( document.body, function()
	{
		return true;
	}  ,  "box_ro"  );

	
	loading.midcell.style.backgroundColor = "#FFF";
	loading.midcell.style.color = "#333";		
	loading.setSize(60	, 60);
	loading.popbg.setDisplay( false );
	loading.setDisplay( true );
	loading.frame.closeButton.thebody.style.display = "none";
	
	var loadingimg = document.createElement("img");
		loading.appendChild( loadingimg );
		loadingimg.src = IMG_DIR+"syc_or_gr.gif";
	
	loading.setDisplay( true );

	
	

	var pop = new PopFrame( document.body, function()
	{
		return true;
	}  ,  "box_ro"  );
	
	pop.midcell.style.backgroundColor = "#FFF";
	pop.midcell.style.color = "#333";		
	pop.setSize(800,600);
	pop.popbg.setDisplay(true);
	//pop.setDisplay( true );
	pop.frame.closeButton.thebody.style.display = "none";
	//alert( pop.frame.closeButton.thebody.tagName );
	
	var linkDiv = document.createElement("div");
	pop.appendChild( linkDiv );
		linkDiv.style.width = "100%";
		linkDiv.align = "left";
		linkDiv.style.paddingBottom = "10px";
	
	
	this.closeButton = new imgButton( linkDiv, linkDiv, IMG_DIR+"close.gif" , "Close", function( event, obj )
	{
		pop.hide();
	} );	
	

	
	var img = document.createElement("img");
		pop.appendChild( img );
		img.style.visibility = "hidden";
		
		img.onload = function()
		{
			pop.setSize( this.offsetWidth,this.offsetHeight );
			
			loading.hide();
			
			if( document.all )
			{
				img.style.visibility = "visible";
				pop.setDisplay( true );
			}
			else
			{
				setOpacity( pop.thebody , 0 );
				img.style.visibility = "visible";
							
				pop.setDisplay( true );
				
				var runner = new transform(
					function( intv ){
						setOpacity( pop.thebody , intv );								
					} , 
					function(){
						setOpacity( pop.thebody , 100 );
					} , 20,  100 );
				runner.run();
			}
		}
				
		img.src = "../img/photos/"+src;

	var link = document.createElement("div");
		pop.appendChild( link );
		link.style.padding = "5px";
		link.innerHTML = "<a class='cotext' href='http://www.jiaart.net/img/photos/"+src+"' >http://www.jiaart.net/img/photos/"+src+"</a>";





}






function fnSetRotation(oObj, deg)
{   
	if( document.all )
	{
		oObj.style.filter = "progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand')";
		
		
		var deg2radians = Math.PI * 2 / 360;
		rad = deg * deg2radians ;
		costheta = Math.cos(rad);
		sintheta = Math.sin(rad);
		
		oObj.filters.item(0).M11 = costheta;
		oObj.filters.item(0).M12 = -sintheta;
		oObj.filters.item(0).M21 = sintheta;
		oObj.filters.item(0).M22 = costheta;
	}
	else
	{
		oObj.style.MozTransform = "rotate("+ deg +"deg)";
		oObj.style.WebkitTransform = "rotate("+ deg +"deg)";
	}
}





function imgOnload( img , size , ro )
{
	
	var width = size;
	var height = parseInt( width*133/200 );
	
	if( document.all )  
	{
		
	}
	else
	{
		setOpacity( img , 0 );
	}
	
	img.style.visibility = "visible";
	
	//alert("Yes");
	var imgHeight = img.offsetHeight;
	var imgWidth = img.offsetWidth;
	
	if( imgWidth > width )
	{
		img.style.width = width + "px";
		img.style.height =  parseInt( width * imgHeight / imgWidth ) + "px";
	}
	
	
	imgHeight = img.offsetHeight;
	imgWidth = img.offsetWidth;
	
	if( imgHeight > height )
	{
		 img.style.height = height + "px";
		 img.style.width = parseInt( height * imgWidth / imgHeight ) + "px";
	}
	
	//img.parentNode.style.paddingTop = parseInt( ( img.parentNode.offsetHeight - imgHeight  ) /2 ) +"px";
	img.parentNode.style.paddingTop = "10px";
	
	//alert( img.offsetWidth );
	
	var deg = getRandomNum( 1, 3 );
	var nag = getRandomNum( 0, 1 );
	
	
	if( nag == 0 ) deg = 360 - deg;
	
	if( ro )
	{
		fnSetRotation( img, deg );	
	}
	
	if( document.all )
	{
		//none
	}
	else
	{
		runner = new transform( function(intv){
		
			setOpacity( img, intv );
		
		}, function(){
			
			setOpacity( img, 100);
			
		}, 15 , 50);
		runner.run();
	}
	
	
}