cms.RootPath = '';
/* TemplateFilter 0x10C80FA000000007 */
local.StartSlideshow = function(g,data,startId,settings) {
	var s = new slideShow();
	s.g = g;
	g.addClass('i001-gallery-slideshow-parent');
	s.ID = Math.floor(Math.random() * 100000);
	local.slideShowTable[s.ID] = s;
	s.SlideshowData = data;
	if (settings) {	for (var x in settings) { s.SlideshowSettings[x] = settings[x]; } }
	s.SlideshowStartId = startId;
	g.data('g',s);
	s.SlideshowPrepareThumbnails();
	s.UnpauseSlideshow();
	s.SlideshowTimeout = setTimeout("local.slideShowTable['" + s.ID + "'].SlideshowExecute()",s.SlideshowSettings.interval);
}

local.slideShowTable = { };

function slideShow() { }
slideShow.prototype.ID = 0;
slideShow.prototype.g = null;
slideShow.prototype.SlideshowIndex = -1;
slideShow.prototype.SlideshowCurrent = null;
slideShow.prototype.SlideshowData = null;
slideShow.prototype.SlideshowTimeout = -1;
slideShow.prototype.SlideshowPaused = false;
slideShow.prototype.SlideshowSettings = {
	interval: 5000,
	transitionInterval: 500,
	thumbSpacing: 120
};
local.PauseSlideshow = function(oLink) { return $(oLink).closest('.i001-gallery-slideshow-parent').data('g').PauseSlideshow(); }
slideShow.prototype.PauseSlideshow = function() {
	var g;
	if (this.SlideshowData) {
		g = this;
	} else if (g == null) {
		g = $(this).closest('.i001-gallery-slideshow-parent').data('g');
	}
	g.SlideshowPaused = true;
	g.g.find('.i001-gallery-slideshow-state .play').removeClass('active');
	g.g.find('.i001-gallery-slideshow-state .pause').addClass('active');
	return false;
};
local.UnpauseSlideshow = function(oLink) { return $(oLink).closest('.i001-gallery-slideshow-parent').data('g').UnpauseSlideshow(); }
slideShow.prototype.UnpauseSlideshow = function() {
	var g;
	if (this.SlideshowData) {
		g = this;
	} else if (g == null) {
		g = $(this).closest('.i001-gallery-slideshow-parent').data('g');
	}
	g.SlideshowPaused = false;
	g.g.find('.i001-gallery-slideshow-state .pause').removeClass('active');
	g.g.find('.i001-gallery-slideshow-state .play').addClass('active');
	return false;
};
slideShow.prototype.SlideshowExecute = function() {
	if (this.SlideshowPaused == true) {
		clearTimeout(this.SlideshowTimeout);
		this.SetTimeout(2);
	} else {
		this.UnpauseSlideshow();
		if (this.SlideshowIndex == -1) this.SlideshowPrepare(this.SlideshowData);
		this.SlideshowChangeTo(this.SlideshowIndex + 1,this.SlideshowData);
	}
};
slideShow.prototype.SlideshowPrepare = function(data) {
	this.SlideshowData = data;
	this.g.find('.i001-gallery-slideshow-img-standby').data('g',this).load(this.SlideshowStandbyLoad).parent().css('z-index',90);
	this.g.find('.i001-gallery-slideshow-img-main').data('g',this).load(this.SlideshowStandbyReset).parent().css('z-index',89);
	for(var i=0; i < data.length; i++) {
		if (parseInt(data[i].ss_id) == this.SlideshowStartId) {
			this.SlideshowIndex = i;
		}
		if (data[i].ss_id > 0) {
			data[i].cacheImg = new Image();
			data[i].cacheImg.src = '/f.ashx?v=' + parseInt(data[i].img_tgt,10);
		}
	}
};
slideShow.prototype.SlideshowChangeTo = function(newIdx,data) {
	if (this.SlideshowIndex == -1) this.SlideshowPrepare(data);
	clearTimeout(this.SlideshowTimeout);
	var oldIdx = this.SlideshowIndex;
	this.SlideshowIndex = newIdx;
	if (this.SlideshowIndex >= data.length - 1) this.SlideshowIndex = 0;
	if (this.SlideshowIndex < 0) this.SlideshowIndex = data.length - 2;

	var t = data[this.SlideshowIndex];
	this.SlideshowCurrent = t;
	this.g.find('.i001-gallery-slideshow-img-standby').attr('src',t.cacheImg.src);
};
slideShow.prototype.SlideshowStandbyReset = function() {
	$(this).css('opacity',1);
	$(this).closest('.i001-gallery-slideshow-parent').find('.i001-gallery-slideshow-img-standby').parent().css('top','-20000px');
};
slideShow.prototype.SlideshowStandbyLoad = function() {
	var g = $(this).data('g');
	if (g == null) return;
	var t = g.SlideshowCurrent;
	if (t == null) return;

	var wrap = g.g.find('.i001-gallery-slideshow-wrap');
	var standby = g.g.find('.i001-gallery-slideshow-img-standby');
	var main = g.g.find('.i001-gallery-slideshow-img-main');

	standby.css('opacity',0).parent().css('top','0');
	main.stop(true).css('opacity',1);
	
	var trans = g.SlideshowSettings.transitionInterval;

	main.stop(true).animate({opacity:0},trans);
	standby.stop(true).animate({opacity: 1},trans,function() {
		main.attr('src',standby.attr('src'));
	});
	wrap.stop(true).animate({height: standby.height()}, trans);

	g.g.find('.i001-gallery-slideshow-title').text(t.title.replace(/&amp;/g,'&'));

	var cap = g.g.find('.i001-gallery-slideshow-caption');
	var sbCap = g.g.find('.i001-gallery-slideshow-caption-standby');
	sbCap.text(t.caption);
	if (t.caption == '' || t.caption == null) {
		cap.parent().stop(true).animate({height: 0},trans,function() { cap.text(''); cap.parent().css('display','none'); });
	} else {
		cap.parent().css('display','block').stop(true).animate({height: sbCap.parent().height()},trans,function() { cap.text(t.caption); });
	}

	g.SlideshowActivateThumbnail(g,t.ss_id);
	g.SetTimeout();
};
slideShow.prototype.SetTimeout = function(divisor) {
	if (divisor > 1) { } else { divisor = 1; }
	this.SlideshowTimeout = setTimeout("local.slideShowTable['" + this.ID + "'].SlideshowExecute()", this.SlideshowSettings.interval / divisor);
}

slideShow.prototype.ThumbOffset = -1;
slideShow.prototype.ThumbListWidth = -1;
slideShow.prototype.ThumbBoxWidth = -1;
slideShow.prototype.ThumbMinPos = 0;
slideShow.prototype.SlideshowPrepareThumbnails = function() {
	var row = this.g.find('.i001-gallery-slideshow-thumbs').data('g',this);
	var inner = row.find('.i001-gallery-thumb_row_inner');

	row.css('overflow','hidden');
	this.ThumbBoxWidth = row.width();

	inner.css('position','absolute').css('left','0');

	var curPos = 0;
	var curIdx = 0;
	var parent = this;
	inner.find('div').each(function() {
		var t = $(this);
		t.css('position','absolute').css('left',curPos).css('float','none');
		this._position = curPos;
		this._idx = curIdx++;
		curPos += parent.SlideshowSettings.thumbSpacing;
	});
	inner.find('a').click(function() {
		var parent = $(this).closest('.i001-gallery-slideshow-parent').data('g');
		parent.SlideshowChangeTo(parseInt($(this).closest('div')[0]._idx),parent.SlideshowData);
		return false;
	});
	this.ThumbListWidth = curPos;
	this.ThumbMinPos = this.ThumbBoxWidth - this.ThumbListWidth;
	
	this.g.find('.i001-gallery-nav.i001-gallery-back a').click(function(){
		var parent = $(this).closest('.i001-gallery-slideshow-parent').data('g');
		parent.SlideshowChangeTo(parent.SlideshowIndex - 1,parent.SlideshowData);
		return false;
	});
	this.g.find('.i001-gallery-nav.i001-gallery-next a').click(function(){
		var parent = $(this).closest('.i001-gallery-slideshow-parent').data('g');
		parent.SlideshowChangeTo(parent.SlideshowIndex + 1,parent.SlideshowData);
		return false;
	});
};
slideShow.prototype.SlideshowActivateThumbnail = function(g,thmId) {
	g.g.find('.i001-gallery-slideshow-nav-parent').find('.i001-gallery-slideshow-item-active').removeClass('i001-gallery-slideshow-item-active');
	var thm = g.g.find('.i001-gallery-slideshow-item-' + parseInt(thmId));
	thm.addClass('i001-gallery-slideshow-item-active');
	var ntPos = (g.ThumbBoxWidth / 2) - (thm[0]._position + (thm.width() / 2));
	if (ntPos < g.ThumbMinPos) ntPos = g.ThumbMinPos;
	if (ntPos > 0) ntPos = 0;
	g.g.find('.i001-gallery-slideshow-thumbs div.i001-gallery-thumb_row_inner').stop(true).animate({left: ntPos},g.SlideshowSettings.transitionInterval);
};
/* TemplateFilter 0x10C80FA00000001A */
local.changeTargetImage = function(smallVerId,largeVerId) {
	cms.Popup.ImgChangeDynamic('#target_img',smallVerId,largeVerId);
	return false;
};
/* TemplateFilter 0x10C80FA0000000E5 */
cms.StdDropdown = function(){
	if (cms.StdDropdownActive == true) { return; }
	$('.w123-std-menu li').hover(
		function() { $(this).closest('li').addClass('open'); },
		function() { $(this).closest('li').removeClass('open'); }
	);
	cms.StdDropdownActive = true;
};
cms.StdDropdownActive = false;

