cookieOpt = {expires: 30, path: '/', domain: 'smarter.co.kr'};

$(function(){
	$('a.sendemail').click(function(){
		var param = $(this).attr('data');
		window.open('/sendemail/sendemail.php?'+param, 'newwindow', 'height=700, width=700, top=0,left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');		
		return false;
	});
		
	$('div.relatedproducts > div.slide > a.prev').click(function(){
		var prev = $('div.relatedproducts li').index($('div.relatedproducts li:visible:first'))-1;
		var next = prev + 2;
		if (prev < 0) {
			return false;
		}
		$('div.relatedproducts li:eq('+prev+')').show('slow');
		$('div.relatedproducts li:eq('+next+')').hide('slow');
		return false;
	});
	
	$('div.relatedproducts > div.slide > a.next').click(function(){
		var next = $('div.relatedproducts li').index($('div.relatedproducts li:visible:last'))+1;
		var prev = next - 2;
		if (next >= $('div.relatedproducts li').length) {
			return false;
		} 
		$('div.relatedproducts li:eq('+prev+')').hide('slow');
		$('div.relatedproducts li:eq('+next+')').show('slow');
		return false;
	});
	
	//enlarge image
	$('div.imgbox').hover(function(){
		$('a[rel=#overlayimg]').show();
	}, function(){
		var t = window.setTimeout(function(){$('a[rel=#overlayimg]').hide();}, 0);
		$('a[rel=#overlayimg]').hover(function(){clearTimeout(t);}, function(){$(this).hide();});
	});
	
	$('a[rel=#overlayimg]').overlay({
		top: 'center'
	});
	
	//recently viewed cookie setup
	if($('div.baseinfo').length > 0) {
		var baseinfo = $('div.baseinfo');
		var rv = $.cookie('RecentlyViewed') || '';
		var data = baseinfo.attr('chid') + '-' + baseinfo.attr('pid') ;
		if (rv.indexOf(data) == -1) {
			var itemLimit = 18;
			if (rv.split('*').length >= itemLimit) {
	            //replace the first one
	            rv = rv.substr(rv.indexOf('*') + 1);
	        }
	        var d = new Date();
	        var stime = (d.getUTCMonth() + 1) + 'x'+ d.getUTCDate() + 'x' + d.getUTCFullYear();
			data = rv ? '*'+data+'-'+stime : data+'-'+stime;
            $.cookie('RecentlyViewed', rv + data, cookieOpt);
		}
	}
	
	//product detail page coupon display
	$('div.coupon > a.detail').hover(function(){
		$(this).next('div.couponwrapper').show();
		$(this).parent(".coupon").css('z-index', '6');
	}, function(){
		var parentCoupon = $(this).parent(".coupon");
		parentCoupon.css('z-index', '0');
		var coupon = $(this).next('div.couponwrapper');
		var t = window.setTimeout(function(){
			coupon.hide()
		}, 0);
		coupon.hover(function(){
			parentCoupon.css('z-index', '6');
			clearTimeout(t);
		}, function(){
			parentCoupon.css('z-index', '0');
			$(this).hide();
		});
	});

});
