<%
/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */
%>

<script type="text/javascript">
	// <![CDATA[
		var Liferay = {
			Browser: {
				acceptsGzip: function() {
					return <%= BrowserSnifferUtil.acceptsGzip(request) %>;
				},
				getMajorVersion: function() {
					return <%= BrowserSnifferUtil.getMajorVersion(request) %>;
				},
				getRevision: function() {
					return "<%= BrowserSnifferUtil.getRevision(request) %>";
				},
				getVersion: function() {
					return "<%= BrowserSnifferUtil.getVersion(request) %>";
				},
				isAir: function() {
					return <%= BrowserSnifferUtil.isAir(request) %>;
				},
				isChrome: function() {
					return <%= BrowserSnifferUtil.isChrome(request) %>;
				},
				isFirefox: function() {
					return <%= BrowserSnifferUtil.isFirefox(request) %>;
				},
				isGecko: function() {
					return <%= BrowserSnifferUtil.isGecko(request) %>;
				},
				isIe: function() {
					return <%= BrowserSnifferUtil.isIe(request) %>;
				},
				isIphone: function() {
					return <%= BrowserSnifferUtil.isIphone(request) %>;
				},
				isLinux: function() {
					return <%= BrowserSnifferUtil.isLinux(request) %>;
				},
				isMac: function() {
					return <%= BrowserSnifferUtil.isMac(request) %>;
				},
				isMobile: function() {
					return <%= BrowserSnifferUtil.isMobile(request) %>;
				},
				isMozilla: function() {
					return <%= BrowserSnifferUtil.isMozilla(request) %>;
				},
				isOpera: function() {
					return <%= BrowserSnifferUtil.isOpera(request) %>;
				},
				isRtf: function() {
					return <%= BrowserSnifferUtil.isRtf(request) %>;
				},
				isSafari: function() {
					return <%= BrowserSnifferUtil.isSafari(request) %>;
				},
				isSun: function() {
					return <%= BrowserSnifferUtil.isSun(request) %>;
				},
				isWap: function() {
					return <%= BrowserSnifferUtil.isWap(request) %>;
				},
				isWapXhtml: function() {
					return <%= BrowserSnifferUtil.isWapXhtml(request) %>;
				},
				isWebKit: function() {
					return <%= BrowserSnifferUtil.isWebKit(request) %>;
				},
				isWindows: function() {
					return <%= BrowserSnifferUtil.isWindows(request) %>;
				},
				isWml: function() {
					return <%= BrowserSnifferUtil.isWml(request) %>;
				}
			},

			ThemeDisplay: {
				getCompanyId: function() {
					return "<%= themeDisplay.getCompanyId() %>";
				},
				getCompanyGroupId: function() {
					return "<%= themeDisplay.getCompanyGroupId() %>";
				},
				getUserId: function() {
					return "<%= themeDisplay.getUserId() %>";
				},

				<c:if test="<%= themeDisplay.isSignedIn() %>">
					getUserName: function() {
						return "<%= UnicodeFormatter.toString(user.getFullName()) %>";
					},
				</c:if>

				getDoAsUserIdEncoded: function() {
					return "<%= UnicodeFormatter.toString(themeDisplay.getDoAsUserId()) %>";
				},
				getPlid: function() {
					return "<%= themeDisplay.getPlid() %>";
				},

				<c:if test="<%= layout != null %>">
					getLayoutId: function() {
						return "<%= layout.getLayoutId() %>";
					},
					getLayoutURL: function() {
						return "<%= PortalUtil.getLayoutURL(layout, themeDisplay) %>";
					},
					isPrivateLayout: function() {
						return "<%= layout.isPrivateLayout() %>";
					},
					getParentLayoutId: function() {
						return "<%= layout.getParentLayoutId() %>";
					},
				</c:if>

				getScopeGroupId: function() {
					return "<%= themeDisplay.getScopeGroupId() %>";
				},
				getParentGroupId: function() {
					return "<%= themeDisplay.getParentGroupId() %>";
				},
				isImpersonated: function() {
					return <%= themeDisplay.isImpersonated() %>;
				},
				isSignedIn: function() {
					return <%= themeDisplay.isSignedIn() %>;
				},
				getDefaultLanguageId: function() {
					return "<%= LocaleUtil.toLanguageId(LocaleUtil.getDefault()) %>";
				},
				getLanguageId: function() {
					return "<%= LanguageUtil.getLanguageId(request) %>";
				},
				isFreeformLayout: function() {
					return <%= themeDisplay.isFreeformLayout() %>;
				},
				isStateExclusive: function() {
					return <%= themeDisplay.isStateExclusive() %>;
				},
				isStateMaximized: function() {
					return <%= themeDisplay.isStateMaximized() %>;
				},
				isStatePopUp: function() {
					return <%= themeDisplay.isStatePopUp() %>;
				},
				getPathContext: function() {
					return "<%= themeDisplay.getPathContext() %>";
				},
				getPathImage: function() {
					return "<%= themeDisplay.getPathImage() %>";
				},
				getPathJavaScript: function() {
					return "<%= themeDisplay.getPathJavaScript() %>";
				},
				getPathMain: function() {
					return "<%= themeDisplay.getPathMain() %>";
				},
				getPathThemeImages: function() {
					return "<%= themeDisplay.getPathThemeImages() %>";
				},
				getPathThemeRoot: function() {
					return "<%= themeDisplay.getPathThemeRoot() %>";
				},
				getURLHome: function() {
					return "<%= themeDisplay.getURLHome() %>";
				},
				getSessionId: function() {
					return "<%= session.getId() %>";
				},
				getPortletSetupShowBordersDefault: function() {
					return <%= GetterUtil.getString(theme.getSetting("portlet-setup-show-borders-default"), "true") %>;
				}
			},

			PropsValues: {
				NTLM_AUTH_ENABLED: <%= PropsValues.NTLM_AUTH_ENABLED %>
			}
		};

		var themeDisplay = Liferay.ThemeDisplay;

		<%
		long javaScriptLastModified = ServletContextUtil.getLastModified(application, "/html/js/", true);

		String alloyBaseURL = themeDisplay.getPathJavaScript() + "/aui/";
		String alloyComboURL = PortalUtil.getStaticResourceURL(request, themeDisplay.getPathContext() + "/combo/", javaScriptLastModified);
		%>

		Liferay.AUI = {
			getBasePath: function() {
				return '<%= alloyBaseURL %>';
			},
			getCombine: function() {
				return <%= themeDisplay.isThemeJsFastLoad() %>;
			},
			getComboPath: function() {
				return '<%= alloyComboURL %>&p=<%= themeDisplay.getPathJavaScript() %>&';
			},
			getFilter: function() {
				<c:choose>
					<c:when test="<%= themeDisplay.isThemeJsFastLoad() %>">
						return {
							replaceStr: function(match, fragment, string) {
								return fragment + 'm=' + (match.split('<%= themeDisplay.getPathJavaScript() %>')[1] || '');
							},
							searchExp: '(\\?|&)/([^&]+)'
						};
					</c:when>
					<c:otherwise>
						return 'raw';
					</c:otherwise>
				</c:choose>
			}
		};

		window.YUI_config = {
			comboBase: Liferay.AUI.getComboPath(),
			fetchCSS: false,
			filter: Liferay.AUI.getFilter(),
			root: Liferay.AUI.getBasePath()
		};

		<%
		String currentURL = PortalUtil.getCurrentURL(request);
		%>

		Liferay.currentURL = '<%= HtmlUtil.escapeJS(currentURL) %>';
		Liferay.currentURLEncoded = '<%= HttpUtil.encodeURL(currentURL) %>';
	// ]]>
</script>

<c:choose>
	<c:when test="<%= themeDisplay.isThemeJsFastLoad() %>">
		<c:choose>
			<c:when test="<%= themeDisplay.isThemeJsBarebone() %>">
				<script src="<%= HtmlUtil.escape(PortalUtil.getStaticResourceURL(request, themeDisplay.getPathJavaScript() + "/barebone.jsp", "minifierBundleId=" + HttpUtil.encodeURL("javascript.barebone.files"), javaScriptLastModified)) %>" type="text/javascript"></script>
			</c:when>
			<c:otherwise>
				<script src="<%= HtmlUtil.escape(PortalUtil.getStaticResourceURL(request, themeDisplay.getPathJavaScript() + "/everything.jsp", "minifierBundleId=" + HttpUtil.encodeURL("javascript.everything.files"), javaScriptLastModified)) %>" type="text/javascript"></script>
			</c:otherwise>
		</c:choose>
	</c:when>
	<c:otherwise>

		<%
		String[] javaScriptFiles = null;

		if (themeDisplay.isThemeJsBarebone()) {
			javaScriptFiles = JavaScriptBundleUtil.getFileNames(PropsKeys.JAVASCRIPT_BAREBONE_FILES);
		}
		else {
			javaScriptFiles = JavaScriptBundleUtil.getFileNames(PropsKeys.JAVASCRIPT_EVERYTHING_FILES);
		}

		for (String javaScriptFile : javaScriptFiles) {
		%>

			<script src="<%= themeDisplay.getPathJavaScript() %>/<%= javaScriptFile %>?t=<%= javaScriptLastModified %>" type="text/javascript"></script>

		<%
		}
		%>

	</c:otherwise>
</c:choose>

<c:if test="<%= PropsValues.JAVASCRIPT_LOG_ENABLED %>">
	<script src="<%= themeDisplay.getPathJavaScript() %>/firebug/firebug.js" type="text/javascript"></script>
</c:if>

<c:if test="<%= themeDisplay.isIncludeServiceJs() %>">
	<script src="<%= HtmlUtil.escape(PortalUtil.getStaticResourceURL(request, themeDisplay.getPathJavaScript() + "/liferay/service.js", javaScriptLastModified)) %>" type="text/javascript"></script>
</c:if>

<script type="text/javascript">
	// <![CDATA[
		<c:if test="<%= (layoutTypePortlet != null) %>">

			<%
			List<String> portletIds = layoutTypePortlet.getPortletIds();
			%>

			<c:if test="<%= !portletIds.isEmpty() && !layoutTypePortlet.hasStateMax() %>">
				Liferay.Portlet.list = ['<%= StringUtil.merge(portletIds.toArray(new String[portletIds.size()]), "','") %>'];
			</c:if>
		</c:if>
	// ]]>
</script>