var J = jQuery.noConflict();
var ie6 = (J.browser.msie && J.browser.version.substring(0,1) === '6')?true:false;

J(document).ready(function ($) {

	/* Cufon */
	Cufon.replace('#header .top-menu ul li .my-bag a.button-rose')

	/* Input hint text */
	$('INPUT.hint-text').focus(function () {
		if ($(this).attr('value') == $(this).attr('title')) $(this).attr('value', '');
	});

	$('INPUT.hint-text').blur(function () {
		if ($(this).attr('value') == '') $(this).attr('value', $(this).attr('title'));
	});

	// Initialize Backgound Stretcher 
	$(document).bgStretcher({
		images: ['http://www.hudsonjeans.com/layout/images/bg/body-bg.jpg'],
		imageWidth: 1250, imageHeight: 1280, slideShow: false
	});

	SetMyBagHover();
});

function SetMyBagHover() {
	if (!ie6) J('.top-menu UL LI .my-bag').css('opacity', 0);
	J('.top-menu UL LI').hover(function () {
		var bag = J('.my-bag', this);
		if (!J(bag).length) return;
		J(bag).stop(true);
		J(bag).css({ 'display': 'none', 'height': 'auto' });
		if (ie6) {
			J(bag).animate({
				height: 'toggle'
			}, 500);
		} else {
			J(bag).animate({
				opacity: 1,
				height: 'toggle'
			}, 500);
		}

		return false;
	}, function () {
		var bag = J('.my-bag', this);
		if (!J(bag).length) return;

		J(bag).stop(true);
		if (ie6) {
			J(bag).animate({
				height: 'toggle'
			}, 300, function () { J(bag).css('height', 'auto'); });
		} else {
			J(bag).animate({
				opacity: 0,
				height: 'toggle'
			}, 300, function () { J(bag).css('height', 'auto'); });
		}

		return false;
	});
}

function UnbindMyBag() {
	J('.top-menu UL LI').unbind('mouseenter mouseleave');
}

function ShowShoppingBag() {
	UnbindMyBag();
	var st;
	var bag = J('.my-bag');
	if (!J(bag).length) return;
	if (ie6) {
		J(bag).animate({
			height: 'toggle'
		}, 500, function () { st = setTimeout(HideShoppingBag, 3000); });
	} else {
		J(bag).animate({
			opacity: 1,
			height: 'toggle'
		}, 500, function () { st = setTimeout(HideShoppingBag, 3000); });
	}

	// temp binding
	setTimeout(function () {
		J('.top-menu UL LI').hover(function () {
			var bag = J('.my-bag');
			if (!J(bag).length) return;
			J(bag).stop(false);
			clearTimeout(st);
			return false;
		}, function () {
			var bag = J('.my-bag');
			if (!J(bag).length) return;
			J(bag).stop(true);
			st = setTimeout(HideShoppingBag, 300);
			return false;
		});
	}, 0);

	return false;
}

function HideShoppingBag() {
	UnbindMyBag();
	var bag = J('.my-bag');
	if (!J(bag).length) return;
	J(bag).stop(true);
	if (ie6) {
		J(bag).animate({
			height: 'toggle'
		}, 300, function () { J(bag).css('height', 'auto'); SetMyBagHover(); });
	} else {
		J(bag).animate({
			opacity: 0,
			height: 'toggle'
		}, 300, function () { J(bag).css('height', 'auto'); SetMyBagHover(); });
	}

	return false;
}

function MM_goToURL() { //v3.0
	var i, args = MM_goToURL.arguments; document.MM_returnValue = false;
	for (i = 0; i < (args.length - 1); i += 2) eval(args[i] + ".location='" + args[i + 1] + "'");
}

function DefaultButton(btnID, event) {
	btn = document.getElementById(btnID);
	if (document.all) {
		if (event.keyCode == 13) {
			event.returnValue = false;
			event.cancelBubble = true;
			btn.click();
		}
	}
	else if (document.getElementById) {
		if (event.which == 13) {
			event.returnValue = false;
			event.cancelBubble = true;
			btn.click();
			btn.focus();
		}
	}
	else if (document.layers) {
		if (event.which == 13) {
			event.returnValue = false;
			event.cancelBubble = true;
			btn.focus();
			btn.click();
		}
	}
}

