var arrWallpaper = ['eggman','shade','shadow','amy','knuckles','kron','tails','gunpawn','big','sonic2','rogue'];
var arrScreenshots = [42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1];

var obj = null;

// png fix
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(s($){3.1s.1k=s(j){j=3.1a({12:\'1m.1j\'},j);8 k=(n.P=="r 10 Z"&&U(n.v)==4&&n.v.E("14 5.5")!=-1);8 l=(n.P=="r 10 Z"&&U(n.v)==4&&n.v.E("14 6.0")!=-1);o(3.17.16&&(k||l)){3(2).L("1r[@m$=.M]").z(s(){3(2).7(\'q\',3(2).q());3(2).7(\'p\',3(2).p());8 a=\'\';8 b=\'\';8 c=(3(2).7(\'K\'))?\'K="\'+3(2).7(\'K\')+\'" \':\'\';8 d=(3(2).7(\'A\'))?\'A="\'+3(2).7(\'A\')+\'" \':\'\';8 e=(3(2).7(\'C\'))?\'C="\'+3(2).7(\'C\')+\'" \':\'\';8 f=(3(2).7(\'B\'))?\'B="\'+3(2).7(\'B\')+\'" \':\'\';8 g=(3(2).7(\'R\'))?\'1d:\'+3(2).7(\'R\')+\';\':\'\';8 h=(3(2).1c().7(\'1b\'))?\'19:18;\':\'\';o(2.9.y){a+=\'y:\'+2.9.y+\';\';2.9.y=\'\'}o(2.9.t){a+=\'t:\'+2.9.t+\';\';2.9.t=\'\'}o(2.9.w){a+=\'w:\'+2.9.w+\';\';2.9.w=\'\'}8 i=(2.9.15);b+=\'<x \'+c+d+e+f;b+=\'9="13:11;1q-1p:1o-1n;O:W-V;N:1l;\'+g+h;b+=\'q:\'+3(2).q()+\'u;\'+\'p:\'+3(2).p()+\'u;\';b+=\'J:I:H.r.G\'+\'(m=\\\'\'+3(2).7(\'m\')+\'\\\', D=\\\'F\\\');\';b+=i+\'"></x>\';o(a!=\'\'){b=\'<x 9="13:11;O:W-V;\'+a+h+\'q:\'+3(2).q()+\'u;\'+\'p:\'+3(2).p()+\'u;\'+\'">\'+b+\'</x>\'}3(2).1i();3(2).1h(b)});3(2).L("*").z(s(){8 a=3(2).T(\'N-S\');o(a.E(".M")!=-1){8 b=a.X(\'1g("\')[1].X(\'")\')[0];3(2).T(\'N-S\',\'1f\');3(2).Q(0).Y.J="I:H.r.G(m=\'"+b+"\',D=\'F\')"}});3(2).L("1e[@m$=.M]").z(s(){8 a=3(2).7(\'m\');3(2).Q(0).Y.J=\'I:H.r.G\'+\'(m=\\\'\'+a+\'\\\', D=\\\'F\\\');\';3(2).7(\'m\',j.12)})}1t 3}})(3);',62,92,'||this|jQuery||||attr|var|style|||||||||||||src|navigator|if|height|width|Microsoft|function|padding|px|appVersion|margin|span|border|each|class|alt|title|sizingMethod|indexOf|scale|AlphaImageLoader|DXImageTransform|progid|filter|id|find|png|background|display|appName|get|align|image|css|parseInt|block|inline|split|runtimeStyle|Explorer|Internet|relative|blankgif|position|MSIE|cssText|msie|browser|hand|cursor|extend|href|parent|float|input|none|url|after|hide|gif|pngFix|transparent|blank|line|pre|space|white|img|fn|return'.split('|'),0,{}))


$j(document).ready(function() {
	
	$j(document).pngFix();
	
	$j('.gallery .wallpaper, .gallery .screenshot, .gallery .video').click(function(){
		var arrRotation=[];
		var itemSelected;
		var galleryType = $j(this).attr('class');
		var url = $j(this).attr('href');
		
		var queryString = url.replace(/^[^\?]+\??/,'');
		var params = tb_parseQuery( queryString );
		
		$j('.txtNumber').val('');
		url = '#TB_inline?inlineId=pop&width=550&height=387';
		$j('.txtGalleryType').val(galleryType);
		
		if(galleryType=='video'){
			var video = queryString.split('=')[1];
			
			url = '#TB_inline?inlineId=pop&width=440&height=480';
			$j('#miolo-pop').html('');
			$j('#miolo-pop').addClass('video');
			$j('.pop').removeClass('pop2');
			$j('.pop').addClass('pop3');
			$j('.selSize').hide();
			$j('.btPrevious').hide();
			$j('.btNext').hide();
			$j('#miolo-pop').flash({ 
				src: '_swf/flashSonic.swf',
				wmode: 'transparent',
				width: 394,
				height: 360,
				flashvars: { xmlPath: '_xml/movies.xml', video:'_media/'+video+'.flv', videoHolder:video }
			},
			{ version: 8 });
		}else{
			$j('#miolo-pop').html('<img id="img" src="_img/loading.gif" width="450" height="281" alt="" class="preview" />');
			$j('.btPrevious').show();
			$j('.btNext').show();
			$j('.pop').removeClass('pop3');
			$j('.pop').removeClass('pop2');
			$j('#miolo-pop').removeClass('video');

			if(galleryType=='wallpaper'){
				$j('.selSize').show();
				galleryType='_wallpapers';
				arrRotation = arrWallpaper;
				$j("#img").attr('width','450');
				$j("#img").attr('height','281');
			}

			else{
				url = '#TB_inline?inlineId=pop&width=420&height=520';
				$j('.pop').addClass('pop2');
				$j('.selSize').hide();
				galleryType='_screenshots';
				arrRotation = arrScreenshots;
				$j("#img").attr('width','308');
				$j("#img").attr('height','460');				
			}

			//Loop Array
			itemSelected = 0;
			itemButton = 0
			$j(arrRotation).each(function(i){
				if(params['img']==arrRotation[i])itemSelected=i;
			});

			$j('.txtNumber').val(itemSelected);

			//Set Image Selected
			$j('.selSize').val('');
			$j("#img").attr('src','_img/_gallery/' + galleryType + '/_lightbox/lbx_'+arrRotation[itemSelected]+'.jpg');
			
			$j('.selSize').unbind('change');
			$j('.selSize').change(function(){
				if ($j(this).val() != '') {
					itemSelected = $j('.txtNumber').val();
					window.open('_img/_gallery/' + galleryType + '/' + $j(this).val() + '/' + arrRotation[itemSelected] + $j(this).val() + '.jpg')
				}
			});

		}
		
		openPopGallery(url,galleryType);
		return false;
	});
	
	//Button Previous
	$j('.btPrevious').click(function(){
		var galleryType = $j('.txtGalleryType').val();
		var arrRotationGallery=[];
		if(galleryType=='wallpaper'){
			$j('.selSize').show();
			galleryType='_wallpapers';
			arrRotationGallery = arrWallpaper;
		}
		else{
			$j('.selSize').hide();
			galleryType='_screenshots';
			arrRotationGallery = arrScreenshots;
			
		}
		
		itemButton = parseInt($j('.txtNumber').val())-1;
		
		
		if(itemButton<0){itemButton=arrRotationGallery.length-1}
		$j('.selSize').val('');
		$j("#img").attr('src','_img/_gallery/' + galleryType + '/_lightbox/lbx_'+arrRotationGallery[itemButton]+'.jpg');
		$j('.txtNumber').val(itemButton)
		return false;
	});
	
	//Button Next
	$j('.btNext').click(function(){
		var galleryType = $j('.txtGalleryType').val();
		var arrRotationGallery=[];
	
		if(galleryType=='wallpaper'){
			$j('.selSize').show();
			galleryType='_wallpapers';
			arrRotationGallery = arrWallpaper;
		}
		else{
			$j('.selSize').hide();
			galleryType='_screenshots';
			arrRotationGallery = arrScreenshots;
			
		}
		
		
		itemButton = parseInt($j('.txtNumber').val())+1;
		//itemButton = parseInt(itemButton+1);
		if(itemButton>arrRotationGallery.length-1){itemButton=0}
		$j('.selSize').val('');
		$j("#img").attr('src','_img/_gallery/' + galleryType + '/_lightbox/lbx_'+arrRotationGallery[itemButton]+'.jpg');
		$j('.txtNumber').val(itemButton)
		return false;
	});

	$j('.mn-sub').hover(function() {
		if (obj) {
			obj.find('ul').fadeOut('fast');
			obj = null;
		} //if
		
		$j(this).find('ul').fadeIn('fast');
	}, function() {
		obj = $j(this);
		setTimeout(
			"checkHover()",
			400);
	});

});

function checkHover() {
	if (obj) {
		obj.find('ul').fadeOut('fast');	
	} //if
} //checkHover

		
function showPage(pag){	
	$j('.pag').hide();
	$j('#p'+pag).show();
	$j('.sel').removeClass('on');
	$j('.selp'+pag).addClass('on');
}