$(function()
{
	try
	{
		var visible = $('#profileinfo').length ? 3 : 5;
		var count = $('.jcarousel-widget>ul>li').length;

		$('.jcarousel-widget').jCarouselLite(
		{
			btnNext: '#slideNext',
			btnPrev: '#slidePrev',
			visible: visible
		});

		if (count < visible) $('#slideNext,#slidePrev').remove();
	}
	catch (o) {}

	try
	{
		if ($.browser.mozilla && navigator.userAgent.toLowerCase().indexOf('mac') > -1) $('input:text').each(function()
		{
			$(this).css(
			{
				'padding-top': $(this).height() / 5,
				'height': $(this).height() * .8
			});
		});
	}
	catch(o){}


	try
	{
		$('.tab-bar').each(function()
		{
			if ($('a', this).length > 1)
			{
				$('a', this).each(function(i)
				{
					$(this).attr('href', 'javascript:void(null)').click(function()
					{
						if ($(this).parent().is('.current')) return;

						$('.tab-pane:visible', this.tabBlock).hide();
						$($('.tab-pane', this.tabBlock)[this.paneIndex]).show();

						//location.hash = escape($(this).text().toLowerCase());

						$(this).parent().parent().find('.current').removeClass('current');
						$(this).parent().addClass('current');
					});

					this.paneIndex = i;
					this.tabBlock = $(this).parent().parent().parent().next();
				});
			}
		});

		//var selected = unescape(location.hash.substr(1)).toUpperCase();

		//if (selected.length) $('.tab-bar a:contains("' + selected + '")').click();
	}
	catch (o) {}

	try { $('#workhours li:last-child').css('border', 0); } catch (o) {}

	if ($.browser.mozilla)
	{
		$('button.fffix').each(function()
		{
			$(this).css('padding-bottom', Math.floor($(this).height() / 2) + 'px');
		});
	}

	$('#locator a.titlebar').click(function()
	{
		var locator = $(this).parent();

		if (!locator.is('.open'))
		{
			var size =
			{
				width: 300,
				height: locator.is('.advanced') ? 324 : 189
			};

			if ($('body').is('.salon-network'))
			{
				$('#contents').height(660 + size.height);

				$.extend(size, {left: (940 - size.width) / 2})
			}

			locator.animate(size, 'fast', function()
			{
				locator.find('.titlebar').andSelf().addClass('open');
			})

			.find('#locatorbody').hide().css({width: size.width - 2, height: size.height - 22}).fadeIn();
		}
		else
		{
			var animation = {width: locator.is('.advanced') ? 205 : 135, height: 20};

			if ($('body').is('.salon-network')) $.extend(animation,
			{
				left: (940 - animation.width) / 2
			});

			locator.animate(animation, 'fast', function()
			{
				locator.find('.titlebar').andSelf().removeClass('open');

				if ($('body').is('.salon-network')) $('#contents').height(660);
			})

			.find('#locatorbody').fadeOut();
		}
	});

	if ($('body').is('.salon-network')) $('#locator a.titlebar').click();

	$('#locator #of').focus(function()
	{
		if ($(this).val() == "zipcode") $(this).val('');
	})
	.blur(function()
	{
		if (!$(this).val().length) $(this).val('zipcode');
	});

	$('#locator a#mode-switch').click(function()
	{
		var self = $(this);
		var locator = self.parents('#locator');

		if (!locator.is('.advanced'))
		{
			if ($('body').is('.salon-network')) $('#contents').height(984);

			locator.animate({height: 324}, 'fast', function()
			{
				self.text('SEARCH');

				locator.addClass('advanced')

				.find(':hidden[name="is_advanced"]').val('1').end()
				.find('a.titlebar span').text('ADVANCED SALON LOCATOR');
			})

			.find('#locatorbody').animate({height: 302}, 'fast')
			.find('.advanced-fields').fadeIn();
		}
		else
		{
			locator.animate({height: 189}, 'fast', function()
			{
				self.text('ADVANCED SEARCH');

				locator.removeClass('advanced')

				.find(':hidden[name="is_advanced"]').val('1').end()
				.find('a.titlebar span').text('SALON LOCATOR');

				if ($('body').is('.salon-network'))
				{
					$('#contents').height(849);
				}
			})

			.find('#locatorbody').animate({height: 167}, 'fast')
			.find('.advanced-fields').fadeOut('fast');
		}

		this.blur();
	});

});
