cms.RootPath = '';
/* WebFilter 0x101000640000013E */
local.DoubleSlideshowIndex = -1;
local.DoubleSlideshowCurrent = null;
local.DoubleSlideshowData = null;
local.DoubleSlideshowTimeout = -1;
local.DoubleSlideshowPaused = false;
local.DoubleSlideshowStandbyLoadCount = 0;
local.DoubleSlideshowLoadCount = 0;
local.DoubleSlideshowSettings = {
	interval: 5000,
	transitionInterval: 500,
	thumbSpacing: 120
};
local.PauseDoubleSlideshow = function() {
	local.DoubleSlideshowPaused = true;
	$('.gallery-slideshow-state .play').removeClass('active');
	$('.gallery-slideshow-state .pause').addClass('active');
	return false;
};
local.UnpauseDoubleSlideshow = function() {
	local.DoubleSlideshowPaused = false;
	$('.gallery-slideshow-state .pause').removeClass('active');
	$('.gallery-slideshow-state .play').addClass('active');
	return false;
};
local.DoubleSlideshowExecute = function(data) {
	if (local.DoubleSlideshowPaused == true) {
		clearTimeout(local.DoubleSlideshowTimeout);
		local.DoubleSlideshowTimeout = setTimeout(function(){local.DoubleSlideshowExecute(data);},local.DoubleSlideshowSettings.interval / 2);
	} else {
		local.UnpauseDoubleSlideshow();
		if (local.DoubleSlideshowIndex == -1) local.DoubleSlideshowPrepare(data);
		local.DoubleSlideshowChangeTo(local.DoubleSlideshowIndex + 1,data);
	}
};
local.DoubleSlideshow = function(data, settings) {
	local.DoubleSlideshowPrepare(data);
	if (settings) {	for (var x in settings) { local.DoubleSlideshowSettings[x] = settings[x]; } }
	local.DoubleSlideshowPrepareThumbnails();
	local.UnpauseDoubleSlideshow();
	local.DoubleSlideshowTimeout = setTimeout(function(){local.DoubleSlideshowExecute(data);},local.DoubleSlideshowSettings.interval);
};
local.DoubleSlideshowPrepare = function(data) {
	local.DoubleSlideshowData = data;
	var main1 = $('#gallery-slideshow-img-left-main');
	var main2 = $('#gallery-slideshow-img-right-main');
	$('#gallery-slideshow-img-left-standby').load(local.DoubleSlideshowStandbyLoadWrap).parent().css('z-index',90);
	$('#gallery-slideshow-img-right-standby').load(local.DoubleSlideshowStandbyLoadWrap).parent().css('z-index',90);
	main1.load(local.DoubleSlideshowStandbyResetWrap).parent().css('z-index',89);
	main2.load(local.DoubleSlideshowStandbyResetWrap).parent().css('z-index',89);
	for(var i=0; i < data.length; i++) {
		if (parseInt(data[i].ss_id) == local.DoubleSlideshowStartId) {
			local.DoubleSlideshowIndex = i;
		}
		if (data[i].ss_id > 0) {
			data[i].cacheImg1 = new Image();
			data[i].cacheImg1.src = '/f.ashx?v=' + parseInt(data[i].img1_tgt,10);
			data[i].cacheImg2 = new Image();
			data[i].cacheImg2.src = '/f.ashx?v=' + parseInt(data[i].img2_tgt,10);
		}
	}
};
local.DoubleSlideshowChangeTo = function(newIdx,data) {
	if (local.DoubleSlideshowIndex == -1) local.DoubleSlideshowPrepare(data);
	clearTimeout(local.DoubleSlideshowTimeout);
	var oldIdx = local.DoubleSlideshowIndex;
	local.DoubleSlideshowIndex = newIdx;
	if (local.DoubleSlideshowIndex >= data.length - 1) local.DoubleSlideshowIndex = 0;
	if (local.DoubleSlideshowIndex < 0) local.DoubleSlideshowIndex = data.length - 2;

	var t = data[local.DoubleSlideshowIndex];
	local.DoubleSlideshowCurrent = t;
	$('#gallery-slideshow-img-left-standby').attr('src',t.cacheImg1.src);
	$('#gallery-slideshow-img-right-standby').attr('src',t.cacheImg2.src);
};
local.DoubleSlideshowStandbyResetWrap = function() {
	local.DoubleSlideshowStandbyLoadCount++;
	if (local.DoubleSlideshowStandbyLoadCount >= 2) {
		local.DoubleSlideshowStandbyLoadCount = 0;
		local.DoubleSlideshowStandbyReset();
	}
}
local.DoubleSlideshowStandbyLoadWrap = function() {
	local.DoubleSlideshowLoadCount++;
	if (local.DoubleSlideshowLoadCount >= 2) {
		local.DoubleSlideshowLoadCount = 0;
		local.DoubleSlideshowStandbyLoad();
	}
}
local.DoubleSlideshowStandbyReset = function() {
	$('#gallery-slideshow-img-left-main').css('opacity',1);
	$('#gallery-slideshow-img-right-main').css('opacity',1);
	$('#gallery-slideshow-img-left-standby').parent().css('top','-20000px');
	$('#gallery-slideshow-img-right-standby').parent().css('top','-20000px');
};
local.DoubleSlideshowStandbyLoad = function() {
	var t = local.DoubleSlideshowCurrent;
	if (t == null) return;

	var wrap = $('#gallery-slideshow-wrap');
	var standby1 = $('#gallery-slideshow-img-left-standby');
	var standby2 = $('#gallery-slideshow-img-right-standby');
	var main1 = $('#gallery-slideshow-img-left-main');
	var main2 = $('#gallery-slideshow-img-right-main');

	standby1.css('opacity',0).parent().css('top','0');
	standby2.css('opacity',0).parent().css('top','0');
	
	var trans = local.DoubleSlideshowSettings.transitionInterval;

	wrap.stop(true).animate({height: Math.max(standby1[0].height,standby2[0].height) + 2}, trans);
	main1.stop(true).css('opacity',1).animate({opacity:0},trans);
	main2.stop(true).css('opacity',1).animate({opacity:0},trans);
	standby1.stop(true).css('opacity',0).animate({opacity: 1},trans,function() {
		main1.attr('src',standby1.attr('src'));
	});
	standby2.stop(true).css('opacity',0).animate({opacity: 1},trans,function() {
		main2.attr('src',standby2.attr('src'));
	});

	var cap = $('#gallery-slideshow-caption1');
	local.DoubleSlideshowSetCaption(cap,t.caption1);
	cap = $('#gallery-slideshow-caption2');
	local.DoubleSlideshowSetCaption(cap,t.caption2);

	local.DoubleSlideshowActivateThumbnail(t.ss_id);
	local.DoubleSlideshowTimeout = setTimeout(function(){local.DoubleSlideshowExecute(data);},local.DoubleSlideshowSettings.interval);
};
local.DoubleSlideshowSetCaption = function(cap,text) {
	if (text == '' || text == null) {
		cap.text('').css('display','none');
	} else {
		cap.text(text).css('display','block');
	}
};

local.DoubleThumbOffset = -1;
local.DoubleThumbListWidth = -1;
local.DoubleThumbBoxWidth = -1;
local.DoubleThumbMinPos = 0;
local.DoubleSlideshowPrepareThumbnails = function() {
	var row = $('#gallery-slideshow-thumbs');
	var inner = row.find('.thumb_row_inner');

	row.css('overflow','hidden');
	local.DoubleThumbBoxWidth = row.width();

	inner.css('position','absolute').css('left','0');

	var curPos = 0;
	var curIdx = 0;
	inner.find('div.thumb_item').each(function() {
		var t = $(this);
		t.css('position','absolute').css('left',curPos).css('float','none');
		this._position = curPos;
		this._idx = curIdx++;
		curPos += local.DoubleSlideshowSettings.thumbSpacing;
	});
	inner.find('a').click(function() {
		local.DoubleSlideshowChangeTo(parseInt($(this).closest('div.thumb_item')[0]._idx),local.DoubleSlideshowData);
		return false;
	});
	local.DoubleThumbListWidth = curPos;
	local.DoubleThumbMinPos = local.DoubleThumbBoxWidth - local.DoubleThumbListWidth;
	
	$('.nav.back a').click(function(){local.DoubleSlideshowChangeTo(local.DoubleSlideshowIndex - 1,local.DoubleSlideshowData);return false;});
	$('.nav.next a').click(function(){local.DoubleSlideshowChangeTo(local.DoubleSlideshowIndex + 1,local.DoubleSlideshowData);return false;});
};
local.DoubleSlideshowActivateThumbnail = function(thmId) {
	$('#gallery-slideshow-nav-parent').find('.gallery-slideshow-item-active').removeClass('gallery-slideshow-item-active');
	var thm = $('#gallery-slideshow-item-' + parseInt(thmId));
	thm.addClass('gallery-slideshow-item-active');
	var ntPos = (local.DoubleThumbBoxWidth / 2) - (thm[0]._position + (thm.width() / 2));
	if (ntPos < local.DoubleThumbMinPos) ntPos = local.DoubleThumbMinPos;
	if (ntPos > 0) ntPos = 0;
	$('#gallery-slideshow-thumbs div.thumb_row_inner').stop(true).animate({left: ntPos},local.DoubleSlideshowSettings.transitionInterval);
};
/* WebFilter 0x101000640000018B */
local.pagePickerSearch = function(oText) {
	if (oText._searchTimeout) { clearTimeout(oText._searchTimeout); }
	oText._searchTimeout = setTimeout(function() {
		oText._searchTimeout = null;
		var ot = $(oText);
		if (oText._lower == null) oText._lower = ot.closest('.cms-page-search').find('.cms-page-search-lower');
		var lwr = oText._lower;
		if (lwr._oldHtml == null) { lwr._oldHtml = $(lwr).html(); }
		if (oText._searchXhr != null) {
			// Request already in progress
			oText._searchQueued = true;
		} else if (oText.value == '' && lwr._oldHtml != null) {
			lwr.html(lwr._oldHtml);
		} else if (oText._lastSearch != oText.value) {
			// Nothing queued
			oText._searchQueued = false;
			ot.closest('div').addClass('active');
			oText._lastSearch = oText.value;
			oText._searchXhr = $.getJSON(cms.RootPath + '/wf.ashx?f=search.json&t=269484034&q=' + encodeURIComponent(oText.value),
				function(sData) {
					$(lwr).empty();
					var h = $(lwr).closest('.ui-dialog-content').height();
					ot.closest('div').removeClass('active');
					ot.closest('.cms-page-search').find('.cms-page-search-lower').scrollTop(0);
					if(sData.length == 0) {
						var outer = $('<div />').addClass('cms-info');
						var inner = $('<div />').addClass('cms-info-inner').addClass('cms-info-info').html('<p>No results found.</p>').appendTo(outer);
						outer.appendTo(lwr);
					} else {
						for (var idx = 0; idx < sData.length; idx++) {
							var sObj = sData[idx];
							var item = $('<div/>').addClass('cms-page-search-result').addClass(idx % 2 == 0 ? 'list-even':'list-odd');
							var hdr = $('<div/>').addClass('cms-page-search-result-title');
							var link = $('<a/>');
							link[0]._type_id = sObj['type_id'];
							link[0]._object_id = sObj['object_id'];
							link.click(function(){storeCmsLink('{{'+this._type_id+':'+this._object_id+'}}');return false;});
							if(sObj['hl_title'])
								link.html(sObj['hl_title']);
							else
								link.text(sObj['title']);
							link.attr('href',sObj['link']).appendTo(hdr);
							hdr.appendTo(item);
							$('<div/>').addClass('cms-page-search-result-url').text(sObj['link']).appendTo(item);
							if(sObj['summary']) $('<div/>').addClass('cms-page-search-result-body').html(sObj['summary']).appendTo(item);
							item.appendTo(lwr);
							var l = $(lwr);
							l.height(h - l.position().top + 24);
						}
					}
					oText._searchXhr = null;
					if (oText._searchQueued == true) {
						oText._searchQueued = false;
						local.pagePickerSearch(oText);
					}
				});
		}
	}, 300);
};
/* WebFilter 0x101000640000018C */
local.filePickerSearch = function(oText,iFolder) {
	if (oText._searchTimeout) { clearTimeout(oText._searchTimeout); }
	oText._searchTimeout = setTimeout(function() {
		oText._searchTimeout = null;
		var ot = $(oText);
		if (oText._lower == null) oText._lower = ot.closest('.cms-page-search').find('.cms-page-search-lower');
		var lwr = oText._lower;
		if (lwr._oldHtml == null) { lwr._oldHtml = $(lwr).html(); }
		if (oText._searchXhr != null) {
			// Request already in progress
			oText._searchQueued = true;
		} else if (oText.value == '' && lwr._oldHtml != null) {
			lwr.html(lwr._oldHtml);
		} else if (oText._lastSearch != oText.value) {
			// Nothing queued
			oText._searchQueued = false;
			ot.closest('div').addClass('active');
			oText._lastSearch = oText.value;
			oText._searchXhr = $.getJSON(cms.RootPath + '/wf.ashx?f=search.json&t=268566529&q=' + encodeURIComponent(oText.value) + '&file.folder=' + parseInt(iFolder,10),
				function(sData) {
					$(lwr).empty();
					var h = $(lwr).closest('.ui-dialog-content').height();
					ot.closest('div').removeClass('active');
					ot.closest('.cms-page-search').find('.cms-page-search-lower').scrollTop(0);
					var result = false;
					if (sData.length > 0) {
						for (var idx = 0; idx < sData.length; idx++) {
							var sObj = sData[idx];
							var size = parseInt(sObj['size'],10);
							if (size > 0) {
								var item = $('<div/>').addClass('cms-page-search-result').addClass('cms-file-search-result').addClass(idx % 2 == 0 ? 'list-even':'list-odd');
								var thm = parseInt(sObj['thumbnail'],10);
								if (thm != 0) {
									var imgLink = $('<a/>')
										.click(function(){storeFileChoice(this._object_id);return false;})
										.attr('href',sObj['link'])
										.appendTo($('<div/>')
										.addClass('cms-file-search-image')
										.appendTo(item));
									imgLink[0]._type_id = sObj['type_id'];
									imgLink[0]._object_id = sObj['object_id'];
									$('<img/>').attr('src',cms.RootPath + '/f.ashx?v=' + thm).appendTo(imgLink);
								}
								var hdr = $('<div/>').addClass('cms-page-search-result-title');
								var link = $('<a/>');
								link[0]._type_id = sObj['type_id'];
								link[0]._object_id = sObj['object_id'];
								link.click(function(){storeFileChoice(this._object_id);return false;});
								if(sObj['hl_title'])
									link.html(sObj['hl_title']);
								else
									link.text(sObj['title']);
								link.attr('href',sObj['link']).appendTo(hdr);
								hdr.appendTo(item);
								$('<div/>').addClass('cms-page-search-result-right').text(((Math.round(parseFloat(sObj['size']) / 1024) * 100) / 100) + ' kB').appendTo(item);
								$('<div/>').addClass('cms-page-search-result-url').text(sObj['path']).appendTo(item);
								$('<a/>').attr('href',sObj['download']).attr('target','_blank').text('download')
									.appendTo($('<div/>').addClass('cms-page-search-result-right').appendTo(item));
								$('<div/>').addClass('cms-page-search-result-url').text(sObj['mime']).appendTo(item);
								$('<div/>').addClass('cms-page-search-result-end').appendTo(item);
								if(sObj['summary']) $('<div/>').addClass('cms-page-search-result-body').html(sObj['summary']).appendTo(item);
								item.appendTo(lwr);
								var l = $(lwr);
								l.height(h - l.position().top + 24);
								result = true;
							}
						}
					}
					if (result == false) {
						var outer = $('<div />').addClass('cms-info');
						var inner = $('<div />').addClass('cms-info-inner').addClass('cms-info-info').html('<p>No results found.</p>').appendTo(outer);
						outer.appendTo(lwr);
					}
					oText._searchXhr = null;
					if (oText._searchQueued == true) {
						oText._searchQueued = false;
						local.pagePickerSearch(oText);
					}
				});
		}
	}, 300);
};
