var width_space = 10;
var width_image = 230;
var i_result,i_images,i_count=3, con_result;

function init()
{
	i_result=document.getElementById("content");
	if(i_result)
	{
		i_images=i_result.getElementsByTagName("td");
		window.onresize=resize;
		resize();
	}
}

function count()
{
	c=Math.floor((document.documentElement.offsetWidth-295-28-28)/(width_image+width_space));
	return c>0?c:1;
}
	
function resize()
{
	var cols=count();
	if(i_count==cols)
	{
		return;
	}	
	i_count=cols;
	var table=document.createElement("table");
	var tbody=document.createElement("tbody");
	var rows=i_images.length/cols;
	
	width=100/cols;

	for(j=0;j<rows;j++)
	{
		row=document.createElement("tr");
		for(i=0;i<cols;i++)
		{
			if(!i_images[0])
			{
				break;
			}
			
			i_images[0].style.width=width+"%";
			row.appendChild(i_images[0]);
		}
		
		tbody.appendChild(row);
	}
	
	table.appendChild(tbody);
	//table.setAttribute('class', 'gallery');
	table.className = 'gallery';
	table.setAttribute('id', 'gallery');
	i_result.appendChild(table);
	var prev=table.previousSibling;
	if(prev!=null)prev.parentNode.removeChild(prev);
	return;
}
	
	
function open_gallery(img, wg, hg)
{

	h = document.documentElement.scrollHeight;
	w = document.documentElement.clientWidth;
	h1 = document.documentElement.clientHeight;
	p = document.documentElement.scrollTop;
	x = (w-wg)/2;
	y =Math.round((h1-hg)/2)+p;
	if($('#img_gallery').html() == null)
	{
		$('#bg_gallery').after('<div id="img_gallery" onclick="return close_gallery();"><div class="close"><a href="#" onclick="close_gallery(); return false;"><img src="/i/close.gif" width="13" height="13" ></a></div><div class="picture"><img src="'+img+'" width="'+wg+'" height="'+hg+'"></div></div>');
		$('#bg_gallery').show();
	}	
	$('#bg_gallery').css({height:h, width:w});
	$('#img_gallery').css({left:x, top:y});
	$('#sel_type').hide();
	$('#sel_status').hide();
}

function close_gallery()
{
	
	$('#img_gallery').remove();
	$('#bg_gallery').hide();
	$('#sel_type').show();
	$('#sel_status').show();
	return false;
}
	
function flash_decoder()
{
	var w,h,i;
	var l = $('.video_object').length;
	var str = String(navigator.userAgent);
	w=320;
	h=240;
	if(l > 0)
	{
		for(i=0; i<l; i++)
		{
			if(!str.match(/(MSIE)/gi)) j = i;
			else j = 0;
						
			$('.video_object').eq(j).attr('id', 'video'+i).wrap('<div class="video"></div>');
			$('.video_object').eq(j).parent().eq(0).attr({'alt':$('.video_object').eq(j).attr('alt'), 'style':$('.video_object').eq(j).attr('style'), 'border':$('.video_object').eq(j).attr('border')});
			file = $('.video_object').eq(j).attr('afile');
			var n = $('.video_object').eq(j).attr('aname');
			
			if(parseInt($('.video_object').eq(j).css('width'))){
				w = parseInt($('.video_object').eq(j).css('width'));
				var w1 = parseInt($('.video_object').eq(j).attr('width'));
				if(w1!=0 && w1>w) w = w1;
			}	
			if(parseInt($('.video_object').eq(j).css('height'))){
				h = parseInt($('.video_object').eq(j).css('height'));
				var h1 = $('.video_object').eq(j).attr('height');
				if(h1!=0 && h1>h) h = h1;
			}
			
			if(!str.match(/(MSIE)/gi)){
				swfobject.embedSWF("/i/mediaplayer.swf", 'video'+i, w, h, "9.0.0", "/i/expressInstall.swf", {"width":w, "height":h, "file":file}, {"fullscreen":false, "wmode":"transparent"}, {"name":n});
			}else{ 
			$('#video'+i).replaceWith('<object id="video'+i+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+w+'" height="'+h+'"> <param name="flashvars" value="width='+w+'&height='+h+'&file='+file+'"/> <param name="allowfullscreen" value="true" /><param name="movie" value="/i/mediaplayer.swf"/> <param name="Src" value="/i/mediaplayer.swf"> <param name="Play" value="0"> <param name="Loop" value="-1"> <param name="Quality" value="High"> <param name="SAlign" value="LT"> <param name="wmode" value="transparent"/></object>');
			}
			$('#video'+i).parent().eq(0).css({"height":h, "width":w}).show();	
		}
	}
}