jQuery.noConflict();
(function($){

$(document).ready(function(){

    $('#newsletter').adjaxify();

	if ($('.slideshow1').length)
	{
		$('.slideshow1').each(function(){
			slideshow(this.id);
		});
	}
	if ($('#slideshow2').length)
	{
		slideshow('slideshow2');
	}

	$('.tabControl').
		find('.tabs li a').click(function(){
			$(this).
				parents('.tabs').find('li').removeClass('active').end().
				parents('.tabControl').find('.tab').hide().end();
			var id = this.id.split('-')[1];
			$('#' + id).show();
			$(this.parentNode).addClass('active');
			return false;
		});

	$('.products1 > ul > li').hover(function(){
		var i = $('.info', this);
		i.animate({ top: (220 - i.outerHeight()) + 'px' }, 350);
	}, function(){
		$('.info', this).animate({ top: '186px' }, 300);
	});

	var timerCart = null;
	$('#menu li a').hover(function(){
		var i = this.parentNode.id.substring(1);
		$('#menu ul').addClass('temp' + i);
		if (i == '3')
			showCart();
	}, function(){
		var i = this.parentNode.id.substring(1);
		$('#menu ul').removeClass('temp' + i);
		if (i == '3')
			timerCart = setTimeout(hideCart, 400);
	});

	$('#cartPopup').hover(showCart, function(){
		timerCart = setTimeout(hideCart, 400);
	});
	function showCart(){
		if (timerCart)
		{
			clearTimeout(timerCart);
			timerCart = null;
		}
		$('#cartPopup').show();
	}
	function hideCart(){
		$('#cartPopup').hide();
		timerCart = null;
	}

	$('#checkout .col1, #checkout .col2').equalHeights({ '.col2': 6, '.col2 col2a': 5 });

	if ($.browser.msie) {
		try {document.execCommand("BackgroundImageCache", false, true);} catch(err){};
		if (typeof(DD_belatedPNG) != 'undefined')
		{
			DD_belatedPNG.fix('');
		}
	}

	$('#checkout .slider label').each(function(){
		var labelColor = '#999';
		var restingPosition = '5px';
		// style the label with JS for progressive enhancement
		$(this).css({
			'color' : labelColor,
		 	'position' : 'absolute',
	 		'top' : '6px',
			'left' : restingPosition,
			'display' : 'inline',
    		'z-index' : '99'
		});

		var inputval = $(this).next().val();

		// grab the label width, then add 5 pixels to it
		var labelwidth = $(this).width();
		var labelmove = labelwidth + 5 +'px';

		// onload, check if a field is filled out, if so, move the label out of the way
		if(inputval !== ''){
			//$(this).stop().animate({ 'left':'-'+labelmove }, 1);
			$(this).stop().fadeTo('fast', 0);
		}

		// if the input is empty on focus move the label to the left
		// if it's empty on blur, move it back
		$('input, textarea').focus(function(){
			var label = $(this).prev('.slider label');
			//var width = $(label).width();
			//var adjust = width + 5 + 'px';
			var value = $(this).val();

			if(value == ''){
				//label.stop().animate({ 'left':'-'+adjust }, 'fast');
				//label.css({'opacity':'0'});
				label.stop().fadeTo('fast', 0);

			} else {
				//label.css({ 'left':'-'+adjust });
				label.css({'opacity': '0'});
			}
		}).blur(function(){
			var label = $(this).prev('label');
			var value = $(this).val();

			if(value == ''){
				//label.stop().animate({ 'left':restingPosition }, 'fast');
				//label.css({'opacity' : '100'});
				label.stop().fadeTo(2000, 100);
			}

		});
	}); // End checkout label fields "each" statement

});

function slideshow(id)
{
	if (!$('#'+id).length)
		return;

	var opts = {
		btnPrev: '#' + id + ' .prev a',
		btnNext: '#' + id + ' .next a',
		speed: 400,
		visible: 1
	};

	if ($('#' + id + ' .tabs').length)
	{
		var i = 0, btns = [];
		$('#' + id + ' .tabs li').each(function(){ this.id = id + 'tab-' + i; btns[btns.length] = '#' + id + 'tab-' + i; i++ });
		i = 0;
		$('#' + id + ' .slider li').each(function(){ this.className = id + 'slide-' + (i++); });

		opts['btnGo'] = btns;
		opts['afterEnd'] = slideshowUpdate;

		slideshowUpdate($('#' + id + ' .slider li:eq(0)'));
	}

	$('#' + id + ' .slider').jCarouselLite(opts);
}

function slideshowUpdate(li){
	var id = li.parents('.slider')[0].parentNode.id;
	var i = li[0].className.split('-')[1];
	$('#' + id + ' .tabs li').removeClass('active');
	$('#' + id + 'tab-' + i).addClass('active');
}



$.fn.equalHeights = function(add) {
	var tallest = 0;
	$(this).each(function(){
		if ($(this).height() > tallest) tallest = $(this).outerHeight();
	});
	$(this).each(function(){
		var t = $(this);
		var p = parseInt(t.css('paddingTop')) + parseInt(t.css('paddingBottom'));
		var h = tallest - p;
		for (var i in add)
			if (this.id + '.' + this.className == i)
				h += add[i];
		if ($.browser.msie && $.browser.version == 6.0)
			t.css({'height': h});
		t.css({'min-height': h});
	});
	return this;
};


})(jQuery);

