/*!
 * Horizontal Ruler helper JS
 * Copyright (c) 2014 Intense Visions, Inc.
 */
/* global jQuery */

jQuery(function($) {
	'use strict';

	function setupHrTitles() {
		var verticalTitles = $('.intense.hr.vertical');		

		$('.hr-title', verticalTitles).each(function() {
			var $el = $(this);
			$el.css('position', 'relative');
			$el.show();

			var $hrContainer = $el.parent();
			var elementTop = ($hrContainer.outerHeight() / 2) - $el.outerHeight() / 2;
			var elementWidth = $el.outerWidth();

			$el.css('margin-left', (-elementWidth / 2) + 'px');
			$el.css('position', 'absolute');
			$el.css('width', elementWidth);

			if ($el.parent().hasClass('hr-center')) {
				$el.css('top', elementTop + 'px');
			} else if ($el.parent().hasClass('hr-top')) {
				$el.css('top', '0');
			} else if ($el.parent().hasClass('hr-bottom')) {
				$el.css('top', $hrContainer.outerHeight() - $el.outerHeight() + 'px');
			} else {
				$el.css('top', elementTop + 'px');
			}

			if (!$hrContainer.parent().hasClass('vertical-hr-wrapper')) {
				$hrContainer.wrap('<div class="vertical-hr-wrapper"></div>');
				$hrContainer.parent().css('width', elementWidth + 30);
				$hrContainer.parent().css('display', 'inline-block');
				$hrContainer.parent().css('text-align', 'center');
			}
		});
	}

	$(document).ready(function() {
		setupHrTitles();

		$(window).resize(function() {
			setupHrTitles();
		});
	});
});