var addFavLocation = function(event, ajax_url) {
	$.getScript(ajax_url, function(data) {
		$(event).replaceWith("saved");
	});
};

var addFavShop = function(event, ajax_url) {
	$.getScript(ajax_url, function(data) {
		$(event).parent().replaceWith("<div class='fvadd_okn'>Saved</div>");
	});
};

$(document).ready(function() {
	$.superbox();
	$(".alert_red").parent("a").click(function(){
		$(".fv_s_add > a[href='javascript:void(0)']").click();
	});
	
	$(".btn_click > a").each(function(){ // Click for Detail
		var btn = $(this);
		btn.click(function(){
			var dealId = btn.next("input:hidden").val();
			var is_voucher = btn.next().next("input:hidden").val();
			var t = btn.parent().next(".codeshow");
			var newUrl = "/redirect/"+dealId;
			if(t.css("display")=="none"&&is_voucher.toLowerCase()=="false"){
				window.open(newUrl,'', 'Width=900,Height=800,toolbar=yes, menubar=yes, scrollbars=yes,resizable=yes,location=yes,status=yes,z-look=no');
			}
			
			if(t.css("display")=="none"&&is_voucher.toLowerCase()=="true"){
				window.open(newUrl,'', 'Width=900,Height=800,toolbar=yes, menubar=yes, scrollbars=yes,resizable=yes,location=yes,status=yes,z-look=no');
				window.focus();	
			}
			t.toggle();
			btn.hide();
			return false;
		});
	});
	
	$(".tellfr").each(function(){
		var temp = $(this);
		temp.click(function(){temp.parent().next(".tell_pop").toggle("slow");});
	});
	
	$(".tell_img").each(function(){
		var temp = $(this);
		temp.click(function(){temp.parent().parent().parent().parent().toggle("slow");});
	});

	$("a.workok").each(function() {
		var temp = $(this);
		temp.click(function(){
			$.getJSON("/deal_vote" + "?id="+parseInt(temp.attr("rel")),function(data){
				alert("Thank you ! Hope you enjoy shopping !");
				temp.children("span").text(data.deal.vote);
			});	
		});	
	});
	
	$("a.notwork").each(function() {
		var temp = $(this);
		temp.click(function() {
			$.getJSON("/deal_expired" + "?id="+parseInt(temp.attr("rel")),function(data){
				alert("Thank you for letting us know the expiration ! Hope you enjoy our service !");
			});
		});
	});

	$("a.re_expired").each(function() {
		var temp = $(this);
		temp.click(function() {
			$.getJSON("/deal_expired" + "?id="+parseInt(temp.attr("rel")),function(data){
				alert("Thank you for letting us know the expiration ! Hope you enjoy our service !");
			});
			return false;
		});
	});

	$("a.close_comment").each(function() {
		var a = $(this);
		a.click(function() {
			$('div.ment_c').toggle('slow');
			if (a.text() == 'Close Comments') {
				a.text('Show Comments');
			} else {
				a.text('Close Comments');
			}
			return false;
		});
	});

});
