﻿gallery={
	el:{
		thumbLinks:null,
		imgFullPop:null, bPopClose:null,
		imgFullGalContainer:null
	},
	initEl:function(){
		var el=this.el;
		el.thumbLinks=$('.thumbgallery > li > a');
		el.imgFullPop=$('.imagefullpop');
		el.bPopClose=$('a.close', el.imgFullPop);
		el.imgFullGalContainer=$('.img-scroll', el.imgFullPop);
	},
	// config method
	afterShowFuncs:[],
	afterShow:function(func){
		if(typeof(func)=='function')
			this.afterShowFuncs.push(func);
	},
	doAfterShow:function(pageIndex){
		$.each(this.afterShowFuncs, function(i,o){
			if(typeof(o)=='function') o(pageIndex);
		});
	},
	// end
	prepareGallery:function(t, callback){
		var _this=this; var el=this.el;
		var o=$(t);
		var parent=o.parent('li').parent('ul').parent('div.slide-page').parent('div.slide-scroll');
		var allGal=$('a', parent);
		var html=''; var cIndex=0;
		$.each(allGal, function(_i,_o){
			var tHref=o.attr('href');
			var href=$(_o).attr('href');
			if(tHref==href) cIndex=_i;
			html+='<img src="'+href+'" alt="" width="890" height="494" />';
		});
		el.imgFullGalContainer.html(html);
		//$('.img-scroll-container').scrollTo((890*cIndex), 0);
		if(typeof(callback)=='function') callback();
	},
	zoomPhoto:function(t){
		var _this=this; var el=this.el;
		var o=$(t);
		var parent=o.parent('li').parent('ul').parent('div.slide-page').parent('div.slide-scroll');
		var allGal=$('a', parent);
		var cIndex=0;
		if(_this.afterShowFuncs && _this.afterShowFuncs.length>0){
			$.each(allGal, function(_i,_o){
				var tHref=o.attr('href');
				var href=$(_o).attr('href');
				if(tHref==href) cIndex=_i;
			});
			el.imgFullGalContainer.html('<img src="'+o.attr('href')+'" alt="" width="890" height="494" />');
			this.prepareGallery(t, function(){
				el.imgFullPop.fadeIn(400, function(){
					_this.doAfterShow(cIndex);
				});
			});
		}else{
			el.imgFullGalContainer.html('<img src="'+o.attr('href')+'" alt="" width="890" height="494" />');
			el.imgFullPop.fadeIn(400, function(){});
		}
		return false;
	},
	initEvents:function(){
		var el=this.el;
		/*
		el.thumbLinks.mousedown(function(){
			el.imgFullPop.fadeIn();
			return false;
		});
		*/
		el.bPopClose.unbind('click').bind('click', function(){
			el.imgFullPop.fadeOut();
			return false;
		});
	},
	init:function(){
		this.initEl();
		this.initEvents();
	}
};
$(function(){
	gallery.init();
});
