/* gallery.js Fitted for Media Day
 * author : yeongun 
 * last update: 2008.07.16 
 * (c) 2008 ncsoft UIDevelopment Team */
var Gallery = {
	data:[],
	idx:{ group:0,item:0,count:0 },
	load:function(dataUrl) {
		var galRequest = new Ajax.Request(
			dataUrl,
			{
				method:'get',
				onSuccess:function(galRequest) {
					var galData=galRequest.responseXML;
					var galGroup=galData.getElementsByTagName('Group');
					var galItem,galAtt;
					if (galGroup.length==0) return;
					var addHashData=function(gidx, idx, item) {
						var title=item.getAttribute('name');
						var value=item.getAttribute('value');
						var type=item.getAttribute('type') ? item.getAttribute('type') : 0;
						var trk=item.getAttribute('trk') ? item.getAttribute('trk') : 0;
						var finalValue=type ? [value,type,trk] : value;
						Gallery.data[gidx].items[idx].set(title, finalValue);
					};
					for (var i=0;i<galGroup.length;i++) {
						Gallery.data[i]={
							idx:i,
							title:galGroup[i].getAttribute('title'),
							description:galGroup[i].getAttribute('description'),
							items:[]
						}
						galItem=galGroup[i].getElementsByTagName('item');
						for (var j=0;j<galItem.length;j++) {
							Gallery.data[i].items[j]=new Hash({ 'idx':j });
							galAtt=galItem[j].getElementsByTagName('attribute');
							for (var k=0;k<galAtt.length;k++) {
								addHashData(i,j,galAtt[k]);
							}
						}					
					}
					Gallery.group();
					if (!Gallery.option.count) Gallery.option.count=20;
					Gallery.play(Gallery.idx.group,Gallery.idx.item);
				}
			}
		);
	},
	play:function(groupNum,itemNum) {
		if ($('wrap_gal_thumbArea')) $('wrap_gal_thumbArea').hide();
		Gallery.idx.item=itemNum;
		Gallery.list('gal_list',groupNum,Gallery.option.count);
		Gallery.display(Gallery.data[groupNum].items[itemNum],'gal_display');
		Gallery.navigation.stop();
		Gallery.navigation.observe();
		Gallery.navigation.load();
	},
	list:function(targetArea,idx,count) {
		if (!$(targetArea)) return;
		var count=(count<=Gallery.data[idx].items.length) ? count : Gallery.data[idx].items.length;
		var disphtml='<ul>';
			for (var j=0; j<count; j++) {
				if (Gallery.data[idx].items[j].get('swf'))
					disphtml+='<li class="media"><img src=\"'+ Gallery.data[idx].items[j].get('src') +'\" onclick=\"Gallery.display(Gallery.data['+idx+'].items['+j+'],\'gal_display\');\" alt=\"'+ Gallery.data[idx].items[j].get('title') +'\" /></li>';
				else disphtml+='<li><img src=\"'+ Gallery.data[idx].items[j].get('src') +'\" onclick=\"Gallery.display(Gallery.data['+idx+'].items['+j+'],\'gal_display\');\" alt=\"'+ Gallery.data[idx].items[j].get('title') +'\" /></li>';
			}
		disphtml+='</ul>';
		$(targetArea).innerHTML=disphtml;
		$(targetArea).hide();
		new Effect.Appear(targetArea,{duration:0.3,from:0.0,to:1.0});
		if($('gal_group')&&$('gal_group').select('li').length!=0) {
			var thisGroup=$('gal_group').select('li');
			thisGroup[Gallery.idx.group].className='';
			thisGroup[idx].className='on';
			Gallery.idx.group=idx;		
		}
	},
	addList:function(targetArea,count,func) {
		var start=$(targetArea).select('ul')[0].select('li').length;
		if (start==Gallery.data[Gallery.idx.group].items.length) return;
		var count=(count<Gallery.data[Gallery.idx.group].items.length-start) ? start+count : Gallery.data[Gallery.idx.group].items.length;
		var currentList=$(targetArea).select('ul')[0];
		for (var i=start;i<count;i++) {
			currentList.innerHTML+='<li><img src=\"'+ Gallery.data[Gallery.idx.group].items[i].get('src') +'\" onclick=\"Gallery.display(Gallery.data['+Gallery.idx.group+'].items['+i+'],\'gal_display\');\" alt=\"'+ Gallery.data[Gallery.idx.group].items[i].get('title') +'\" /></li>';
		}
		Gallery.idx.count=$(targetArea).select('li').length;
		if (!func)  return;
		else scrollControl();
		function scrollControl() {
			var current=parseInt(parseInt($('gal_thumbArea').getStyle('top'))/10);
			Gallery.thumbscroll.slider.setDisabled();
			Gallery.thumbscroll=new Scroll('gal_thumbArea','scroll_handle',function() {
				Gallery.addList('gal_thumbArea',8,1);
			});
			Gallery.thumbscroll.slider.setValueBy(-current);
		}
	},
	display:function(selectedData,displayArea) {
		if (!selectedData) return;
		if ($('gal_mediaplay')) $('wrap_gallery').removeChild($('gal_mediaplay'));
		if ($('gal_thumblist')&&$('gal_thumblist').getStyle('display')!='none') {
			$('gal_thumblist').hide();
			$('gal_thumbArea').setStyle({top:0}).hide();
			if ($('wrap_scroll_handle')) $('wrap_scroll_handle').hide();
			$('gal_thumbArea').select('li')[Gallery.idx.item].className='';
		}
		var data=selectedData;
		var dataSrc=data.get('src');
		dataSrc=Gallery.util.check(data.get('idx'));
		if ($('gal_list')&&data.get('idx')>=$('gal_list').select('li').length) $('gal_progress').setStyle({display:'block'});
		if (!$('gal_ready')) $('wrap_gallery').appendChild(Builder.node('div',{id:'gal_ready'}));
		else $('gal_ready').update('');
		$('gal_ready').update('<img src="'+dataSrc+'" id="dispImg" />');
		$('dispImg').observe('load',function() {
			var image=Gallery.util.mag($(displayArea),$('dispImg'));
			var xpos=image.areaX/2-image.width/2;
			var ypos=image.areaY/2-image.height/2;
			$(displayArea).update('<img src=\"'+ dataSrc +'\" onclick=\"Gallery.popup.open(this,'+ data.get('idx') +');\" style="width:'+image.width+'px;height:'+image.height+'px;top:'+ypos+'px;left:'+xpos+'px;" id="showimg" alt=\"'+ data.get('title') +'\" />');
			$('showimg').hide();
			var loadList=function() {
				if (!$('gal_list')) { Gallery.idx.item=data.get('idx'); return; }
				$('gal_list').select('li')[Gallery.idx.item].className=''; 
				Gallery.idx.item=data.get('idx');
				Gallery.description();
				Gallery.navigation.go(selectedData.get('listIndex'));
				$('gal_list').select('li')[Gallery.idx.item].className='on';
				Gallery.navigation.disable();
			}
			if ($('gal_list')&&data.get('idx')>=$('gal_list').select('li').length) {
				var count=data.get('idx') - $('gal_list').select('li').length+Gallery.navigation.count;
				Gallery.addList('gal_list',count);
				Gallery.navigation.load();
				loadList();
			}
			else loadList();
			/* Media Day Fit */
			if (data.get('swf')) {
				$('wrap_gallery').appendChild(Builder.node('div',{id:'gal_mediaplay'}));
				swfobject.embedSWF(data.get('swf'), 'gal_mediaplay', "489", "389", "9,0,124",'',{},{wmode:"transparent"});
				if ($('gal_progress')) $('gal_progress').hide();
			}
			else {
				new Effect.Appear('showimg',{duration:0.2,from:0.0,to:1.0,beforeStart:function() {
						if ($('gal_prev_img')) $('gal_prev_img').hide();
						if ($('gal_next_img')) $('gal_next_img').hide();
						if ($('gal_prev_img')) { 
							var prevIdx=parseInt(Gallery.idx.item-1);
							var prevImage=(Gallery.idx.item!=0) ? '<img src=\"'+ Gallery.data[Gallery.idx.group].items[prevIdx].get('src') + '\" onclick=\"Gallery.display(Gallery.data['+Gallery.idx.group+'].items['+prevIdx+'], \'gal_display\');\" alt=\"\" />' : '';
							$('gal_prev_img').update(prevImage);
						}	
						if ($('gal_next_img')) { 
							var nextIdx=parseInt(Gallery.idx.item+1);
							var nextImage=(Gallery.idx.item!=Gallery.data[Gallery.idx.group].items.length-1) ? '<img src=\"'+ Gallery.data[Gallery.idx.group].items[nextIdx].get('src') + '\" onclick=\"Gallery.display(Gallery.data['+Gallery.idx.group+'].items['+nextIdx+'], \'gal_display\');\" alt=\"\" />' : '';
							$('gal_next_img').update(nextImage);
						}							
					},afterFinish:function() {
						if ($('gal_progress').getStyle('display')=='block') $('gal_progress').hide();
						if ($('gal_prev_img')) new Effect.Appear('gal_prev_img',{duration:0.3,from:0.0,to:1.0});
						if ($('gal_next_img')) new Effect.Appear('gal_next_img',{duration:0.3,from:0.0,to:1.0});
					}
				});
			}
			if ($('gal_list')) Gallery.idx.count=$('gal_list').select('li').length;
		});
	},
	description:function() {
		var option=Gallery.option.item;
		var ititem=Gallery.data[Gallery.idx.group].items[Gallery.idx.item];
		var filterdeData;
		/* Media Day Fit */
		if ($('gal_download')&&$('gal_download').getStyle('display')=='none') {
			$('gal_download').setStyle({display:'block'});
		}
		for (var i=0;i<option.length;i++) {
			if (Object.isUndefined(ititem.get(option[i])))	{
				$('gal_'+option[i]).setStyle({display:'none'});
			}
			else {
				if ($('gal_'+option[i]).getStyle('display')=='none') { 
					$('gal_'+option[i]).setStyle({display:''}); 
				}
				if (typeof ititem.get(option[i])=='object'&&ititem.get(option[i])[1]=='link'&&$('gal_'+option[i])) {
					$('gal_'+option[i]).setAttribute('href',ititem.get(option[i])[0]);
					/*add trk*/
					$('gal_'+option[i]).setAttribute('rel',option[i]);
					Event.stopObserving('gal_'+option[i],'mousedown',Gallery.addTrk);
					Event.observe('gal_'+option[i],'mousedown',Gallery.addTrk);
				}
				else {
					filterdeData=ititem.get(option[i]).replace(/#br#/g,	"<br />");
					$('gal_'+option[i]).update(filterdeData);
				}
			}
		}
		if ($('gal_pos')) $('gal_pos').update(Gallery.idx.item+1 + '/' + Gallery.data[Gallery.idx.group].items.length);
		filteredData=null;
	},
	addTrk:function(e) {
		var element=Event.element(e).ancestors()[0];
		var trkcode=Gallery.data[Gallery.idx.group].items[Gallery.idx.item].get(element.getAttribute('rel'))[2];
		if (trkcode) eval('try{ _trk_clickTrace( \'EVT\', \''+trkcode+'\' ); }catch(_e){ }');
		element=null;
		trkcode=null;
	},
	thumblist:function(idx) {
		Gallery.navigation.stop();
		if ($('gal_thumblist_close')) $('gal_thumblist_close').observe('click',function() { Gallery.display(Gallery.data[Gallery.idx.group].items[Gallery.idx.item],'gal_display') });
		var count=(Gallery.idx.count>Gallery.option.count) ? Gallery.idx.count : Gallery.option.count;
		Gallery.list('gal_thumbArea',idx,count);
		var scrollArea = $('gal_thumbArea').ancestors()[0];
		$('gal_thumblist').setStyle({display:'block'});
		new Effect.Appear('wrap_gal_thumbArea',{duration:0,from:0.0,to:0.8});
		$('gal_thumbArea').select('li')[Gallery.idx.item].className='on';
		if (scrollArea.getHeight()<$('gal_thumbArea').getHeight()) {
			if (!$('wrap_scroll_handle')) {
				$('gal_thumblist').appendChild(Builder.node('div',{id:'wrap_scroll_handle'}));
				$('wrap_scroll_handle').appendChild(Builder.node('div',{id:'scroll_handle'}));
			}
			else $('wrap_scroll_handle').show();
			Gallery.thumbscroll=new Scroll('gal_thumbArea','scroll_handle',function() {
				Gallery.addList('gal_thumbArea',8,1);
			});
		}
	},
	navigation:{
		width:0,
		basis:0,
		index:[],
		group:0,
		count:0,
		status:0,
		load:function() {
			var width=parseInt($('gal_list').getStyle('width'));
			var height=parseInt($('gal_list').getStyle('height'));
			var item=$('gal_list').select('li')[0];
			var itemWidth=parseInt(item.getStyle('width'));
			var itemHeight=parseInt(item.getStyle('height'));
			var itemRight=parseInt(item.getStyle('marginRight'));
			var itemBottom=parseInt(item.getStyle('marginBottom'));
			Gallery.navigation.count=parseInt(((width*height)+itemRight+itemBottom)/((itemWidth+itemRight)*(itemHeight+itemBottom)));
			var itemTotal=$('gal_list').select('li').length;
			Gallery.navigation.group=parseInt(itemTotal/Gallery.navigation.count+1);
			Gallery.navigation.basis=(Gallery.option.thumbtype!='vertical') ? parseInt($('gal_list').select('ul')[0].getStyle('left')) : parseInt($('gal_list').select('ul')[0].getStyle('top'));
			if (Gallery.option.thumbtype!='vertical')
				$('gal_list').select('ul')[0].setStyle({width:itemTotal*(itemWidth+itemRight) + itemWidth + 'px'});
			for (var i=0;i<itemTotal;i++) {
				Gallery.data[Gallery.idx.group].items[i].set('listIndex',parseInt(i/Gallery.navigation.count + 1));
			}
			for (var j=0;j<Gallery.navigation.group;j++) {
				if (Gallery.option.thumbtype!='vertical') {
					if (j==0)	Gallery.navigation.index[j]=width*j;
					else	Gallery.navigation.index[j]=-(width*j+itemRight*j);
				}
				else {
					if (j==0)	Gallery.navigation.index[j]=height*j;
					else	Gallery.navigation.index[j]=-(height*j+itemBottom*j);
				}
			}
		},
		observe:function() {
			if ($('gal_prev')) {
				$('gal_prev').observe('click',function() {
					Gallery.navigation.stop();
					Gallery.display(Gallery.data[Gallery.idx.group].items[Gallery.idx.item-1],'gal_display');
				});
			}
			if ($('gal_next')) {
				$('gal_next').observe('click',function() {
					Gallery.navigation.stop();
					Gallery.display(Gallery.data[Gallery.idx.group].items[Gallery.idx.item+1],'gal_display');
				});
			}
			if ($('gal_thumb')) {
				$('gal_thumb').onclick=function() {	Gallery.thumblist(Gallery.idx.group); }
			}
			if ($('gal_before')) {
				$('gal_before').stopObserving('click',Gallery.navigation.before);
				$('gal_before').observe('click',Gallery.navigation.before);
			}
			if ($('gal_after')) {
				$('gal_after').stopObserving('click',Gallery.navigation.after);
				$('gal_after').observe('click',Gallery.navigation.after);
			}
			if ($('gal_play')) {
				$('gal_play').stopObserving('click',Gallery.navigation.auto);
				$('gal_play').observe('click',Gallery.navigation.auto);
			}
		},
		before:function() {
			Gallery.navigation.stop();
			var target=parseInt(Gallery.idx.item%Gallery.navigation.count);
			target=Gallery.idx.item - Gallery.navigation.count - target;
			Gallery.display(Gallery.data[Gallery.idx.group].items[target],'gal_display');
		},
		after:function() {
			Gallery.navigation.stop();
			var target=parseInt(Gallery.idx.item%Gallery.navigation.count);
			target=Gallery.idx.item + Gallery.navigation.count - target;
			if ((Gallery.idx.item+1)%Gallery.navigation.count==0) target=Gallery.idx.item+1;
			Gallery.display(Gallery.data[Gallery.idx.group].items[target],'gal_display');	
		},		
		auto:function() {
			if (Gallery.navigation.status==0)	Gallery.navigation.play();
			else Gallery.navigation.stop();				
		},
		go:function(target) {
			var basisTest=(Gallery.option.thumbtype!='vertical');
			var basis= basisTest ? parseInt($('gal_list').select('ul')[0].getStyle('left')) : parseInt($('gal_list').select('ul')[0].getStyle('top'));
			if (Gallery.navigation.index[target - 1] == basis) return;
	  	var goal = Gallery.navigation.index[target - 1] - basis;
	  	if (basisTest) new Effect.Move($('gal_list').select('ul')[0], { x: goal, y: 0	});
	  	else new Effect.Move($('gal_list').select('ul')[0], { x: 0, y: goal	});	  	
			Gallery.navigation.basis = Gallery.navigation.index[target - 1];
		},
		stop:function() { 
				if (Gallery.navigation.status==0) return;
				clearInterval(Gallery.navigation.status);
				if ($('gal_play')) $('gal_play').src=$('gal_play').src.replace('stop.','play.');
				Gallery.navigation.status=0;
		},
		play:function() {
			if ($('gal_play')) $('gal_play').src=$('gal_play').src.replace('play.','stop.');
			var idx=Gallery.idx.item;
			Gallery.navigation.status=setInterval(function() {
				idx++;
				if (Object.isUndefined(Gallery.data[Gallery.idx.group].items[idx])) {
					Gallery.navigation.stop();
					return;
				}
				Gallery.display(Gallery.data[Gallery.idx.group].items[idx],'gal_display');
			},2000);
		},
		disable:function() {
			var itemLength=Gallery.data[Gallery.idx.group].items.length-1;
			var listLength=Math.ceil(Gallery.data[Gallery.idx.group].items.length/Gallery.navigation.count);
			var listIndex=Gallery.data[Gallery.idx.group].items[Gallery.idx.item].get('listIndex');			
			if (Gallery.idx.item==0) convertImg('gal_prev',1);
			else convertImg('gal_prev',0);
			if (Gallery.idx.item==itemLength) convertImg('gal_next',1); 
			else convertImg('gal_next',0);
			if (listIndex==1) convertImg('gal_before',1);
			else convertImg('gal_before',0);
			if (listIndex==listLength) convertImg('gal_after',1);
			else convertImg('gal_after',0);
			function convertImg(objectId,value) {
				if (!$(objectId)) return;
				var item=($(objectId).tagName.toUpperCase()=='IMG') ? $(objectId) : $(objectId).select('img')[0];
				if (Object.isUndefined(item)) return;
				var itemSrc=item.src;
				var fileType=itemSrc.substr(itemSrc.lastIndexOf('.'),itemSrc.length);
				if (value) itemSrc=(itemSrc.indexOf('_off.')!=-1) ? itemSrc : itemSrc.replace(fileType,'_off'+fileType);
				else itemSrc=itemSrc.replace('_off'+fileType,fileType);
				item.src=itemSrc;			
			}					
		}		
	},
	group:function() {
		if (!$('gal_group')) return;
		if (Gallery.data.length<=1) return;
		var groupTag='<ul>';
		for (var i=0;i<Gallery.data.length;i++) {
			groupTag+='<li onclick=\"Gallery.play('+ i +',0)\"><div><img src=\"' + Gallery.data[i].items[0].get('src') + '\" /></div><h6>' + Gallery.data[i].title + '</h6><p>' + Gallery.data[i].description + '</p></li>';
		}
		groupTag+='</ul>';
		$('gal_group').update(groupTag);
	},
	popup:{
		id:0,
		status:0,
		before:{},
		after:{},
		load:function() {
				var browser=function() {
					if (document.documentElement.clientHeight) return [document.documentElement.clientWidth,document.documentElement.clientHeight];
					else if (window.innerHeight) return [window.innerWidth,window.innerHeight];
					else return [0,0];
				}
				var imgSize=[$('popupImg').getWidth(),$('popupImg').getHeight()];
				var pdvalue=[$('gal_popup').getWidth()-$('popupImg').getWidth(),$('gal_popup').getHeight()-$('popupImg').getHeight()];
				var areaSize=[browser()[0]-pdvalue[0],browser()[1]-pdvalue[1]];
				var mag=(imgSize[0]/areaSize[0]>imgSize[1]/areaSize[1]) ? imgSize[0]/areaSize[0] : imgSize[1]/areaSize[1];
				var xwidth, xheight;
				if (mag>1) {
					xwidth=parseInt(imgSize[0]/mag);
					xheight=parseInt(imgSize[1]/mag);
				}
				else {
					xwidth=imgSize[0];
					xheight=imgSize[1];
				}
				$('popupImg').setStyle({
					width:xwidth+'px',
					height:xheight+'px'
				});
				/* Media Day Fit */
				$('popup_navi').setStyle({width:xwidth+'px'});

				var divSize=[$('gal_popup').getWidth(),$('gal_popup').getHeight()];
				var scrollTop=Position.realOffset(Gallery.util.body)[1];
				var xpos=parseInt(browser()[0]/2-divSize[0]/2);
				var ypos=parseInt(browser()[1]/2-divSize[1]/2) + scrollTop;
				if (ypos<0) ypos=0;
				var fact=(Gallery.popup.status) ? 0 : -50;
				$('gal_popup').setStyle({ top:ypos+fact+'px',left:xpos+'px'});
				if (Gallery.popup.status==0) { 
					$('gal_popup').hide();
					new Effect.Parallel([new Effect.Appear('gal_popup'),new Effect.MoveBy('gal_popup',50,0),new Effect.Opacity('gal_popup',{sync:true,from:0.0,to:1.0})],{duration:0.5});
					new Draggable('gal_popup',{handle:'popup_handle',starteffect:false,endeffect:false});
				}
		},
		navi:{
			goleft:function() {
				Gallery.popup.open(Gallery.popup.before,Gallery.popup.before.info,0);
			},
			goright:function() {
				Gallery.popup.open(Gallery.popup.after,Gallery.popup.after.info,0);
			}
		},
		open:function(object,info,end) {
			if (Object.isUndefined(Gallery.data[Gallery.idx.group].items[info])) return;
			var chInfo, chStatus;
			var thisGroup=Gallery.data[Gallery.idx.group].items.length-1;			
			if (!Object.isUndefined(Gallery.data[Gallery.idx.group].items[info].get('swf'))) {
				if (Gallery.popup.before.info==info) { chInfo=info-1; chStatus=0; }
				else { chInfo=info+1; chStatus=1; }
				if (Object.isUndefined(Gallery.data[Gallery.idx.group].items[chInfo])) return;
				if (chInfo>0) {
					Gallery.popup.before={
						src:Gallery.data[Gallery.idx.group].items[chInfo-1].get('src'),
						info:(chStatus) ? chInfo-1 : chInfo
					}						
				}
				if (chInfo<thisGroup) {
					Gallery.popup.after={
						src:Gallery.data[Gallery.idx.group].items[chInfo+1].get('src'),
						info:(chStatus) ? chInfo : chInfo+1
					}
				}				
				Gallery.popup.open({
					src:Gallery.data[Gallery.idx.group].items[chInfo].get('src'),
					info:chInfo
				},chInfo,1)
				return;
			}
			
			if (parseInt($('gal_popup').getStyle('top'))>=0) Gallery.popup.status=1;
			var id='popupImg';
			if (!$('popup')) $('gal_popup').appendChild(Builder.node('div',{id:'popup'}));
			var objectSrc=Gallery.util.check(info);
			var imgInfo='<img src=\"'+ objectSrc +'\" class="image" id="'+ id +'" alt="" />';
			if (!Object.isUndefined(info)) {
				Event.stopObserving('popImg_prev','click',Gallery.popup.navi.goleft);
				Event.stopObserving('popImg_next','click',Gallery.popup.navi.goright);
				if (info>0) {
					Gallery.popup.before={
						src:Gallery.data[Gallery.idx.group].items[info-1].get('src'),
						info:info-1
					}
					Event.observe('popImg_prev','click',Gallery.popup.navi.goleft);
				}
				if (info<thisGroup) {
					Gallery.popup.after={
						src:Gallery.data[Gallery.idx.group].items[info+1].get('src'),
						info:info+1
					}
					Event.observe('popImg_next','click',Gallery.popup.navi.goright);
				}


				// popup layer data
				var ititem=Gallery.data[Gallery.idx.group].items[info];
				var option=Gallery.option.item;
				for (var i=0;i<option.length;i++) {
					if (Object.isUndefined(ititem.get(option[i])))	{
						if ($('gal_pop_'+option[i])) $('gal_pop_'+option[i]).setStyle({display:'none'});
					}
					else {
						if ($('gal_pop_'+option[i])) {
							if ($('gal_pop_'+option[i]).getStyle('display')=='none') 
								$('gal_pop_'+option[i]).setStyle({display:''}); 
						}
						if (typeof ititem.get(option[i])=='object'&&ititem.get(option[i])[1]=='link'&&$('gal_pop_'+option[i])) {
							if (!ititem.get('swf')) {
								$('gal_pop_'+option[i]).setAttribute('href',ititem.get(option[i])[0]);
								/*add trk*/
								$('gal_pop_'+option[i]).setAttribute('rel',option[i]);
								Event.stopObserving('gal_pop_'+option[i],'mousedown',Gallery.addTrk);
								Event.observe('gal_pop_'+option[i],'mousedown',Gallery.addTrk);
							}
						}
					}
				}
				/* Media Day Fit: Except Button Disabled */
			}
			$('popup').innerHTML=imgInfo;
			$(id).observe('click', Gallery.popup.close);			
			Event.stopObserving(id,'load',Gallery.popup.load);
			Event.observe(id,'load',Gallery.popup.load);
			objectSrc=null;
		},
		close:function() {
				$('gal_popup').setStyle({top:'-2000px',left:0});
				Event.stopObserving('popupImg','load',Gallery.popup.load);
				$('gal_popup').removeChild($('popup'));
				Gallery.popup.status=0;
		}
	},
	util:{
		body:$$('body')[0],
		mag:function(area,object) {
			var areaSize={width:area.clientWidth,height:area.clientHeight};
			var imageSize={width:object.clientWidth,height:object.clientHeight};
			var xwidth,xheight,mag;
			mag=(imageSize.width/areaSize.width>imageSize.height/areaSize.height) ? imageSize.width/areaSize.width : imageSize.height/areaSize.height; 
			if (mag>1) {
				xwidth=imageSize.width/mag;
				xheight=imageSize.height/mag;
			}
			else {
				xwidth=imageSize.width;
				xheight=imageSize.height;
			}
			return { width:parseInt(xwidth),height:parseInt(xheight),areaX:parseInt(areaSize.width),areaY:parseInt(areaSize.height) }
		},
		check:function(info) {
			var displayItem=Gallery.data[Gallery.idx.group].items[info];
			if (Object.isUndefined(displayItem.get('origin'))) {
				return displayItem.get('src');
			}
			else {	
				return displayItem.get('origin'); 
			}
		}
	}
};

