$(function(){
	//$('a img','.subCategory').click(function(){ popImage(this); return false;});
	$('a[href^=#]').click(function(){return false;})
	var slideshow='#slideshow #photo';
	if($(slideshow).length) changeImage(0,json_slideshow,slideshow);
});

popImage=function(ref){
	if(!$(ref).length) return false;
	
	var klass='popImage';
	var pImage=$('#popImage');
	if(pImage.length) pImage.remove();
	//$('html').removeClass().addClass('oH');
	//var layer=$('<div id=layer/>').css('opacity',.5).attr('title','Double click to Close').prependTo(document.body);
	var oSRC=$(ref).attr('src').toString();
	var nSRC=oSRC.replace(/(\/<=)?0|_0/ig,'')||$(ref).parent().attr('href');
	$(new  Image()).load(function(){
						  var W=this.width;
						  var H=this.height;
						  var S=this.src;
						  var A=this.alt;
						  var T=this.title;
						  //var wH=$(window).height();
						  //var wW=$(window).width();
						  var IMG=$('<img id=popImage/>').attr({src:S,alt:S,title:T,width:W,height:H}).prependTo(document.body);
						  IMG.css({
								  position:'absolute',
								  zIndex:9696,
								  //top:(wH-H)/2, 
								  //left:(wW-W)/2,
								  top:'50%',
								  left:'50%', 
								  marginLeft:-(W/2), 
								  marginTop:-(H/2),
								  lineHeight:H,
								  textAlign:'center',
								  display:'block',
								  border:'1px solid #000',
								  background:'#f0f0f0'
								  }).click(function(){return removeLayer(this);});
						  }).attr({'src':nSRC,'alt':'loading...','title':'Click to close'})
}

removeLayer=function(ref){
	if($(ref).length) $(ref).remove(); 
	$('html').removeClass();
	return false;
}

changeImage=function(index,json,ref){
	var SRC=path_slideshow+escape(json[index].s);
	var TITLE=json[index].t;
	$(new Image).load(function(){
						var image=$('<img  src="'+this.src+'" title="'+this.title+'"/>');
						index=(index>=json.length-1)?0:index+=1;
						$(image).appendTo($(ref).empty())
								.hide()
								.fadeIn(1000,function(){
						window.setTimeout(function(){image.fadeOut(1000,function(){
															image.remove();
															changeImage(index,json,ref)});
												   			},3000);
													});
						

			   }).attr({src:SRC,title:TITLE});
}
