$nym=jQuery.noConflict();


//this function finds all spans made for <img /> , takes needed attrs for the <img /> tag and intiate image loading with loadimg() function

var enableimg=function(objects)
{  
	

	objects.each
	(	
			function(i,val)
			{	
				var count=$nym(this).find('img').size();
				
				if(count<1)
				{
				
					var i=$nym(this).find('span.nym-post-picture');
					
					
								o = {
										id : i.attr('id'),
										cl : i.attr('class'),
										ttl : i.attr('title'),
										src : i.attr('source'),
										alt : i.attr('alt'),
										w : i.attr('width'),
										h : i.attr('height')
									}
					
					var img='<img src="'+o.src+'" id="'+o.id+'" class="'+o.cl+'" alt="'+o.alt+'" title="'+o.ttl+'" width="'+o.w+'" height="'+o.h+'"  />';
					
					
					
					var destination=$nym(this);
					
					var container=$nym(this).parents('.nym-img-holder');
					
					$nym(this).css('width',o.w+'px');
					$nym(this).css('height',o.h+'px');
					
					loadimg(img,destination,container);
					
				}
			
			}
		
	);
	
}
 	




//this function, hides images that are in loading process and shows the images that are fully loaded

var loadimg=function(img,dest,cont)
{   
	
	$nym(dest).addClass('nym-loading');
	
	$nym(img).load
	(		
		function()
		{	
			$nym(dest).prepend( $nym(this) );
			$nym(dest).removeClass('nym-loading');
		}
	);	
}


//this function loads images if the content container is opened

$nym(document).ready(function() 
{
	
	var containers=$nym('.nym-post-container');
	



	containers.each
	(	
			function(i,val)
			{	
				
				if($nym(this).css('display')!=='none')
				{

					var imgs=$nym(this).find('.nym-img-holder');
					enableimg(imgs);
				}
			
			}
		
	);



	
}
);






$nym(document).ready
(
 function(){
	$nym('a.nym-vote-for-image').click( function(event) 
		{
			
			node1=$nym(this).parents('big').find('.nym-votes-count');
			node1_v=parseInt(node1.html());
			
			node1_v=node1_v+1;
			
			node1.html(node1_v);
			
			$nym(this).css("display","none");
			
		}
	);

  }
);
//








/*makes first image from the post*/
$nym(document).ready(function() {

check=$nym('.nym-post');
if(check.length>0)
{






	check.each
	(
			function(i,val)
			{	
					first_img=$nym(this).find('.nym-first-image');
					if(first_img.size()>0)
					{
						var first_image=first_img.html();
						
						first_image_container=$nym(this).find('.nym-open-post');
						first_image_container.prepend(first_image);
						$nym(this).find('.first-image').html('');
					}
					first_t=$nym(this).find('.nym-first-piece');
					if(first_img.size()>0)
					{
						first_piece=first_t.html();

						first_piece_container=$nym(this).find('.nym-title-text');
						first_piece_container.prepend(first_piece);
						$nym(this).find('.nym-first-piece').html('');
					}
					
			}
		
	);





}


	

	

	img=$nym('.x-intro-t').find('img').css('display','none');
	noder=$nym('.intro-img');
	noder.prepend(img.css('display','block'));
	


});
//









// SHOW post
$nym(document).ready
(
 
 function(){
	$nym('a.nym-open-post-x').click( function(event) 
		{
			
			
			var node = $nym(this).parents('.nym-post').children('.nym-post-container');
					
			var imgs=$nym(this).parents('.nym-post').find('.nym-img-holder');
			
			enableimg(imgs);
			

			
			

				
			
			
		}
	);

  }
);
//





