svCoreURL = typeof svCoreURL === 'undefined' ? 'svcore/': svCoreURL;
document.write('<script type="text/javascript" src="' + svCoreURL + 'js/jquery-1.3.2.min.js"></script>');
document.write('<script type="text/javascript" src="' + svCoreURL + 'js/swfobject.js"></script>');
document.write('<link rel="stylesheet" href="' + svCoreURL + 'css/simpleviewer.css" type="text/css">');
var SV = {};
SV.simpleviewer = (function () {
	var n;
	var o, currentPhoto, currentImageObj, pageWidth;
	var p, winWidth;
	var q, containerHeight, svWidth, svHeight, backgroundColor;
	var r = {};
	var s, svContainerId;
	var t, winOverflow;
	var u = '';
	var v = 'sv' + (new Date()).getTime();
	var w = '9.0.124';
	var x, params, attributes;
	var y = screen.availHeight && screen.availHeight > 500 ? 14 : 11;
	var z = 50;
	var A = 1;
	function parseXML(b) {
		try {
			var c = $(b).find('simpleviewergallery');
			r = {
				'showOpenButton': c.attr('showOpenButton') && c.attr('showOpenButton').toLowerCase() === 'false' ? false: true,
				'showFullscreenButton': c.attr('showFullscreenButton') && c.attr('showFullscreenButton').toLowerCase() === 'false' ? false: true,
				'useFlickr': c.attr('useFlickr') && c.attr('useFlickr').toLowerCase() === 'true' ? true: false,
				'mobileShowCaption': c.attr('mobileShowCaption') && c.attr('mobileShowCaption').toLowerCase() === 'false' ? false: true,
				'mobileShowNav': c.attr('mobileShowNav') && c.attr('mobileShowNav').toLowerCase() === 'false' ? false: true,
				'flickrUserName': c.attr('flickrUserName') || '',
				'flickrTags': c.attr('flickrTags') || '',
				'imagePath': c.attr('imagePath') || '',
				'thumbPath': c.attr('thumbPath') || '',
				'mobileTransition': c.attr('mobileTransition') ? c.attr('mobileTransition').toLowerCase() : 'slide',
				'images': []
			};
			c.find('image').each(function () {
				var a;
				if (r.images.length < z) {
					a = {
						imageURL: (typeof svGalleryPath !== 'undefined' ? svGalleryPath: '') + ($(this).attr('imageURL') || ''),
						thumbURL: (typeof svGalleryPath !== 'undefined' ? svGalleryPath: '') + ($(this).attr('thumbURL') || ''),
						imageFullURL: $(this).attr('linkURL') || ((typeof svGalleryPath !== 'undefined' ? svGalleryPath: '') + ($(this).attr('imageURL') || '')),
						linkTarget: $(this).attr('linkTarget') || '_blank',
						caption: '',
						preloadedImage: null,
						preloaded: false
					};
					if ($(this).find('caption').length > 0) {
						a.description = $(this).find('caption:first').text()
					}
					r.images.push(a)
				}
			})
		} catch(e) {
			errorMessage('Cannot Parse Gallery XML.')
		}
		return r
	};
	function generateSVHtml() {
		var a;
		a = '<div id="sv-mobile" class="simpleviewer" style="background: #' + backgroundColor + ';" >';
		a += '<div id="sv-photos" ></div>';
		a += '<div id="sv-prev-photo"><span></span></div>';
		a += '<div id="sv-next-photo"><span></span></div>';
		a += '<a href="" id="' + v + '"></a>';
		a += '<div id="sv-topmenu"><div id="sv-topmenu-right"></div><div id="sv-topmenu-links">';
		a += '<a href="" id="sv-open-window" target="_blank"><span>Open Image in New Window</span></a>';
		a += '<a href="" id="sv-go-fullscreen"><span>Go Fullcreen</span></a>';
		a += '</div><div id="sv-topmenu-left"></div></div>';
		a += '</div>';
		return a
	};
	function generateSVFlashHtml() {
		var a;
		a = '<div id="sv-mobile-flash">';
		a += '<div id="sv-mobile-flash-swf"></div>';
		a += '</div>';
		return a
	};
	function checkForResize() {
		var a = window.innerHeight ? window.innerHeight: $(window).height();
		var b = window.innerWidth ? window.innerWidth: $(window).width();
		if (a !== p || b !== winWidth) {
			resizeViewer()
		}
		if (t === 'fullscreen') {
			window.scrollTo(0, 1)
		}
	}
	function resizeViewer() {
		var a, newH;
		p = window.innerHeight ? window.innerHeight: $(window).height();
		winWidth = window.innerWidth ? window.innerWidth: $(window).width();
		if (t === 'fullscreen') {
			$('#sv-mobile, .sv-photo').width($('#sv-mobile').parent().width() || winWidth);
			$('#sv-mobile, .sv-photo, #sv-photos, #sv-prev-photo, #sv-next-photo').height(p);
			if (o) {
				$('#sv-photos').css({
					'width': o.images.length * ($('#sv-mobile').parent().width() || winWidth) + 'px',
					'left': -((A - 1) * ($('#sv-mobile').parent().width() || winWidth)) + 'px'
				})
			}
		} else {
			if (svWidth.indexOf('%') > -1) {
				a = Math.floor((svWidth.replace('%', '') / 100) * s.width())
			} else {
				a = parseInt(svWidth)
			}
			if (svHeight.indexOf('%') > -1) {
				newH = Math.floor((svHeight.replace('%', '') / 100) * (containerHeight || p))
			} else {
				newH = parseInt(svHeight)
			}
			$('#sv-mobile, .sv-photo').width(a);
			$('#sv-mobile, #sv-photos, .sv-photo, #sv-prev-photo, #sv-next-photo').height(newH);
			if (o) {
				$('#sv-photos').css({
					'width': o.images.length * newH + 'px',
					'left': -((A - 1) * a) + 'px'
				})
			}
		}
		resizeImages()
	};
	function resizeImages() {
		$('.sv-photo').each(function () {
			if (!$(this).hasClass('loading')) {
				resizeImage(parseInt($(this).attr('id').replace('sv-photo-', '')) - 1)
			}
		})
	};
	function resizeImage(a) {
		if (!o.images[a].preloaded || !o.images[a].preloadedImage.height) {
			window.setTimeout(function () {
				resizeImage(a)
			},
			250);
			return
		}
		var b, origH, targetW, targetH, ration, xRatio, yRatio;
		var c, newSvHeight;
		b = o.images[a].preloadedImage.width;
		origH = o.images[a].preloadedImage.height;
		c = $('#sv-mobile').width();
		newSvHeight = $('#sv-mobile').height();
		if (t === 'fullscreen') {
			xRatio = winWidth / b;
			yRatio = p / origH;
			ratio = Math.min(xRatio, yRatio);
			var d = Math.floor(ratio * origH);
			if (xRatio > yRatio) {
				$('#sv-photo-' + (a + 1) + ' img').css({
					'height': p + 'px',
					'width': 'auto',
					'marginTop': '0'
				})
			} else {
				$('#sv-photo-' + (a + 1) + ' img').css({
					'width': winWidth + 'px',
					'height': 'auto'
				});
				$('#sv-photo-' + (a + 1) + ' img').css({
					'marginTop': parseInt((p - d) / 2) + 'px'
				})
			}
		} else {
			xRatio = c / b;
			yRatio = newSvHeight / origH;
			ratio = Math.min(xRatio, yRatio);
			if (xRatio > yRatio) {
				$('#sv-photo-' + (a + 1) + ' img').css({
					'height': newSvHeight + 'px',
					'width': 'auto',
					'marginTop': '0'
				})
			} else {
				$('#sv-photo-' + (a + 1) + ' img').css({
					'width': c + 'px',
					'height': 'auto'
				});
				$('#sv-photo-' + (a + 1) + ' img').css({
					'marginTop': parseInt((newSvHeight - $('#sv-photo-' + (a + 1) + ' img').height()) / 2) + 'px'
				})
			}
		}
	};
	function resizeFlashViewer() {
		var a, newH;
		p = window.innerHeight ? window.innerHeight: $(window).height();
		winWidth = window.innerWidth ? window.innerWidth: $(window).width();
		if (t === 'fullscreen') {
			s.css('position', 'static');
			$('#sv-mobile-flash').width($('#sv-mobile-flash').parent().width() || winWidth);
			$('#sv-mobile-flash').height(p)
		} else {
			$('#sv-mobile-flash').height(parseInt(containerHeight || p))
		}
	};
	function preloadImages(b, c) {
		var i, end;
		end = (b - 1 + c) > o.images.length ? o.images.length: (b - 1 + c);
		for (i = b - 1; i < end; i += 1) {
			if (!o.images[i].preloaded) {
				o.images[i].preloadedImage = new Image();
				o.images[i].preloadedImage.onload = function (a) {
					return function () {
						o.images[a].preloaded = true;
						$('#sv-photo-' + (a + 1) + ' img').attr('src', o.images[a].imageURL);
						$('#sv-photo-' + (a + 1)).removeClass('loading');
						resizeImage(a)
					}
				} (i);
				o.images[i].preloadedImage.src = o.images[i].imageURL
			}
		}
	};
	function toggleFullscreenMode(a) {
		if (t === 'fullscreen') {
			t = 'embed';
			$(document.body).css('overflow', 'auto');
			window.scrollTo(0, s.offset().top)
		} else {
			t = 'fullscreen';
			$(document.body).css('overflow', 'hidden');
			window.scrollTo(0, 0)
		}
		resizeViewer();
		a.preventDefault();
		a.stopPropagation()
	};
	function errorMessage(a) {
		var b, newH;
		if (svWidth.indexOf('%') > -1) {
			b = Math.floor((svWidth.replace('%', '') / 100) * s.width())
		} else {
			b = parseInt(svWidth)
		}
		if (svHeight.indexOf('%') > -1) {
			newH = Math.floor((svHeight.replace('%', '') / 100) * (s.height() || p))
		} else {
			newH = parseInt(svHeight)
		}
		resizeViewer();
		$('#sv-mobile').html('<div id="sv-error" style=""><div id="sv-error-text">' + a + '</div><div id="sv-error-bg"></div></div>');
		$('#sv-error').css({
			'width': $('#sv-error-text').outerWidth() + 'px',
			'height': $('#sv-error-text').outerHeight() + 'px',
			'top': (newH / 2) - ($('#sv-error-text').outerHeight() / 2) + 'px',
			'left': (b / 2) - ($('#sv-error-text').outerWidth() / 2) + 'px'
		});
		$('#sv-error-bg').css({
			'height': $('#sv-error-text').outerHeight() + 'px'
		})
	};
	function changePage() {
		if (o.mobileTransition === 'fade') {
			$('#sv-photos').fadeOut(250, function () {
				$('#sv-photos').css({
					left: '-' + ((A - 1) * $('#sv-mobile').width()) + 'px'
				});
				$('#sv-photos').fadeIn(250);
				preloadImages(A, 4)
			})
		} else if (o.mobileTransition === 'none') {
			$('#sv-photos').css({
				left: '-' + ((A - 1) * $('.sv-photo').width()) + 'px'
			});
			preloadImages(A, 4)
		} else {
			$('#sv-photos').animate({
				left: -((A - 1) * $('.sv-photo').width()) + 'px'
			},
			{
				duration: 500,
				complete: function () {
					preloadImages(A, 4)
				}
			})
		}
		$('#sv-open-window').attr('href', o.images[A - 1].imageFullURL).attr('target', o.images[A - 1].linkTarget)
	};
	n = {
		load: function (d, e, f, g, h, j, k, l) {
			var m;
			p = window.innerHeight ? window.innerHeight: $(window).height();
			winWidth = window.innerWidth ? window.innerWidth: $(window).width();
			svContainerId = d;
			s = $('#' + d);
			s.html('');
			q = s.width();
			containerHeight = s.height();
			svWidth = e;
			svHeight = f;
			if (e === '100%' && f === '100%' && s.parent().width() === $('body').width()) {
				t = 'fullscreen';
				$('body, html').css({
					'overflow': 'hidden',
					'height': '100%',
					'margin': '0',
					'padding': '0'
				});
				$('head').append('<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="black">')
			} else {
				t = 'embed';
				if (!containerHeight && f.indexOf('%') === -1) {
					s.css({
						'height': f + 'px'
					})
				}
			}
			backgroundColor = g.replace('#', '');
			x = j || {};
			params = k || {};
			attributes = l || {};
			if (typeof swfobject !== 'undefined' && swfobject.hasFlashPlayerVersion(w) && (typeof h === 'undefined' || (typeof h !== 'undefined' && h))) {
				m = parseInt(containerHeight || p);
				s.html(generateSVFlashHtml());
				$('#sv-mobile-flash').height(m);
				params.allowfullscreen = true;
				params.allowscriptaccess = 'always';
				params.bgcolor = params.bgcolor || g;
				swfobject.embedSWF(svCoreURL + 'swf/simpleviewer.swf', 'sv-mobile-flash-swf', e, f, w, false, x, params, attributes);
				$(window).bind('resize', resizeFlashViewer);
				window.setTimeout(resizeFlashViewer, 100);
				return
			}
			s.css({
				'position': 'relative'
			});
			s.html(generateSVHtml());
			if (t === 'embed') {
				$('#' + d + ' .simpleviewer').css({
					'position': 'relative'
				})
			}
			$('#sv-mobile').css({
				'background': '#' + backgroundColor
			});
			$('#' + v).css({
				'display': 'block',
				'width': '105px',
				'height': '15px',
				'overflow': 'hidden',
				'position': 'absolute',
				'bottom': '10px',
				'right': '10px',
				'z-index': '10',
				'text-decoration': 'none',
				'font-size': '11px',
				'background': 'url(http://www.pusri.co.id/images/sv.png) no-repeat 0 0'
			});
			$('#' + v).click(function (a) {
				window.open('http://www.pusri.co.id', 'sv');
				a.preventDefault();
				a.stopPropagation()
			});
			$.ajax({
				type: 'GET',
				url: (svCoreURL !== '' && svCoreURL !== 'svcore/' ? window.location.href.substr(0, window.location.href.lastIndexOf('/') + 1) : '') + (j && j.galleryURL ? j.galleryURL: 'gallery.xml'),
				dataType: ($.browser.msie) ? 'text': 'xml',
				success: function (b) {
					var c;
					if (typeof b === 'string') {
						c = new ActiveXObject("Microsoft.XMLDOM");
						c.async = false;
						c.loadXML(b)
					} else {
						c = b
					}
					o = parseXML(c);
					if (o.useFlickr) {
						if (o.flickrUserName) {
							n.flickrApi.getUserId(function () {
								n.flickrApi.getPhotos(initCallback)
							})
						} else {
							n.flickrApi.getPhotos(initCallback)
						}
					} else {
						initCallback()
					}
					function initCallback() {
						var i, photoHtml;
						if (!o.images || o.images.length === 0) {
							errorMessage('No Images Specified in Gallery XML.');
							return
						}
						if (t === 'embed' && o.showFullscreenButton) {
							$('#sv-go-fullscreen').attr('href', svCoreURL + 'full.html?bg=' + g + '&galleryURL=' + encodeURIComponent(svCoreURL !== '' && svCoreURL !== 'svcore/' ? window.location.href.substr(0, window.location.href.lastIndexOf('/') + 1) : '../') + (j && j.galleryURL ? j.galleryURL: 'gallery.xml'));
							$('#sv-topmenu-links').width($('#sv-topmenu-links').width() + 37);
							$('#sv-topmenu, #sv-go-fullscreen').show()
						}
						if (o.showOpenButton) {
							$('#sv-topmenu-links').width($('#sv-topmenu-links').width() + 37);
							$('#sv-topmenu, #sv-open-window').show()
						}
						if (typeof svMobile !== 'undefined' && svMobile) {
							$('#sv-go-fullscreen').click(function (a) {
								history.back();
								a.preventDefault();
								a.stopPropagation()
							});
							$('#sv-topmenu-links').width($('#sv-topmenu-links').width() + 37);
							$('#sv-topmenu, #sv-go-fullscreen').show()
						}
						for (i = 0; i < o.images.length; i += 1) {
							photoHtml = '<div class="sv-photo loading" id="sv-photo-' + (i + 1) + '">';
							photoHtml += '<img src="' + svCoreURL + 'img/empty-pixel.png" alt="">';
							photoHtml += '<div class="sv-caption clearfix" style="font-size: ' + y + 'px;">';
							photoHtml += '<div class="sv-paging">' + (i + 1) + '/' + o.images.length + '</div>';
							photoHtml += o.images[i].caption ? '<div class="sv-title">' + o.images[i].caption + '</div>': '';
							photoHtml += '<div class="sv-description" style="font-size: 11px;">' + o.images[i].description + '</div>';
							photoHtml += '</div>';
							photoHtml += '</div>';
							$('#sv-photos').append(photoHtml)
						}
						if (!o.mobileShowCaption) {
							$('.sv-photo .sv-caption').hide()
						}
						if (!o.mobileShowNav) {
							$('#sv-prev-photo span, #sv-next-photo span').hide()
						} else {
							$('#sv-prev-photo span, #sv-next-photo span').show()
						}
						$('#sv-open-window').attr('href', o.images[A - 1].imageFullURL).attr('target', o.images[A - 1].linkTarget);
						preloadImages(1, 3);
						$('#sv-prev-photo').click(function (a) {
							if (A > 1) {
								n.prevImage()
							}
							a.preventDefault()
						});
						$('#sv-next-photo').click(function (a) {
							if (o.images.length > A) {
								n.nextImage()
							}
							a.preventDefault()
						});
						if (o.images.length > 1) {
							$('#sv-next-photo').show()
						}
						$(window).bind('resize', resizeViewer);
						window.setTimeout(resizeViewer, 100);
						window.setInterval(checkForResize, 500)
					}
				},
				error: function (a, b, c) {
					if (navigator.userAgent.indexOf('Chrome') > -1 && (window.location.href.indexOf('http://') === -1 || window.location.href.indexOf('https://') === -1)) {
						errorMessage('SimpleViewer does not display locally in Google Chrome.')
					} else {
						errorMessage('Gallery XML Not Found.')
					}
				}
			})
		},
		flickrApi: (function () {
			var f;
			var g = 1;
			var h = 50;
			var j = 'http://api.flickr.com/services/rest/?method=';
			var k = '&api_key=b40dc56c795c0103c6170731e6271e04';
			var l = {
				FLICKR_SEARCH: 'flickr.photos.search',
				FLICKR_INTERESTINGNESS: 'flickr.interestingness.getList',
				FLICKR_SET: 'flickr.photosets.getPhotos',
				FLICKR_GROUP: 'flickr.groups.pools.getPhotos',
				FLICKR_FIND_USER: 'flickr.people.findByUsername',
				FLICKR_PHOTO_INFO: 'flickr.photos.getInfo',
				FLICKR_PEOPLE_FIND: 'flickr.people.findByUsername'
			};
			function getFlickrBaseUrl(a) {
				return j + l[a] + k
			};
			function getFlickrSearchUrl() {
				return getFlickrBaseUrl('FLICKR_SEARCH') + '&tags=' + o.flickrTags + (o.flickrUserId ? '&user_id=' + o.flickrUserId: '') + '&page=' + g + '&per_page=' + h + '&extras=url_sq, url_m, url_l,url_o,original_format&format=json&jsoncallback=?'
			};
			function getFlickrInterestingnessUrl() {
				return getFlickrBaseUrl('FLICKR_INTERESTINGNESS') + '&page=' + g + '&per_page=' + h + '&extras=url_sq, url_m, url_l,url_o,original_format&format=json&jsoncallback=?'
			};
			function getFlickrPeopleFindUrl() {
				return getFlickrBaseUrl('FLICKR_PEOPLE_FIND') + '&username=' + o.flickrUserName + '&extras=url_sq, url_m, url_l,url_o,original_format&format=json&jsoncallback=?'
			};
			function getFlickrUrl() {
				if (o.flickrTags || o.flickrUserName) {
					return getFlickrSearchUrl()
				} else {
					return getFlickrInterestingnessUrl()
				}
			};
			function getPhotoPageUrl(a, b) {
				return 'http://www.flickr.com/photos/' + a + '/' + b
			};
			function getThumbUrl(a, b, c, d) {
				return 'http://farm' + a + '.static.flickr.com/' + b + '/' + d + '_' + c + '_s.jpg'
			};
			function getMediumUrl(a, b, c, d) {
				return 'http://farm' + a + '.static.flickr.com/' + b + '/' + d + '_' + c + '.jpg'
			};
			function getLargeUrl(a, b, c, d) {
				return 'http://farm' + a + '.static.flickr.com/' + b + '/' + d + '_' + c + '_b.jpg'
			};
			f = {
				getUserId: function (d) {
					var e = getFlickrPeopleFindUrl();
					$.ajax({
						url: e,
						dataType: 'json',
						success: function (a) {
							if (a.stat === 'ok') {
								o.flickrUserId = a.user.id;
								if (d) {
									d()
								}
							} else {
								errorMessage('Cannot load from Flickr.')
							}
						},
						error: function (a, b, c) {
							errorMessage('Cannot load from Flickr.')
						}
					})
				},
				getPhotos: function (d) {
					var e = getFlickrUrl();
					$.ajax({
						url: e,
						dataType: 'json',
						success: function (a) {
							if (a.stat === 'ok') {
								o.images = f.parseFlickrResponse(a);
								if (d) {
									d()
								}
							} else {
								errorMessage('Cannot load from Flickr.')
							}
						},
						error: function (a, b, c) {
							errorMessage('Cannot load from Flickr.')
						}
					})
				},
				nextPage: function () {
					g += 1
				},
				prevPage: function () {
					if (g > 1) {
						g -= 1
					}
				},
				parseFlickrResponse: function (a) {
					var b, i, items, item;
					b = a.photos.photo;
					items = [];
					for (i = 0; i < b.length; i += 1) {
						item = {
							thumbURL: getThumbUrl(b[i].farm, b[i].server, b[i].secret, b[i].id),
							imageFullURL: getPhotoPageUrl(b[i].owner, b[i].id),
							linkTarget: '_blank',
							caption: b[i].title || '',
							description: '',
							preloadedImage: null,
							preloaded: false
						};
						if (b[i].url_l) {
							item.imageURL = b[i].url_l
						} else {
							item.imageURL = b[i].url_m
						}
						items.push(item)
					}
					return items
				}
			};
			return f
		})(),
		nextImage: function () {
			A += 1;
			changePage();
			if (A >= o.images.length) {
				$('#sv-next-photo').hide()
			}
			$('#sv-prev-photo').show()
		},
		prevImage: function () {
			A -= 1;
			changePage();
			if (A === 1) {
				$('#sv-prev-photo').hide()
			}
			$('#sv-next-photo').show()
		}
	};
	return n
})();
