/**
* @author    JoomlaShine.com http://www.joomlashine.com
* @copyright Copyright (C) 2008 - 2011 JoomlaShine.com. All rights reserved.
* @license   GNU/GPL v2 http://www.gnu.org/licenses/gpl-2.0.html
*/

	var JSNTemplate = {
		_templateParams:		{},

		initOnDomReady: function()
		{
			// Typography setup
			JSNUtils.createExtList("list-number-", "span", "jsn-listbullet", true);
			JSNUtils.createExtList("list-icon", "span", "jsn-listbullet", false);

			// Smooths effect for go top link
			JSNUtils.setSmoothScroll(_templateParams.enableJQuery);

			if (!_templateParams.enableMobile) {
				if (!_templateParams.mobileDevice) {
					// Fade in / Fade out effect when scrolling
					JSNUtils.setFadeScroll(_templateParams.enableJQuery);

					// Menu dropdown setup
					JSNUtils.setDropdownMenu("menu-mainmenu", (_templateParams.enableMMFX?1:0), { duration:250, delay:500, orientation: 'h' }, _templateParams.enableJQuery);
					JSNUtils.setDropdownMenu("menu-sidemenu", (_templateParams.enableSMFX?1:0), { duration:250, delay:500, orientation: 'v' }, _templateParams.enableJQuery);
					JSNUtils.setDropdownMenuFX("jsn-sitetools-menu", (_templateParams.enableMMFX?1:0), { duration:250, delay:500, orientation: 'h' }, _templateParams.enableJQuery);
				}


				// Menu layout setup
				JSNUtils.setSidemenuLayout("menu-sidemenu", _templateParams.enableRTL);
				JSNUtils.setSitetoolsLayout("jsn-sitetools-menu", _templateParams.enableRTL);

				// Typography setup
				JSNUtils.createGridLayout("DIV", "grid-layout", "grid-col", "grid-lastcol");
			} else {
				JSNUtils.setMobileMenu("menu-mainmenu");
			}
		},

		initOnLoad: function()
		{
			if (!_templateParams.enableMobile) {
				// Setup vertical positions of stickleft, stickright positions
				JSNUtils.setVerticalPosition("jsn-pos-stick-leftmiddle", 'middle');
				JSNUtils.setVerticalPosition("jsn-pos-stick-rightmiddle", 'middle');
				
				if (_templateParams.enableEqualHeight) JSNTemplate.setEqualHeight();
			}
		},

		initTemplate: function(templateParams)
		{
			// Store template parameters
			_templateParams = templateParams;
			
			// Init template on "domready" event
			if (_templateParams.enableJQuery) {
				$j(document).ready(function(){
					JSNTemplate.initOnDomReady();
				});
			} else if (typeof(MooTools) != 'undefined') {
				window.addEvent('domready', JSNTemplate.initOnDomReady);
			}

			// Init template on "load" event
			JSNUtils.addEvent(window, 'load', JSNTemplate.initOnLoad);
		},
		
		setAttribute: function(attributeName, attributeValue) {
			JSNUtils.setTemplateAttribute(_templateParams.templatePrefix, attributeName, attributeValue);
		},

		setEqualHeight: function(containerClass, columnClass) {
			var containerClass 	= "jsn-horizontallayout";
			var columnClass 	= "jsn-modulecontainer_inner";
			var horizontallayoutObjs = $$('.'+containerClass);
			var maxHeight = 0;
			Array.each(horizontallayoutObjs, function(item) {
				var columns = item.getElements('.'+columnClass);
				maxHeight = 0;
				Array.each(columns, function(col) {
					var coordinates = col.getCoordinates();
					if (coordinates.height > maxHeight) maxHeight = coordinates.height;
				});
				Array.each(columns, function(col) {
					col.setStyle('height',maxHeight);
				});
			});
		}
	};
