var J = jQuery.noConflict();
var ie6 = (J.browser.msie && J.browser.version.substring(0, 1) === '6') ? true : false;
var ie8 = (J.browser.msie && J.browser.version.substring(0, 1) === '8') ? true : false;
var ie = (J.browser.msie) ? true : false;
var saf = (J.browser.safari) ? true : false;

J(document).ready(function ($) {

	/* Select box */
	$("SELECT").selectbox();

	/* Cufon */
	Cufon.replace('#content .title-page h1')('#content .box-blog h3')('#content .filters .column-filter h4')('#header .top-menu ul li .my-bag a.button-rose')
	('.head-box h3')('#content .box.newsletter h2')('.guide-description H2')('.home-top-content h2')('#content .column-filter .first .filter-size h4')('#content .home-content .link-pic span')('#content .main-content .link-pic span')
    ('#content .link-view span.click-to-view, #content .link-view-modal span.click-to-view');
	if (!ie6) Cufon.replace('.home-top-content ul li a', { hover: true });
	if (ie) Cufon.replace('#content .home-content .link-pic em', { hover: true, hoverables: { em: true} })

	/* Center content */
	setup_center_page();

	$(window).bind('resize', function () {
		setup_center_page();
	});

	$('.link-lightbox3-gallery').click(function () {
		show_lightbox3(this, '-gallery');
		window.scroll(0, 0);
		return false;
	});

	$('.link-pic .overlay-bg').mouseover(function () {
		$(this).attr('src', $(this).attr('src').replace('_off', '_on'));
	});

	$('.link-pic .overlay-bg').mouseout(function () {
		$(this).attr('src', $(this).attr('src').replace('_on', '_off'));
	});

	$('.item SPAN.view').click(function () {
		$(this).parent().children('A.link-lightbox3-gallery').click();
		return false;
	});


	/* 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'));
	});

	/*Scroll*/
	fleXenv.fleXcrollMain('scroll');

	if ($.browser.msie && ($.browser.version < 7)) {
		$('.vscrollerbar').hover(function () {
			$('.vscrollerbar').addClass('hover');
		},
		function () {
			$('.vscrollerbar').removeClass('hover');
		})
	}

	// Initialize Backgound Stretcher 
	$(document).bgStretcher({
		images: ['/layout/images/bg/body-bg.jpg'],
		imageWidth: 1250, imageHeight: 1280, slideShow: false
	});

	/* Overlay */
	$('.link-lightbox .quick-view').click(function () {
		var el = $(this).parents('.link-lightbox:first');
		var id = $(el).next('input').val();
		showPopUp(id, id);
		setValue(id, id);
		s_config(this);
		return false;
	});
	$('.link-lightbox').click(function () {
		if ($('.quick-view', this).length) return true;
		showPopUp();
		return false;
	});

	$('.link-lightbox-gallery').click(function () {
		show_lightbox(this, '-gallery');
		window.scroll(0, 0);
		return false;
	});

	$('.item SPAN.view').click(function () {
		$(this).parent().children('A.link-lightbox-gallery').click();
		return false;
	});

	$('.link-view').click(function () {
		show_lightbox(this, '-view');
		window.scroll(0, 0);
		return false;
	});

	$('.link-view-modal').click(function () {
		show_lightbox4(this, '-view');
		window.scroll(0, 0);
		return false;
	});

	$('.link-view SPAN.label').click(function () {
		$(this).parent('A.link-view').click();
		return false;
	});

	if ($(".carousel ul.pic-area LI").length > 0) {
		$(".carousel").jCarouselLite({
			visible: 4,
			scroll: 1,
			btnNext: ".head-box .next",
			btnPrev: ".head-box .prev"
		});
	}
	else {
		$(".head-box").css('display', 'none');
	}

	/* Overlay - Share This */
	$('.link-lightbox2 .quick-view').click(function () {
		var el = $(this).parents('.link-lightbox2:first');
		show_lightbox2(el);
		return false;
	});
	$('.link-lightbox2').click(function () {
		if ($('.quick-view', this).length) return true;
		show_lightbox2(this);
		return false;
	});

	if ($('.thumbnails-list ul li').length > 3) {
		$('.thumbnails-list ul').jcarousel({
			buttonNextHTML: '<div class="next"><img src="/layout/images/buttons/next.gif" alt="Previous" /></div>',
			buttonPrevHTML: '<div class="prev"><img src="/layout/images/buttons/prev.gif" alt="Previous" /></div>',
			scroll: 1
		});
	}

	/* Tabs */
	$('.tabs A').click(function () {
		if ($($(this).attr('href')).hasClass('selected')) return false;
		$('.tab-area .selected').removeClass('selected');
		$('.tabs A.active').removeClass('active');
		$($(this).attr('href')).addClass('selected');
		$(this).addClass('active');
		return false;

	});


	/*  My bag slide down  */

	SetMyBagHover();

	/*  Home page featured item animation  */
	if (!ie6) {
		$('.slideshow LI .featured-item').css('opacity', 0);
		$('.slideshow LI').hover(function () {
			var featuredItem = $('.featured-item', this);
			$(featuredItem).stop(true);
			$(featuredItem).fadeTo(600, 1);
			return false;
		}, function () {
			var featuredItem = $('.featured-item', this);
			$(featuredItem).stop(true);
			$(featuredItem).css('display', 'block');
			$(featuredItem).fadeTo(500, 0);
			return false;
		});
	}

	/*  Quick view button animation  */
	$('.link-lightbox').hover(function () {
		var button = $('.quick-view', this);
		var label = $('.label', this);
		$(button).css('opacity', 0).stop(true).animate({
			opacity: 1
		}, 350);
		if (!ie6 && !ie) $(label).stop(true).css('opacity', 0.5).animate({
			opacity: 1
		}, 350);

		return false;
	}, function () {
		var button = $('.quick-view', this);
		var label = $('.label', this);
		$(button).stop(true).animate({
			opacity: 0
		}, 350);
		if (!ie6 && !ie) $(label).stop(true).css('opacity', 0.5).animate({
			opacity: 1
		}, 350);
		return false;
	});

	/* Shop Now button animation  */
	$('.lifestyle-pic').hover(function () {
		var button = $('.press-shop-now', this);
		$(button).css('opacity', 0).stop(true).animate({
			opacity: 1
		}, 450);
		return false;
	}, function () {
		var button = $('.press-shop-now', this);
		$(button).stop(true).animate({
			opacity: 0
		}, 450);
		return false;
	});

	$('.lifestyle-pic .press-shop-now').click(function () {
		id = $(this).attr('id');
		link = $('#shop-link-' + id).val();
		window.location.href = link;
		return false;
	});

	$('.lifestyle-pic').hover(function () {
		var button = $('.sightings-shop-now', this);
		$(button).css('opacity', 0).stop(true).animate({
			opacity: 1
		}, 450);
		return false;
	}, function () {
		var button = $('.sightings-shop-now', this);
		$(button).stop(true).animate({
			opacity: 0
		}, 450);
		return false;
	});

	$('.lifestyle-pic .sightings-shop-now').click(function () {
		id = $(this).attr('id');
		link = $('#shop-link-' + id).val();
		window.location.href = link;
		return false;
	});

	/*  Filters animation  */
	$('#filter').hover(function () {
		var filters = $('#filters', this);
		if (!$(filters).length) return;
		$(filters).stop(true);
		$(filters).css({ 'display': 'none', 'height': 'auto' });
		if (ie6) {
			$(filters).animate({
				height: 'toggle'
			}, 500);
		} else {
			$(filters).css({ 'opacity': 0 });
			$(filters).animate({
				opacity: 1,
				height: 'toggle'
			}, 500);
		}

		return false;
	}, function () {
		var filters = $('#filters', this);
		if (!$(filters).length) return;

		$(filters).stop(true);
		if (ie6) {
			$(filters).animate({
				height: 'toggle'
			}, 300, function () { $(filters).css('height', 'auto'); });
		} else {
			$(filters).animate({
				opacity: 0,
				height: 'toggle'
			}, 300, function () { $(filters).css('height', 'auto'); });
		}

		return false;
	});

	$(".carousel").jCarouselLite({
		visible: 4,
		scroll: 1,
		btnNext: ".head-box .next",
		btnPrev: ".head-box .prev"
	});

	/* Campaign Page */
	$('.item').hover(function () {
		$('.item .view').css('display', 'none');
		$('.item .shadow').stop(true, true).addClass('fade-to');
		$(this).children('.shadow').removeClass('fade-to');
		$('.item .fade-to').show().fadeTo(200, 0.8);
		$(this).children('.shadow').fadeTo(200, 0, function () {
			$(this).css('display', 'none');
		});
		$(this).children('.view').css('display', 'block');
	},
	function () {
		$('.item .view').css('display', 'none');
	});

	$('.item A.link-embed-video').click(function () {
		$(this).html('<if' + 'rame src="' + $(this).attr('href') + '" width="' + $(this).width() + '" height="' + $(this).height() + '" frameborder="0"></ifr' + 'ame>');
		return false;
	});

	$('.campaign').hover(function () { }, function () {
		$('.item .shadow').fadeTo(200, 0);
	});

	$('.bg-thumb-mini').click(function (event) {
		J('.BeatImgContainer').hide();
		J('.DefaultImgContainer').show();
	});

	$('.link-view').hover(function () {
		$(this).children('SPAN.label').fadeTo(300, 1);
	}, function () {
		$(this).children('SPAN.label').fadeTo(300, 0);
	});

	$("#realZOOMHighlight").live('click', function () {
		$('.main-content').hide();
		show_lightbox4(this, '-view');
		window.scroll(0, 0);
		return false;
	})

});

function load_quicklook(id) {
	var url = '/store/QuickLook.aspx?productid=' + id + '&action=1';
	J.ajax({
		url: url,
		success: function (html) {
			show_lightbox_QV(html);
			BuildQuicklookJs();
			change_unitcost(id);
			initializeAllProducts('true');
		},
		error: function (e) {
			alert(e.responseText);
		}
	});
}

$modal = J.extend({
	el: null,
	suf: null
});

function show_lightbox(el, suf) {
	$modal.el = el;
	$modal.suf = suf;
	var w = J(window).width();
	var h = J(document).height();
	if (ie6) w -= 16;
	if (suf == '-view') {
		h += 40;
		if (ie6) w -= 6;
	}
	J('.overlay' + suf).css('width', w).css('height', h).show();
	var w_p = parseInt((w - J('#custom-lightbox' + suf).width()) / 2);
	J('#custom-lightbox' + suf).css('left', w_p);

	if (suf != '-gallery') {
		J('#custom-lightbox' + suf + ' .lightbox-wrapper').html(J(el).parent().children('.custom-lightbox').html());
	} else {
		if (J('#custom-lightbox' + suf + ' .lightbox-wrapper').hasClass('go-gallery')) {
			J('#custom-lightbox' + suf + ' .lightbox-wrapper').removeClass('go-gallery').html('');
		}
		J('#custom-lightbox' + suf + ' .lightbox-wrapper').load(J(el).attr('href'), function (response, status, xhr) {
			J('#custom-lightbox' + suf + ' .lightbox-wrapper').addClass('go-gallery');
			go_big_slideshow(J(el).attr('rel').split('-')[1], J(el).attr('rel').split('-')[0]);
		});
	}

	J('#custom-lightbox' + suf + ' .lightbox-wrapper').css('display', 'inline');
	J('#custom-lightbox' + suf + ' A.close-lightbox').show();

	if (ie) {
		if ((!ie6) && (suf == '')) J('#custom-lightbox' + suf).css('top', '125px');
		J('#custom-lightbox' + suf).css({ 'display': 'block' });
		if (J('.social-link a.more').length) {
			J('.social-link a.more').unbind('click');
			J('.social-link a.more').click(function () {
				var to_show = J(this).attr('rel');
				J(to_show).slideDown(1000);
				return false;
			});
		}
	} else {
		if (suf == '') J('#custom-lightbox' + suf).css('top', '125px');
		J('#custom-lightbox' + suf).css({ 'opacity': 0, 'display': 'block' });
		J('#custom-lightbox' + suf).fadeTo(800, 1, function () {
			if (J('.social-link a.more').length) {
				J('.social-link a.more').unbind('click');
				J('.social-link a.more').click(function () {
					var to_show = J(this).attr('rel');
					J(to_show).slideDown(1000);
					return false;
				});
			}
		});
	}

	J('.overlay' + suf).click(function () {
		hide_lightbox(suf);
	});

	J('.close-lightbox').click(function () {
		hide_lightbox(suf);
	});

}

function hide_lightbox(suf) {
	$('.main-content').show();
	if (!ie) {
		J('#custom-lightbox' + suf).fadeTo(200, 0, function () {
			J('.overlay' + suf).hide();
			J('#custom-lightbox' + suf + ' .lightbox-wrapper').hide();
			J('#custom-lightbox' + suf + ' A.close-lightbox').hide();
			J('#custom-lightbox' + suf).css('top', '0px');
		}).hide();
	} else {
		J('.overlay' + suf).hide();
		J('#custom-lightbox' + suf + ' .lightbox-wrapper').hide();
		J('#custom-lightbox' + suf + ' A.close-lightbox').hide();
		J('#custom-lightbox' + suf).css({ 'display': 'none' });
	}
}

function show_lightbox_QV(html) {
	var w = J(document).width();
	var h = J(document).height();
	if (ie6) w -= 16;
	J('.overlay').css('width', w).css('height', h).show();
	var w_p = parseInt((w - J('#custom-lightbox').width()) / 2);
	J('#custom-lightbox').css('left', w_p);
	J('#custom-lightbox .lightbox-wrapper').html(html);
	J('#custom-lightbox .lightbox-wrapper').css('display', 'inline');
	J('#custom-lightbox A.close-lightbox').show();

	if (ie6) {
		//J('#custom-lightbox').css('top', '125px');
		J('#custom-lightbox').css({ 'display': 'block' });
		if (J('.social-link a.more').length) {
			J('.social-link a.more').unbind('click');
			J('.social-link a.more').click(function () {
				var to_show = J(this).attr('rel');
				J(to_show).slideDown(1000);
				return false;
			});
		}
	} else {
		J('#custom-lightbox').css('top', '125px');
		J('#custom-lightbox').css({ 'opacity': 0, 'display': 'block' });
		J('#custom-lightbox').fadeTo(800, 1, function () {
			if (J('.social-link a.more').length) {
				J('.social-link a.more').unbind('click');
				J('.social-link a.more').click(function () {
					var to_show = J(this).attr('rel');
					J(to_show).slideDown(1000);
					return false;
				});
			}
		});
	}

	J('.overlay').click(function () {
		hide_lightbox_QV();
	});

	J('.close-lightbox').click(function () {
		hide_lightbox_QV();
	});

}

function hide_lightbox_QV() {
	if (!ie6) {
		J('#custom-lightbox').fadeTo(200, 0, function () {
			J('.overlay').hide();
			J('#custom-lightbox .lightbox-wrapper').hide();
			J('#custom-lightbox A.close-lightbox').hide();
			J('#custom-lightbox').css('top', '0px');
		}).hide();
	} else {
		J('.overlay').hide();
		J('#custom-lightbox .lightbox-wrapper').hide();
		J('#custom-lightbox A.close-lightbox').hide();
		J('#custom-lightbox').css({ 'display': 'none' });
	}
}

function setup_center_page() {
	var w_cont = parseInt(J(window).width());
	var w_page_bg = parseInt(J('.bg').css('width'));
	var w_page = parseInt(J('#page').css('width'));
	w_page = 999;
	var mar_page_bg = 0;

	if (w_cont < w_page) w_cont = w_page;
	if (w_cont < w_page_bg) {
		mar_page_bg = ((w_page_bg - w_cont) / 2) * (-1);
		J('.container').width(w_cont - 8 + 'px');
		J('.bg').css('margin-left', mar_page_bg + 'px');
	} else {
		J('.bg').css('margin-left', 'auto').css('margin-right', 'auto');
		J('.container').width('auto');
	}

}

function show_lightbox2(el) {
	var w = J(document).width();
	var h = J(document).height();
	if (ie6) w -= 16;
	if (ie8) w -= 20;
	J('.overlay').css('width', w).css('height', h).show();
	var w_p = parseInt((w - J('#custom-lightbox2').width()) / 2);
	J('#custom-lightbox2').css('left', w_p);
	J('#custom-lightbox2 .lightbox-wrapper2').html(J(el).parent().children('.custom-lightbox2').html());
	J('#custom-lightbox2 .lightbox-wrapper2').css('display', 'inline');
	J('#custom-lightbox2 A.close-lightbox2').show();

	if (ie) {
		if (!ie6) J('#custom-lightbox2').css('top', '125px');
		J('#custom-lightbox2').css({ 'display': 'block' });
		if (J('.social-link a.more').length) {
			J('.social-link a.more').unbind('click');
			J('.social-link a.more').click(function () {
				var to_show = J(this).attr('rel');
				J(to_show).slideDown(1000);
				return false;
			});
		}
	} else {
		J('#custom-lightbox2').css('top', '125px');
		J('#custom-lightbox2').css({ 'opacity': 0, 'display': 'block' });
		J('#custom-lightbox2').fadeTo(800, 1, function () {
			if (J('.social-link a.more').length) {
				J('.social-link a.more').unbind('click');
				J('.social-link a.more').click(function () {
					var to_show = J(this).attr('rel');
					J(to_show).slideDown(1000);
					return false;
				});
			}
		});
	}

	J('.overlay').click(function () {
		hide_lightbox2();
	});

	J('.close-lightbox2').click(function () {
		hide_lightbox2();
	});

}

function show_lightbox3(el, suf) {
	var w = J(document).width();
	var h = J(document).height();
	if (ie6) w -= 16;
	if (ie8) w -= 20;
	if (suf == '-view') {
		h += 40;
		if (ie6) w -= 6;
		if (ie8) w -= 2;
	}

	J('.overlay' + suf).css('width', w).css('height', h).show();
	var w_p = parseInt((w - J('#custom-lightbox3' + suf).width()) / 2);
	J('#custom-lightbox3' + suf).css('left', w_p);

	if (suf != '-gallery') {
		J('#custom-lightbox3' + suf + ' .lightbox-wrapper3').html(J(el).parent().children('.custom-wrapper3').html());
	} else {
		if (J('#custom-lightbox3' + suf + ' .lightbox-wrapper3').hasClass('go-gallery')) {
			J('#custom-lightbox3' + suf + ' .lightbox-wrapper3').removeClass('go-gallery').html('');
		}
		J('#custom-lightbox3' + suf + ' .lightbox-wrapper3').load(J(el).attr('href'), function () {
			J('#custom-lightbox3' + suf + ' .lightbox-wrapper3').addClass('go-gallery');
			go_big_slideshow(J(el).attr('rel').split('-')[1], J(el).attr('rel').split('-')[0]);
		});
	}

	J('#custom-lightbox3' + suf + ' .lightbox-wrapper3').css('display', 'inline');
	J('#custom-lightbox3' + suf + ' A.close-lightbox3').show();

	if (ie) {
		if ((!ie6) && (suf == '')) J('#custom-lightbox3' + suf).css('top', '125px');
		J('#custom-lightbox3' + suf).css({ 'display': 'block' });
		if (J('.social-link a.more').length) {
			J('.social-link a.more').unbind('click');
			J('.social-link a.more').click(function () {
				var to_show = J(this).attr('rel');
				J(to_show).slideDown(1000);
				return false;
			});
		}
	} else {
		if (suf == '') J('#custom-lightbox3' + suf).css('top', '125px');
		J('#custom-lightbox3' + suf).css({ 'opacity': 0, 'display': 'block' });
		J('#custom-lightbox3' + suf).fadeTo(800, 1, function () {
			if (J('.social-link a.more').length) {
				J('.social-link a.more').unbind('click');
				J('.social-link a.more').click(function () {
					var to_show = J(this).attr('rel');
					J(to_show).slideDown(1000);
					return false;
				});
			}
		});
	}

	J('.overlay' + suf).click(function () {
		hide_lightbox3(suf);
	});

	J('.close-lightbox3').click(function () {
		hide_lightbox3(suf);
	});

}

function show_lightbox4(el, suf) {
	var w = J(document).width();
	var h = J(document).height();
	if (ie6) w -= 16;
	if (ie8) w -= 20;
	if (suf == '-view') {
		h += 40;
		if (ie6) w -= 6;
		if (ie8) w -= 2;
		if (saf) h += 300;
	}
	J('.overlay' + suf).css('width', w).css('height', h).show();
	var w_p = parseInt((w - J('#custom-lightbox4' + suf).width()) / 2);
	J('#custom-lightbox4' + suf).css('left', w_p).show();

	if (suf != '-gallery') {
		J('#custom-lightbox4' + suf + ' .lightbox-wrapper4').html(J('.custom-lightbox4').html());
	} else {
		if (J('#custom-lightbox4' + suf + ' .lightbox-wrapper4').hasClass('go-gallery')) {
			J('#custom-lightbox4' + suf + ' .lightbox-wrapper4').removeClass('go-gallery').html('');
		}
		J('#custom-lightbox4' + suf + ' .lightbox-wrapper4').load(J(el).attr('href'), function () {
			J('#custom-lightbox4' + suf + ' .lightbox-wrapper4').addClass('go-gallery');
			go_big_slideshow(J(el).attr('rel').split('-')[1], J(el).attr('rel').split('-')[0]);
		});
	}

	J('#custom-lightbox4' + suf + ' .lightbox-wrapper4').css('display', 'inline');
	J('#custom-lightbox4' + suf + ' A.close-lightbox4').show();

	if (ie) {
		if ((!ie6) && (suf == '')) J('#custom-lightbox4' + suf).css('top', '125px');
		J('#custom-lightbox4' + suf).css({ 'display': 'block' });
		if (J('.social-link a.more').length) {
			J('.social-link a.more').unbind('click');
			J('.social-link a.more').click(function () {
				var to_show = J(this).attr('rel');
				J(to_show).slideDown(1000);
				return false;
			});
		}
	} else {
		if (suf == '') J('#custom-lightbox4' + suf).css('top', '125px');
		J('#custom-lightbox4' + suf).css({ 'opacity': 0, 'display': 'block' });
		J('#custom-lightbox4' + suf).fadeTo(800, 1, function () {
			if (J('.social-link a.more').length) {
				J('.social-link a.more').unbind('click');
				J('.social-link a.more').click(function () {
					var to_show = J(this).attr('rel');
					J(to_show).slideDown(1000);
					return false;
				});
			}
		});
	}

	J('.overlay' + suf).click(function () {
		J('.main-content').show();
		hide_lightbox4(suf);
	});

	J('.close-lightbox4').click(function () {
		J('.main-content').show();
		hide_lightbox4(suf);
	});

}

function hide_lightbox4(suf) {
	if (!ie) {
		J('#custom-lightbox4' + suf).fadeTo(200, 0, function () {
			J('.overlay' + suf).hide();
			J('#custom-lightbox4' + suf + ' .lightbox-wrapper4').hide();
			J('#custom-lightbox4' + suf + ' A.close-lightbox4').hide();
			J('#custom-lightbox4' + suf).css('top', '0px');
		}).hide();
	} else {
		J('.overlay' + suf).hide();
		J('#custom-lightbox4' + suf + ' .lightbox-wrapper4').hide();
		J('#custom-lightbox4' + suf + ' A.close-lightbox4').hide();
		J('#custom-lightbox4' + suf).css({ 'display': 'none' });
	}
}

function hide_lightbox3(suf) {
	if (!ie) {
		J('#custom-lightbox3' + suf).fadeTo(200, 0, function () {
			J('.overlay' + suf).hide();
			J('#custom-lightbox3' + suf + ' .lightbox-wrapper3').hide();
			J('#custom-lightbox3' + suf + ' A.close-lightbox3').hide();
			J('#custom-lightbox3' + suf).css('top', '0px');
		}).hide();
	} else {
		J('.overlay' + suf).hide();
		J('#custom-lightbox3' + suf + ' .lightbox-wrapper3').hide();
		J('#custom-lightbox3' + suf + ' A.close-lightbox3').hide();
		J('#custom-lightbox3' + suf).css({ 'display': 'none' });
	}
}

function hide_lightbox2() {
	if (!ie) {
		J('#custom-lightbox2').fadeTo(200, 0, function () {
			J('.overlay').hide();
			J('#custom-lightbox2 .lightbox-wrapper2').hide();
			J('#custom-lightbox2 A.close-lightbox2').hide();
			J('#custom-lightbox2').css('top', '0px');
		}).hide();
	} else {
		J('.overlay').hide();
		J('#custom-lightbox2 .lightbox-wrapper2').hide();
		J('#custom-lightbox2 A.close-lightbox2').hide();
		J('#custom-lightbox2').css({ 'display': 'none' });
	}
}

function RemoveItem(recid, qty) {
	var url = '/store/removeminicartitem.aspx?recid=' + recid;
	J('#minicart-message').show();
	J('#minicart-message').html('processing...');
	J.ajax({
		url: url,
		success: function (data) {
			var notice = J('#minicart-message');
			notice.html('Item has been removed from your Bag!');
			setTimeout(function () { notice.hide('slow'); }, 2000);
			setTimeout(function () { RefreshCart(); }, 1000);
			if (document.getElementById('ShoppingBag1_CartItemsCountLB') == null) {
				document.getElementById('Header1_ShoppingBag1_CartItemsCountLB').innerHTML = parseInt(document.getElementById('Header1_ShoppingBag1_CartItemsCountLB').innerHTML) - qty;
			} else {
				document.getElementById('ShoppingBag1_CartItemsCountLB').innerHTML = parseInt(document.getElementById('ShoppingBag1_CartItemsCountLB').innerHTML) - qty;
			}
		},
		error: function (err) {
			return false;
		}
	});

}

function RefreshCart() {
	J.ajax({
		url: '/store/MiniCart.aspx',
		cache: false,
		success: function (html) {
			J('.my-bag-bg').html(html);
		}
	});
}

function ShareThis(pid, cid) {
	var notice = J('#sharethis-message');
	var emailfrom = document.getElementById('ContentPlaceHolder1_SocialNetwork1_raf_email_from').value;
	var emailto = document.getElementById('ContentPlaceHolder1_SocialNetwork1_raf_email_to').value;
	var message = document.getElementById('ContentPlaceHolder1_SocialNetwork1_raf_message').value;
	var url = '/store/sharethis.aspx?pid=' + pid + "&emailfrom=" + emailfrom + "&emailto=" + emailto + "&message=" + message + "&colorid=" + cid;

	J('#sharethis-message').show();
	J('#sharethis-message').html('sending...');

	if (emailfrom == "" || emailto == "") {
		notice.html('Please enter an email!');
		setTimeout(function () { notice.hide('slow'); }, 1000);
		return;
	}
	if (emailfrom != "" && emailto != "") {
		ValidateEmail(emailfrom);
		ValidateEmail(emailto);
	}

	J.ajax({
		url: url,
		success: function (data) {
			notice.html('Email has been sent!');
			setTimeout(function () { notice.hide('slow'); }, 2000);
		},
		error: function (err) {
			alert(err.responseText);
		}
	});
}

function ValidateEmail(str) {

	var notice = J('#sharethis-message');
	J('#sharethis-message').show();

	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str)) {
		return true;
	} else {
		notice.html('Invalid E-mail Address! Please re-enter.');
		setTimeout(function () { notice.hide('slow'); }, 1000);
		return false;
	}
}

function UpdateShoppingBag() {
	J.ajax({
		url: '/store/MiniCartAjax.aspx',
		success: function (html) {
			J('.my-bag-count').html(html);
		}
	});
}

function load_minicart_contents() {
	RefreshCart();
}

function UpdateShoppingBagCount(qty, price) {
	var CartItems;
	var CartItemsHidden;

	CartItems = getElementByID_Master("CartItemsLBGet");
	CartItemsHidden = getElementByID_Master("ctl00$ShoppingBag1$CartItemsHidden");

	if (CartItems != null)
		CartItems.innerHTML = parseInt(CartItems.innerHTML) + parseInt(qty);
}

function OnResponseEnd() {
	UpdateShoppingBag();
	UpdateShoppingBagCount(getElementByID_Master('ContentPlaceHolder1_QuantityTB'), 0);
	load_minicart_contents();
	ShowShoppingBag();
}

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 toggleDesc() {
	var desc = document.getElementById('DescriptionHidden').value;
	var descblock = document.getElementById('descblock');
	var descblockcontainer = document.getElementById('descblockcontainer');

	if (descblockcontainer.style.display == 'none') {
		descblockcontainer.innerHTML = desc;
		descblockcontainer.style.display = 'block';
	} else {
		descblockcontainer.innerHTML = '';
		descblockcontainer.style.display = 'none';
	}
}

function change_img(img) {
	getElementByID_Master("BeatImg").src = img;
	J('.BeatImgContainer').show();
	J('.DefaultImgContainer').hide();
}

