function tb_detectMacXFF() {
	  var userAgent = navigator.userAgent.toLowerCase();
	  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
	    return true;
	  }
	}

	function assignAjax()
	{
		$("a.cert").cluetip({
			height: 320,
			width: 644,
			closeText: '<div class="close"><a href="#"><img width="36" height="33" src="/style/img/popups/close.gif"/></a></div>',
			attribute: 'rel',
			local: true
		});

		$("a.coupon").cluetip({
			height: 345,
			width: 644,
			closeText: '<div class="close"><a href="#"><img width="36" height="33" src="/style/img/popups/close.gif"/></a></div>',
			attribute: 'rel',
			local: true,
			onShow: function(a,b){
			var newsoption1 = {
				firstname: "#cluetip-inner .coupon-container:last",
				secondname: "#cluetip-inner .coupon-show:last",
				thirdname:"#cluetip-inner .coupon-title:last",
				fourthname:"#cluetip-inner .coupon-button:last",
				playingtitle:"Now:",
				nexttitle:"Next Coupon: ",
				prevtitle:"Prev Coupon: ",
				newsspeed:15000,
				mouseover:false,
        imagedir:'/style/img/',
        disablenewscount: true
				}
				$.init_news(newsoption1);
			}
		});

		$("a.reward").cluetip({
			height: 320,
			width: 644,
			closeText: '<div class="close2"><a href="#"><img src="/style/img/popups/close.gif" width="36" height="33" /></a></div>',
			attribute: 'rel',
			local: true
		});

		$("a.infoad").cluetip({
			width: 355,
			height: 490,
			closePosition: 'title'
		});

		$(".result_pages a").click(function(){
				$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div>");
				if(tb_detectMacXFF()){
					$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
				}else{
					$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
				}

				$("body").append("<div id='TB_load'><img src='images/loading.gif' /></div>");//add loader to the page
				$('#TB_load').show();//show loader
				$("#content").load($(this).attr('href'), {}, function(){
						$("#TB_overlay, #TB_HideSelect, #TB_load").remove();
						var div_map = $("div#map_url");
						if (div_map.size() == 1)
						{
							if (div_map.text().length > 0)
								$("a#map").attr('class', 'thickbox').attr('href', div_map.text());
						}
						assignAjax();
				});
				return false;
		});
	}

	$(document).ready(function(){
		//Ajax Stop Action
		assignAjax();

		$("a#categories_link").cluetip({
			closePosition: 'title',
			width: 150,
			attribute: 'rel',
			local: true,
			onShow: function(){
				$("#cluetip-inner a").click(function(){
					var cur_val = $("#keywords").val();
					if (cur_val == 'Search for Savings by Name or Category')
						cur_val = '';
					$("#keywords").val($(this).attr('title')).focus();
					$("#cluetip-close").click();
				});
			}
		});

		$("#nh_link").cluetip({
			attribute: 'rel',
			local: true,
			closePosition: 'title',
			height: 300
		});

		$("#directions_link").cluetip({
			attribute: 'rel',
			local: true,
			closePosition: 'title',
			height: 150,
			width: 250
		});

		$("#search_form").submit(function(){
			var keywords = $(this).find(":input[@name='keywords']");
			var location = $(this).find(":input[@name='location']");
			var category = $(this).find(":input[@name='category']")

			if (keywords.val() == 'Search for Savings by Name or Category')
				keywords.val('');
			if (category.val() == 'Zip or Town')
				category.val('');
			if (keywords.val() + category.val() == '')
				keywords.val('Cincinnati');
			if (keywords.val() == 'All')
				keywords.val('Cincinnati');
			if (category.val() == 'All')
				category.val('Cincinnati');
			if (keywords.val() + category.val() == 'All')
				keywords.val('Cincinnati');
            if (category.val() == 'westchester')
				category.val('West Chester');
            if (category.val() == 'Westchester')
				category.val('West Chester');
		});

		$("a.letter_filter").click(function(){
			$("#search_form").append('<input type="hidden" name="letter" value='+$(this).text()+'>').submit();
			return false;
		});
	});