/* Init */

function checkImg(pclass, wmax, hmax){
	
	jQuery('.'+pclass+' img').each(function(index){
		var cw = jQuery(this).width();
		var ch = jQuery(this).height();
		var nw = cw;
		var nh = ch;
		var mod = false;
		
		if(cw>wmax){
			nw = wmax;
			nh = parseInt((ch/cw)*wmax);
			
			if(nh>hmax){
				nw = parseInt((nw/nh)*hmax);
				nh = hmax;
			}
			mod = true;
		}
		else {
			if(nh>hmax){
				nw = parseInt((nw/nh)*hmax);
				nh = hmax;
				mod = true;
			}
		}
		
		if(mod==true){
			jQuery(this).width(nw);
			jQuery(this).height(nh);
			jQuery(this).css('cursor','pointer');
			jQuery(this).click(function(){
				jQuery.fancybox({
					'href'			: jQuery(this).attr('src'),
					'title'   		: jQuery(this).attr('title'),
					//'orig'			: $(this),
					'padding'		: 0,
					'hideOnContentClick': true
					//'transitionIn'	: 'elastic',
					//'transitionOut'	: 'elastic'
				});
			});
		}
	});
}

function initCheckImg(){
	checkImg('post_sig',820,150);
	checkImg('member_sig',400,150);
	checkImg('post_body',820,600);
	checkImg('post_home',625,500);
}

jQuery(document).ready(function(){

	initCheckImg();
	setTimeout("initCheckImg();", 2000);
	setTimeout("initCheckImg();", 5000);
	
	jQuery('a.imgattachment').each(function(index){
		jQuery(this).click(function(){
			jQuery.fancybox({
				'href'			: jQuery(this).attr('href'),
				'title'   		: jQuery(this).attr('title'),
				//'orig'			: $(this),
				'padding'		: 0,
				'hideOnContentClick': true
				//'transitionIn'	: 'elastic',
				//'transitionOut'	: 'elastic'
			});
			return false;
		});
	});
	
});
