// Ye old zebra
$(function(){
	$('table.zebra').each(function(){
		$('tr:odd', $(this)).addClass('odd');
	});
});

// Turns bland old submit buttons into buttons of awesomeness.
/*$(function(){
	$('input[type=submit].button').each(function(){
		$(this)
			.wrap('<div class="button-wrapper" />')
			.after('<div class="cu-bold-italic">'+$(this).val()+'</div>');

		$(this).val(null);

		Cufon.refresh('.cu-bold-italic');
	});
});*/

function cufonify() {
	$('input[type=submit].button, input[type=button].button, .sf_admin_actions input[type=submit]').each(function(){
		$(this)
			.wrap('<div class="button-wrapper" />')
			.after('<div class="cu-bold-italic">'+$(this).val()+'</div>');

		$(this).val(null);
	});

	$('input[type=submit].button-simple, input[type=button].button-simple').each(function(){
		$(this)
			.wrap('<div class="button-simple-wrapper" />')
			.closest('.button-simple-wrapper')
			.css('width', $(this).outerWidth())
			.css('height', $(this).outerHeight())
			.end()
			.after('<div class="cu-bold-italic">'+$(this).val()+'</div>');

		//$(this).val(null);
	});

	Cufon.now();
}

function default_inputs() {
	$('input[type=text].default-value-when-empty').each(function(){
		$(this).bind('focus', function(){
			if ($(this).val() == $(this).attr('data-default'))
				$(this).val('');
		});

		$(this).bind('blur', function(){
			if ($(this).val().length == 0)
				$(this).val($(this).attr('data-default'));
		});

		$(this).trigger('blur');
	});

	$('input[type=password].default-value-when-empty').each(function(){
		var o = $(this).position();

		var input = $(document.createElement('input'));

		input
			.attr('type', 'text')
			.attr('tabindex', '-1')
			.val($(this).attr('data-default'))
			.css({
				position: 'absolute',
				//top: o.top,
				left: o.left,
				width: $(this).width(),
				height: +$(this).height(),
				marginTop: $(this).css('marginTop'),
				zIndex: 0
			});

		input.insertAfter(this);

		// Fixes IE8 z-index issue.
		var parent = $(this);
		input.bind('focus', function(){
			parent.focus();
			return false;
		});

		var alt = $(this).next();

		$(this).bind('focus', function(){
			$(this).attr('style', 'background-color: #ffffff;');
		});

		$(this).bind('blur', function(){
			if ($(this).val().length == 0)
				// Most browsers will not correctly parse !important properties.
				// Directly modify the style to achieve the desired result.
				// $(this).css('backgroundColor', 'transparent !important');
				$(this).attr('style', 'background-color: transparent !important;');
		});

		$(this).trigger('blur');
	});
}

$(function(){
	$('#locator-accordian').each(function(){
		var context = $(this);
		var contextBottom = context.offset().top + context.height();
		var container = $(this).parent();

		$('#locator-accordian-results .content', context).bind('resizeAccordianResults', function(e, slide, target){
			var bottom = $(this).outerHeight(true) + $(this).offset().top;

			var res = $('#locator-accordian-results .title');
			$(this).height(contextBottom - (res.outerHeight(true) + res.offset().top));
			return;
/*
			//console.log('zzz', contextBottom, res.outerHeight() + res.offset().top, contextBottom - (res.outerHeight() + res.offset().top));
			var height;
			if (slide == 'open' && bottom > contextBottom) {
				var height = $(this).height() - (bottom - contextBottom);
				//console.log((bottom - contextBottom), bottom, contextBottom);
			}
			else if (slide == 'close' && !$(this).is(target)) {
				var height = contextBottom - $(this).offset().top;
			}

			if (height) {
			//console.log(height, $(this));
				$(this).height(height);
			}
*/
		});

		$('.slider .title', context).bind('click', function(){
			var parent = $(this).closest('.slider');
			var content = $('.content', parent).eq(0);
			var isOpen = parent.hasClass('open');

			if (isOpen) {
				content.animate({
					height: 'hide',
					marginBottom: 'hide',
					marginTop: 'hide',
					paddingBottom: 'hide',
					paddingTop: 'hide'
				}, {
					duration: 'fast',
					step: function(now, fx){
						if (fx.prop == 'height') {
							
							$('#locator-accordian-results .content').trigger('resizeAccordianResults', ['close', $(this)]);
						}
					},
					complete: function(){
						parent.removeClass('open');
					}
				});
			}
			else
			{
				parent.addClass('open')
				content.animate({
					height: 'show',
					marginBottom: 'show',
					marginTop: 'show',
					paddingBottom: 'show',
					paddingTop: 'show'
				}, {
					duration: 'fast',
					step: function(now, fx){
						if (fx.prop == 'height') {
							$('#locator-accordian-results .content').trigger('resizeAccordianResults', ['open', $(this)]);
						}
					},
					complete: function(){}
				});
			}
		});
	});
});

