$(document).ready(function(){
	if($(document.body).hasClass('popup-cont')){
		initP();
	}
	else{
		$('a.btn-display-popup').click(function(){
		    //By Mahongtao 2009/03/11 Begin
		    if(this.id=='btnNewsletter')
		    {
		        return checkNewletter($(this));
		    }
		    //By Mahongtao 2009/03/11 End
			displayPopup(this.href);
			return false;
		});
		$('.gallery-holder li').live('mouseover', function(){
			$(this).addClass('hover');
		}).live('mouseout', function(){
			$(this).removeClass('hover');
		});
		$('.promo-column .container li').live('mouseover', function(){
			$(this).addClass('hover').find('img').eq(0).css('opacity', 0.5);
			
		}).live('mouseout', function(){
			$(this).removeClass('hover').find('img').eq(0).css('opacity', 1);
		});
		//productGal();
		slideGal1($('.slide-gal1'));
		slideGal2($('.slide-gal2'));
		slideGal3($('.slide-gal3'));
		slideGal4($('.slide-gal4'));
		slideGal5($('.slide-gal5'));
		clearInputs();
		initMenu();
		//currencyChange();
		
//		var _i=parseInt($('#CenterLogo').height());
//		
//		if(_i>103)
//		    $('#header').height(_i);

        $('.imgOver img').live('mouseover', function(){
			$(this).css('opacity', 0.5);
			
		}).live('mouseout', function(){
			$(this).css('opacity', 1);
		});
	}
});

function checkNewletter(el)
{
    var txt=el.siblings()[0];
    if(txt.value==''||txt.value=='email address')
    {
	    alert('email address is required.');
	    txt.focus();
	    return false;
    }
    if(!isEmail(txt.value))
    {
        alert('email address is not valid.');
	    txt.focus();
	    return false;
    }
    else
    {
	    el.href='inc/Newsletter.aspx?E='+escape(txt.value)+'&width=621&height=367';
	    displayPopup(el.href);
	    return false;
    }
}
/*--- function clearInputs ---*/
function clearInputs(){
	$(':text, :password').each(function(){
	
	    
		this.val = this.value;
		this.onfocus = function() {
		if(this.id=='ProductColor'||this.id=='ProductQty'){return;}
			if(this.value == this.val) { this.value = '';}
		}
		this.onblur = function() {
		if(this.id=='ProductColor'||this.id=='ProductQty'){return;}
			if(this.value == '') { this.value = this.val;}
		}
	});
}
/*--- function initMenu ---*/
function initMenu(){
	var _hold = $('ul.menu li:has(ul)');
	$('ul.menu li').each(function(){
		var _box = $(this).children('ul');
		var _btn = $(this).children('a');
		if(_box.length > 0){
			_btn.click(function(){
				_hold.not($(this).parents()).removeClass('opened').find('ul').slideUp(300);
				_box.slideToggle(300);
				$(this).parent().toggleClass('opened');
				return false;
			});
		}
		else{
			_btn.click(function(){
				_hold.not($(this).parents()).removeClass('opened').find('ul').slideUp(300);
			});
		}
		if($(this).hasClass('opened')){
			_box.show();
		}
		//By Mahongtao 2009/03/09 Begin
		else
		{
		    _box.hide();
		}
		//By Mahongtao 2009/03/09 End
	});
}
/*--- function currencyChange ---*/
function currencyChange(){
	var _list =  $('.currency ul a');
	_list.live('click', function(){
		_list.removeClass('active');
		$(this).addClass('active');
		$(this).parents('.currency').find('.currency-val').val($(this).html());
		return false;
	});
}
/*--- function product gallery ---*/
function productGal(){
	var gal_hold = $('.product-promo .product-photos');
	if(gal_hold.length > 0){
		var img_hold = gal_hold.find('.big-photo');
		var btn_list = gal_hold.find('.photos a');
		var _loader = $('<div class="load-icon">load...</div>');
		var _a;
		var _f = true;
		if(btn_list[0]){
			btn_list[0]._img = $('<img src="' + btn_list.eq(0).attr('href') + '" rel="' + btn_list.eq(0).attr('rel') + '" />');
			img_hold.html(btn_list[0]._img);
			_a = btn_list[0];
		}
		
		//By mahongtao Begin
		btn_list.mouseover(function(){
		    imgsrc=$(this).attr('href');
		    
		    $('.product-promo .product-photos .big-photo img').attr('src',imgsrc);
		    
//		    $('.product-promo .product-photos .big-photo img').fadeOut(400,function(){
//		        $('.product-promo .product-photos .big-photo img').attr('src',imgsrc);
//		    }).fadeIn(400);
		})
		//By mahongtao End
		
		btn_list.click(function(){
			if(_a != this && _f){
				var _btn = this;
				_f = false;
				img_hold.css({
					height: img_hold.height()
				});
				if(_btn._img){
					_btn._img.css({
						display: 'none',
						position: 'absolute',
						top: 0,
						left: 0
					});
					var prev_img = img_hold.find('img').fadeOut(400);
					img_hold.append(_btn._img);
					_btn._img.fadeIn(400, function(){
						_btn._img.css('position', 'static');
						prev_img.remove();
						img_hold.height('auto');
						_f = true;
					});
				}
				else{
					var prev_img = img_hold.find('img').fadeOut(200, function() {
						img_hold.append(_loader);
						_loader.fadeIn(100);
						_btn._img = $('<img src="' + _btn.href + '" rel="' + _btn.rel + '" />');
						(_btn._img).load(function(){
							_loader.fadeOut(100, function(){
								_btn._img.hide();
								img_hold.append(_btn._img);
								_btn._img.fadeIn(200, function(){
									_f = true;
								});
								prev_img.remove();
								_loader.remove();
								img_hold.height('auto');
							});
						});
					});
				}
				_a = this;
			}
			if(this.big_img){
				displayBig(this.big_img);
				
			}
			else{
				this.big_img = $('<img src="' + $(this).find('.popup-img-url').html() + '" rel="' + this.rel + '" />');
				displayBig(this.big_img);
			}
			return false;
		});
		
		//By Mahongtao 2009/04/14 Begin
		$('#bigPhoto').click(function(){
		
		        
				displayBig($('<img src="' + $('#bigPhoto img').attr('src').replace('416_292_','') + '" rel="' + $('#bigPhoto img').attr('rel') + '" />'));
		});
		//By Mahongtao 2009/04/14 End
	}
	function displayBig(big_img){
		var _duration = 300;
		var _popup = $('#popup-img-place');
		_popup.find('.img-hold').html(big_img);
		//_popup.html(big_img);
		var _fader = $('<div class="popup-fader"><div></div></div>');
		var _t = $(window).scrollTop() + $(window).height()/2;
		_fader.css({
			opacity: 0,
			display: 'block',
			height: initH()
		}).find('div').css('top', _t);
		$(document.body).append(_fader);
		hideSelectBoxes(_fader);
		_fader.fadeTo(_duration, 0.5, function(){
			if(_popup.outerHeight() >= $(window).height()){
				_popup.css('top', $(window).scrollTop());
			}
			else{
				_popup.css('top', $(window).scrollTop() + ($(window).height() - _popup.outerHeight())/2);
			}
			_popup.fadeIn(_duration/2);
			_popup.find('a.x').one('click', function(){
			
			
			
				_popup.fadeOut(_duration/2, function(){
					_fader.fadeOut(_duration, function(){
						showSelectBoxes(_fader);
						_fader.remove();
					});
				});
				
				
				
				return false;
			});
		});
	}
}
/*--- function slideGal1 ---*/
function slideGal1(gal_holders){
	gal_holders.each(function(){
	    var f=true;
		var _timer;
		var _duration = 9000;
		var gal_hold = $(this);
		var list_hold = gal_hold.find('.gallery-holder > ul');
		var btn_next = gal_hold.find('.next a');
		var btn_prev = gal_hold.find('.prev a');
		var _loader = $('<div class="load-icon">load...</div>');
		list_hold.parent().append(_loader);
		var _step = list_hold.parent().width();
		var _a = 0;
		var _list = list_hold.children();
		_list.each(function(){
			this._url = $(this).html().replace('&amp;','&');
		});
		var btn_list = $('<ul></ul>');
		for(var i = 1; i < _list.length + 1; i++){ btn_list.append('<li><a href="#">object' + i + '</a></li>');}
		gal_hold.find('.bottom-nav ul').replaceWith(btn_list);
		btn_list = gal_hold.find('.bottom-nav a');
		btn_list.eq(_a).parent().addClass('active');
		
		var prevEl = $('<li></li>');
		var thisEl = $('<li></li>');
		var nextEl = $('<li></li>');
		list_hold.css('margin-left', -_step).empty().append(prevEl, thisEl, nextEl);
		_loader.fadeIn(100);
		$.ajax({
			url: _list[_a]._url,
			cache: true,
			dataType: 'html',
			success: function(_html) {
				_loader.fadeOut(100, function(){
					var _el = $(_html);
					_list[_a]._html = _el;
					thisEl.html(_list[_a]._html);
				});
			}
		});
		function changeP(_ind){
			if(!list_hold.is(':animated') && _ind != _a){
				if(_timer) clearTimeout(_timer);
				if(_ind == -1) _ind = _list.length - 1;
				else if(_ind == _list.length) _ind = 0;
				btn_list.eq(_a).parent().removeClass('active');
				btn_list.eq(_ind).parent().addClass('active');
				if(_list[_ind]._html){
					prevEl.html(_list[_ind]._html);
					list_hold.animate({marginLeft: 0}, 400, function(){
						thisEl.html(prevEl.html());
						list_hold.css('margin-left', -_step);
						_a = _ind;
						_timer = setTimeout(function(){ changeN(_a +1);}, _duration);
					});
				}
				else{
					_loader.fadeIn(100, function(){
						$.ajax({
							url: _list[_ind]._url,
							cache: true,
							dataType: 'html',
							success: function(_html) {
								var _el = $(_html);
								_loader.fadeOut(100, function(){
									_list[_ind]._html = _el;
									prevEl.html(_el);
									list_hold.animate({marginLeft: 0}, 400, function(){
										thisEl.html(prevEl.html());
										list_hold.css('margin-left', -_step);
										_a = _ind;
										_timer = setTimeout(function(){ changeN(_a +1);}, _duration);
									});
								});
							}
						});	
					});
				}
			}
		}
		function changeN(_ind){
			if(!list_hold.is(':animated') && _ind != _a){
				if(_timer) clearTimeout(_timer);
				if(_ind == -1) _ind = _list.length - 1;
				else if(_ind == _list.length) _ind = 0;
				btn_list.eq(_a).parent().removeClass('active');
				btn_list.eq(_ind).parent().addClass('active');
				if(_list[_ind]._html){
					nextEl.html(_list[_ind]._html);
					list_hold.animate({marginLeft: -2*_step}, 400, function(){
						thisEl.html(nextEl.html());
						list_hold.css('margin-left', -_step);
						_a = _ind;
						_timer = setTimeout(function(){ changeN(_a +1);}, _duration);
					});
				}
				else{
					_loader.fadeIn(100, function(){
						$.ajax({
							url: _list[_ind]._url,
							cache: true,
							dataType: 'html',
							success: function(_html) {
								var _el = $(_html);
								_loader.fadeOut(100, function(){
									_list[_ind]._html = _el;
									nextEl.html(_el);
									list_hold.animate({marginLeft: -2*_step}, 400, function(){
										thisEl.html(nextEl.html());
										list_hold.css('margin-left', -_step);
										_a = _ind;
										_timer = setTimeout(function(){ changeN(_a +1);}, _duration);
									});
								});
							}
						});	
					});
				}
			}
		}
		if(_list.length > 1){
			btn_next.click(function(){
				changeN(_a + 1);
				return false;
			});
			btn_prev.click(function(){
				changeP(_a - 1);
				return false;
			});
			btn_list.click(function(){
				var _ind = btn_list.index(this);
				if(_ind > _a) changeN(_ind);
				if(_ind < _a) changeP(_ind);
				return false;
			});
			_timer = setTimeout(function(){ changeN(_a +1);}, _duration);
			list_hold.hover(function(){
				if(_timer) clearTimeout(_timer);
			}, function(){
				if(_timer) clearTimeout(_timer);
				if(f)_timer = setTimeout(function(){ changeN(_a +1);}, _duration);
			});
			
			list_hold.click(function(){
				if(_timer) clearTimeout(_timer);
				f=false;
			});
		}
		else{
			btn_next.click(function(){ return false;});
			btn_prev.click(function(){ return false;});
			btn_list.click(function(){ return false;});
		}
	});
}
/*--- function slideGal2 ---*/
function slideGal2(gal_holders){
	gal_holders.each(function(){
		var gal_hold = $(this);
		var list_hold = gal_hold.find('.container-list > ul');
		var btn_next = gal_hold.find('.column-heading .nav .right');
		var btn_prev = gal_hold.find('.column-heading .nav .left');
		var _loader = $('<div class="load-icon">load...</div>');
		list_hold.parent().append(_loader);
		var _step = list_hold.parent().width();
		var _a = 0;
		var _list = list_hold.children();
		_list.each(function(){
			this._url = $(this).html();
		});
		var prevEl = $('<li></li>');
		var thisEl = $('<li></li>');
		var nextEl = $('<li></li>');
		list_hold.css('margin-left', -_step).empty().append(prevEl, thisEl, nextEl);
		_loader.fadeIn(100);
		$.ajax({
			url: _list[_a]._url,
			cache: true,
			dataType: 'html',
			success: function(_html) {
				_loader.fadeOut(100, function(){
					var _el = $(_html);
					_list[_a]._html = _el;
					thisEl.html(_list[_a]._html);
				});
			}
		});
		function changeP(_ind){
			if(!list_hold.is(':animated')){
				if(_ind == -1) _ind = _list.length - 1;
				else if(_ind == _list.length) _ind = 0;
				if(_list[_ind]._html){
					prevEl.html(_list[_ind]._html);
					list_hold.animate({marginLeft: 0}, 400, function(){
						thisEl.html(prevEl.html());
						list_hold.css('margin-left', -_step);
						_a = _ind;
					});
				}
				else{
					_loader.fadeIn(100, function(){
						$.ajax({
							url: _list[_ind]._url,
							cache: true,
							dataType: 'html',
							success: function(_html) {
								var _el = $(_html);
								_loader.fadeOut(100, function(){
									_list[_ind]._html = _el;
									prevEl.html(_el);
									list_hold.animate({marginLeft: 0}, 400, function(){
										thisEl.html(prevEl.html());
										list_hold.css('margin-left', -_step);
										_a = _ind;
									});
								});
							}
						});	
					});
				}
			}
		}
		function changeN(_ind){
			if(!list_hold.is(':animated')){
				if(_ind == -1) _ind = _list.length - 1;
				else if(_ind == _list.length) _ind = 0;
				if(_list[_ind]._html){
					nextEl.html(_list[_ind]._html);
					list_hold.animate({marginLeft: -2*_step}, 400, function(){
						thisEl.html(nextEl.html());
						list_hold.css('margin-left', -_step);
						_a = _ind;
					});
				}
				else{
					_loader.fadeIn(100, function(){
						$.ajax({
							url: _list[_ind]._url,
							cache: true,
							dataType: 'html',
							success: function(_html) {
								var _el = $(_html);
								_loader.fadeOut(100, function(){
									_list[_ind]._html = _el;
									nextEl.html(_el);
									list_hold.animate({marginLeft: -2*_step}, 400, function(){
										thisEl.html(nextEl.html());
										list_hold.css('margin-left', -_step);
										_a = _ind;
									});
								});
							}
						});	
					});
				}
			}
		}
		if(_list.length > 1){
			btn_next.click(function(){
				changeN(_a + 1);
				return false;
			});
			btn_prev.click(function(){
				changeP(_a - 1);
				return false;
			});
		}
		else{
			btn_next.click(function(){ return false;});
			btn_prev.click(function(){ return false;});
		}
	});
}
/*--- function slideGal3 ---*/
function slideGal3(gal_holders){
	gal_holders.each(function(){
		var gal_hold = $(this);
		var list_hold = gal_hold.find('.container > ul');
		var btn_prev = gal_hold.find('.top');
		var btn_next = gal_hold.find('.bottom');
		var _m = 0;
		var _a = 0;
		if(list_hold.height() > list_hold.parent().height()){
			var _list = list_hold.children();
			//list_hold.append(_list.clone());
			btn_prev.click(function(){
				if(!list_hold.is(':animated')){
					if(_a == 0){
					//by ma
						return false;
					//ba ma
						_m = list_hold.height()/2;
						list_hold.css('margin-top', -_m);
						_a = _list.length;
					}
					var _k = _list.eq(_a - 1).outerHeight(true);
					_duration = _k*2;
					_m = _m - _k;
					list_hold.animate({marginTop: -_m}, _duration);
					_a--;
				}
				return false;
			});
			btn_next.click(function(){
				if(!list_hold.is(':animated')){
					if(_a == _list.length-1){
					//by ma
					return false;
					//by ma
						_m = 0;
						_a = 0;
						list_hold.css('margin-top', _m);
					}
					var _k = _list.eq(_a).outerHeight(true);
					_duration = _k*2;
					_m = _m + _k;
					list_hold.animate({marginTop: -_m}, _duration);
					_a++;
				}
				return false;
			});
		}
		else{
			btn_prev.click(function(){ return false;});
			btn_next.click(function(){ return false;});
		}
	});
}
/*--- function slideGal4 ---*/
function slideGal4(gal_holders){
	gal_holders.each(function(){
		var gal_hold = $(this);
		var list_hold = gal_hold.find('.container > ul');
		var btn_prev = gal_hold.find('.top');
		var btn_next = gal_hold.find('.bottom');
		var _m = 0;
		var _h = list_hold.height();
		var _step = list_hold.children().height();
		var _a = 0;
		if(_h > _step){
			var _list = list_hold.children();
			list_hold.append(_list.clone()).append(_list.clone());
			btn_prev.click(function(){
				if(!list_hold.is(':animated')){
					if(_m < _step) {
						_m += _h;
						list_hold.css('margin-top', -_m);
						_a = _list.length;
					}
					var n_m = 0;
					do{
						n_m += _list.eq(_a).outerHeight(true);
						_a--;
						if(_a == 0) _a = _list.length;
					}
					while(n_m + _list.eq(_a).outerHeight(true) < _step)
					_m -= n_m;
					list_hold.animate({marginTop: -_m}, 300);
				}
				return false;
			});
			var _f = true;
			btn_next.click(function(){
				if(!list_hold.is(':animated')){
					if(_m + _step > _h*2) {
						_m -= _h;
						list_hold.css('margin-top', -_m);
					}
					var n_m = 0;
					do{
						n_m += _list.eq(_a).outerHeight(true);
						_a++;
						if(_a == _list.length) _a = 0;
					}
					while(n_m + _list.eq(_a).outerHeight(true) < _step)
					_m += n_m;
					list_hold.animate({marginTop: -_m}, 300);
				}
				return false;
			});
		}
		else{
			btn_prev.click(function(){ return false;});
			btn_next.click(function(){ return false;});
		}
	});
}
/*--- function slideGal5 ---*/
function slideGal5(gal_holders){
	gal_holders.each(function(){
		var gal_hold = $(this);
		var list_hold = gal_hold.find('.container > ul');
		var btn_prev = gal_hold.find('.top');
		var btn_next = gal_hold.find('.bottom');
		var _list = list_hold.children();
		var _a = 0;
		var _m = 0;
		if(_list.length > 1) {
			//list_hold.append(list_hold.children().clone());
			
			
			
			//by mahongtao 2009/04/13 Begin
			_list.find('h3 a').each(function()
			{
			    $(this).bind('click',function()
			    {
			       var stat=$(this).parent().parent().find('.more-box').css('display');
			       
			       if(stat=='block')
			       {
			           return true;
			       }
			       else
			       {
			           _list.find('.more-box').hide();
			           
			           $(this).parent().parent().find('.more-box').show();
			           
			           return false;
			       }
			    });
			});
			//by mahongtao 2009/04/13 End
			
			_list.eq(_a).find('.more-box').show();
			
			var t_h;
			btn_next.click(function(){
				if(!list_hold.is(':animated')){
					if(_a < _list.length - 1){
						t_h = _list.eq(_a).outerHeight();
						_list.eq(_a).find('.more-box').each(function(){
							t_h -= $(this).outerHeight();
						}).slideUp(300);
						_m += t_h;
						list_hold.animate({marginTop: -_m}, 300);
						_list.eq(_a+1).find('.more-box').slideDown(300);
						_a++;
					}
//					else{
//						t_h = _list.eq(_a).outerHeight();
//						_list.eq(_a).find('.more-box').each(function(){
//							t_h -= $(this).outerHeight();
//						}).slideUp(300);
//						_m += t_h;
//						list_hold.animate({marginTop: -_m}, 300);
//						list_hold.children().eq(_list.length).find('.more-box').slideDown(300, function(){
//							_a = 0;
//							_m = 0;
//							_list.eq(_a).find('.more-box').show();
//							list_hold.css('margin-top', _m);
//							list_hold.children().eq(_list.length).find('.more-box').hide();
//						});
//					}
				}
				return false;
			});
			var _f2 = false;
			btn_prev.click(function(){
				if(!list_hold.is(':animated')){
					if(_a > 0){
						t_h = _list.eq(_a).outerHeight();
						_list.eq(_a).find('.more-box').each(function(){
							t_h -= $(this).outerHeight();
						}).slideUp(300);
						_m -= _list.eq(_a - 1).outerHeight();
						list_hold.animate({marginTop: -_m}, 300);
						_list.eq(_a - 1).find('.more-box').slideDown(300);
						_a--;
					}
//					else{
//						_list.eq(_a).find('.more-box').hide();
//						_list.each(function(){ _m += $(this).outerHeight();});
//						list_hold.css('margin-top', -_m);
//						_a = _list.length - 1;
//						_m -= list_hold.children().eq(_list.length).outerHeight();
//						list_hold.children().eq(_list.length).find('.more-box').show().slideUp(300);
//						list_hold.animate({marginTop: -_m}, 300);
//						_list.eq(_a).find('.more-box').slideDown(300);
//					}

				}
				
				return false;
			});
		}
		else{
			_list.eq(_a).find('.more-box').show();
			btn_prev.click(function(){ return false;});
			btn_next.click(function(){ return false;});
		}
	});
}
/*--- function display popup ---*/
function displayPopup(_href){

    if("javascript:void(0)"==_href)
        return;
    
	var _params = _href.split('&');
	var _url, _w, _h;
	for(var i=0; i < _params.length; i++){
		if(_params[i].indexOf('.') != -1) _url = _params[i];
		else if(_params[i].indexOf('width=') != -1) _w = _params[i].substr(_params[i].indexOf('=') + 1);
		else if(_params[i].indexOf('height=') != -1) _h = _params[i].substr(_params[i].indexOf('=') + 1);
	}
	
	var _duration = 400;
	var _fader = $('<div class="popup-fader"><div></div></div>');
	var _loader = $('<div class="load-icon">load...</div>');
	var _t = $(window).scrollTop() + $(window).height()/2;
	_fader.css({
		opacity: 0,
		display: 'block',
		height: initH()
	}).find('div').css('top', _t);
	_loader.css('top', _t);
	$(document.body).append(_fader).append(_loader);
	_loader.fadeIn(_duration);
	hideSelectBoxes(_fader);
	
	
	
	var _iFrame = $('<div id="tb-window"><iframe frameborder="0" hspace="0" src="'+_href+'" id="TB_iframeContent" style="width:'+_w+'px; height:'+_h+'px;" allowtransparency="true"></iframe></div>');
	_fader.fadeTo(_duration, 0.5, function(){
		var _t = $(window).scrollTop() + ($(window).height() - _h)/2;
		if(_t < 0) _t = 0;
		_iFrame.css({'top': _t, 'margin-left': -_w/2, display: 'block'});
		$(document.body).append(_iFrame);
		
		$(document.body).find('.load-icon').remove();
	});
	
	//by Mahongtao 2009/04/14 Begin
	if(_href.indexOf('ShoppingCart.aspx')>0)
	    $(window).scrollTop(0);
	//by Mahongtao 2009/04/14 End
	
}


function initP(){
	var top_wind = $(window.top.document.body);
	top_wind.find('#tb-window').show();
	$('.popup-cont').children().fadeIn(200, function(){
		top_wind.find('.load-icon').remove();
	});
	$('.popup a.x,.popup a.xx').click(function(){
		
		
		//By Mahongtao 2009/04/14 Begin
		
		if(this.id=='check_out')
		{
		    return true;
		}
		
		if(this.id=='check-out')
		{
		    $.ajax({
                url: '../AJAX/CurrentCartCount.ashx',
                type: 'GET',
                dataType: 'html',
                timeout: 1000,
                success: function(html){
                    
                    top_wind.find('#CurrentCartCount').html(html);
                    
                    if(html>0)
                    {
                        top_wind.find('#CurrentCartCount').parent().parent().find('a').addClass('yellow');
                    }
                    else
                    {
                        top_wind.find('#CurrentCartCount').parent().parent().find('a').removeClass('yellow');
                    }
                    
                    
                    top_wind.find('.popup-fader').fadeOut(400);
		            top_wind.find('#tb-window').fadeOut(200, function(){
			        $(this).remove();
			        top_wind.find('.popup-fader').remove();
		            });
        		
		            return false;
                    
                }
            });

		}
		else
		{
		    top_wind.find('.popup-fader').fadeOut(400);
		    top_wind.find('#tb-window').fadeOut(200, function(){
			$(this).remove();
			top_wind.find('.popup-fader').remove();
		    });
		
		    return false;
		}
		//By Mahongtao 2009/04/14 End
		
		
		
	});
}

function closeWidow()
{
    var top_wind = $(window.top.document.body);
    top_wind.find('.popup-fader').fadeOut(400);
		top_wind.find('#tb-window').fadeOut(200, function(){
			$(this).remove();
			top_wind.find('.popup-fader').remove();
		});
}

/*--- function page height ---*/
function initH() {
	var _h = $('#page').outerHeight() + $('#footer').outerHeight();
	if(_h < $(window).height()) _h = $(window).height();
	return _h;
}
/*--- function hide/show selects for IE ---*/
function hideSelectBoxes(object) {
	if ($.browser.msie && $.browser.version < 7) {
		var selects_list = $('#page select, #footer select');
		object.each(function() {
			var _el = $(this);
			var t = _el.offset().top;
			var l = _el.offset().left;
			var w = _el.outerWidth();
			var h = _el.outerHeight();
			var el_selects = [];
			selects_list.each(function(){
				var _select = $(this);
				var s_t = _select.offset().top;
				var s_l = _select.offset().left;
				var s_w = _select.outerWidth();
				var s_h = _select.outerHeight();
				var _ver = false, _hor = false;
				if((t - s_t > 0) ? (t - s_t < s_h) : (t - s_t + h > 0)) _ver = true;
				if((l - s_l > 0) ? (l - s_l < s_w) : (l - s_l + w > 0)) _hor = true;
				if(_ver && _hor) {
					_select.css('visibility', 'hidden');
					el_selects.push(this);
				}
			});
			this.sboxes = el_selects;
		});
	}
}
function showSelectBoxes(object) {
	if ($.browser.msie && $.browser.version < 7) {
		object.each(function() {
			if(this.sboxes.length > 0) {
				$(this.sboxes).css('visibility','visible');
			}
		});
	}	
}

function isEmail(s)
{
	if (s.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else
		return false;
}

function writeCookie(name, value, hours)

{

  var expire = "";

  if(hours != null)

  {

    expire = new Date((new Date()).getTime() + hours * 3600000);

    expire = "; expires=" + expire.toGMTString();

  }

  document.cookie = name + "=" + escape(value) + expire;

}



function readCookie(name)

{

  var cookieValue = "";

  var search = name + "=";

  if(document.cookie.length > 0)

  { 

    offset = document.cookie.indexOf(search);

    if (offset != -1)

    { 

      offset += search.length;

      end = document.cookie.indexOf(";", offset);

      if (end == -1) end = document.cookie.length;

      cookieValue = unescape(document.cookie.substring(offset, end))

    }

  }

  return cookieValue;

}