$(document).ready(function(){
	$("#offer_details > div.offer > div.offer_head")
	.bind('mouseenter mouseleave', function(){
		$(this).toggleClass('hover')
	}).toggle(function(){
		$(this).parent().addClass("open").find('div.offer-hide').slideDown(500, 'easeOutQuint');
	},function(){
		$(this).parent().find('div.offer-hide').slideUp({duration: 500, easing: 'easeOutQuint', complete: function(){
			$(this).parents("div.offer").removeClass("open")
		}});
	}).find('a').click(function(e){
		e.stopPropagation();
	});

	$("div.offer .coupon a").click(function(){
		// couponPop( $(this).find('p > img').attr('src') );
		couponPop(this);
		return false;
	});

	$('#showAllOffers').click(function() {
		$('#showbar').attr('class', 'allOffers');
		$('#offer_details > div.offer').fadeIn();
		return false;
	});

	$('#showStoreOffers').click(function() {
		$('#showbar').attr('class', 'storeOffers');
		$('#offer_details > div.offer:not(.store)').fadeOut(function(){
			$('#offer_details > div.offer.store').fadeIn();
		});
		return false;
	});

	$('#showOnlineOffers').click(function() {
		$('#showbar').attr('class', 'onlineOffers');
		$('#offer_details > div.offer:not(.online)').fadeOut(function(){
			$('#offer_details > div.offer.online').fadeIn();
		});
		return false;
	});

	$('#printAllCoupons').click(function() {
		couponPop( $('div.offer .coupon a') );
		return false;
	});
});


function couponPop(coupons) {
	var couponPop = window.open('','coupon','height=330,width=533,scrollbars=1');
	var src = couponPop.document;
	src.write('<html><head><title>Print Coupon</title>');
	src.write('</head><body onload="window.print();">');

	$(coupons).each(function(){
		src.write('<p><img src="'+this.href+'" width="500" /></p>');
	});

	src.write('<p align="center"><input type="button" onclick="window.print()" value="print" />&nbsp;<input type="button" onclick="self.close()" value="close" /></p>');
	src.write('</body></html>');
	src.close();
}
