VISA.include_js("/js/jquery/jquery.bgiframe.min.js");
VISA.include_js("/js/jquery/jquery.client.js");

var allMerchantsTimeoutHide;
var allMerchantsTimeoutShow;
var allMerchantsReady = false;

// for google pageView tracking
var pageTracker;
if(typeof _gat !== 'undefined') {
    pageTracker = _gat._getTracker("UA-8460445-1");
}

// Stop IE from always trying to download background images
try
{
    document.execCommand("BackgroundImageCache", false, true);
}
catch(exception)
{
    // Do nothing
}

var QueryStringInstance = function () {

    var qs, params, args, i, value, pair, name;
    qs = (location.search.length > 1) ? location.search.substring(1, location.search.length):'';
    params = {};

    if (qs.length > 0) {
        qs = qs.replace(/\+/g, ' ');
        args = qs.split('&'); // parse out name/value pairs separated via &

        for (i = 0; i < args.length; i += 1) {

            pair = args[i].split('=');
            name = unescape(pair[0]);
            if (pair.length === 2) {
                value = unescape(pair[1]);
            } else {
                value = name;
            }
            params[name] = value;
        }
    }

    this.get = function (key) {
        if (qs === "") {
            return "";
        }
        var value = params[key];
        if (!value) {
            value = '';
        }
        return value;
    };

};

var QueryString = new QueryStringInstance();

var emailValue = {
    from: "",
    fromEmail: "",
    to: "",
    toEmail: "",
    message: "",
    shortDesc: "",
    imgUrl: "",
    subject: "",
    offerName: "",
    shareUrl: ""
};
// call by flash to send email
function mdEmailPromotion(from, fromEmail, to, toEmail, message, shortDesc, imgUrl, subject, offerName, shareUrl) {

    emailValue.from = from;
    emailValue.fromEmail = fromEmail;
    emailValue.to = to;
    emailValue.toEmail = toEmail;
    emailValue.message = unescape(message);
    emailValue.shortDesc = unescape(shortDesc);
    emailValue.imgUrl = imgUrl;
    emailValue.subject = unescape(subject);
    emailValue.offerName = offerName;
    emailValue.shareUrl = shareUrl;
    console.log(emailValue);
    
    var iframe = $('#frameEmail');
    var url = '/personal/discounts/discounts-email.html';

    if(iframe.length < 1) {
        iframe = $('<iframe src="' + url + '" id="frameEmail" width="0" height="0" frameborder="0"></iframe>');
        $('body').append(iframe);
    } else {
        $(iframe[0]).attr('src', url);
    }
};

// this function is called by an iframe document to submit email
function submitEmail() {
    var iframe = document.getElementById("frameEmail");
    var iDoc = iframe.contentWindow || iframe.contentDocument;
    if (iDoc.document) {
        iDoc = iDoc.document;
    }
    iDoc.getElementById('FROMNAME').value = emailValue.from;
    iDoc.getElementById('email').value = emailValue.fromEmail;
    iDoc.getElementById('FRIEND_FNAME1').value = emailValue.to;
    iDoc.getElementById('FRIEND_EMAIL1').value = emailValue.toEmail;
    iDoc.getElementById('SHORT_DESC').value = emailValue.shortDesc;
    iDoc.getElementById('SUBJECT_LINE').value = emailValue.subject;
    iDoc.getElementById('MESSAGE').value = emailValue.message;
    iDoc.getElementById('TEXT_OFFER_NAME').value = emailValue.offerName;
    iDoc.getElementById('OFFER_URL').value = emailValue.shareUrl;
    iDoc.getElementById('IMAGE_URL').value = emailValue.imgUrl;
    iDoc.getElementById('formEmail').submit();
}

$(document).ready(function() {

    //couponCopy();
    checkAllMerchants();
    //merchantSlider();
    // init custom analytics
    discountsAnalytics.initAnalytics();

	/////////////////////////////////
	// DETAIL OFFER TOOLTIP BEGINS //
	/////////////////////////////////

    /*
    $(".landing_offer").hover(function() {
		if($(this).hasClass('couponInitalize')) {
		
		} else {
			couponCopy();
		}
		$(".landing_offer").addClass('couponInitalize');
	});
    */

    $(".landing_offer .gray").click(function(event) {
		$("#detail_offer_tc").hide();
		displayDetailOfferTooltip(event, $(this).parent());
		return false;
	});

	$(".category_offer").hover(function() {
		$(this).css("cursor", "pointer");
		$(this).addClass("hover");
    }, function() {
		$(this).css("cursor", "auto");
		$(this).removeClass("hover");
	});

	$(".category_offer").click(function(event) {
		$("#detail_offer_tc").hide();
		displayDetailOfferTooltip(event, $(this));
		return false;
	});

    // stop dropdowns showing through the detail offer tooltip on IE6
    $(".detail_offer_tooltip").bgiframe();

	///////////////////////////////
	// DETAIL OFFER TOOLTIP ENDS //
	///////////////////////////////

    $('.landing-offer-sharing a').click(function(e){
        if($(this).hasClass('email')) {
            pop_email($(this).attr('href'));
            e.preventDefault();
            return false;
        } else if ($(this).hasClass('facebook')) {
            pop_facebook($(this).attr('href'));
            e.preventDefault();
            return false;
        }
    });

	/////////////////////////////////////////////
	// SIGNATURE EVENT PAGE SHARE OVERLAY ENDS //
	/////////////////////////////////////////////		
	
	$.preloadImages(
		"/img/other/bebo_ico.gif",
		"/img/other/email_ico.gif",
		"/img/other/facebook_ico.gif",
		"/img/other/myspace_ico.gif",
		"/img/other/twitter_ico.gif",
		"/img/other/callout_bg.jpg",
		"/img/other/share_overlay_top.gif",
		"/img/other/share_overlay_btm.gif",
		"/img/other/btn-share.gif",
		"/img/other/btn-share-over.gif",
		"/img/other/tooltip/tooltip-narrow-top.png", 
		"/img/other/tooltip/tooltip-narrow-mid.png",
		"/img/other/tooltip/tooltip-narrow-bot.png", 
		"/img/other/tooltip/tooltip-wide-top.png", 
		"/img/other/tooltip/tooltip-wide-mid.png", 
		"/img/other/tooltip/tooltip-wide-bot.png"
	);	
});

// handles custom analytics no the discounts index page
var discountsAnalytics = {
    shareTimer: null,
    initAnalytics: function() {
        discountsAnalytics.setShareAnalyticsEvents();
        discountsAnalytics.setViewDetailsPageViewEvent();
    },
    setShareAnalyticsEvents: function () {
        $('.landing_offer_container').each(function(i, sec){
            discountsAnalytics.addShareClickEvent(sec);
        });
    },
    addShareClickEvent: function(sec) {
        var params = {};
        var offerURL = $(sec).find('.offer-cta a').attr('href');
        if ((/\?/).test(offerURL)) {
            var dest = offerURL.split(/\?/);
            params.page = dest[0];
            params.query = dest[1];
        }
        $(sec).find('.landing-offer-sharing a').bind("click", function(e){
            if(discountsAnalytics.shareTimer) clearTimeout(discountsAnalytics.shareTimer);
            VISA.Analytics.addParameters(params);
            discountsAnalytics.shareTimer = setTimeout(function(){VISA.Analytics.removeParameters(params)}, 200);
        });
    },
    setViewDetailsPageViewEvent: function () {
        $('.landing_offer_container .offer-cta a').click(function(e) {
            pageTracker._trackPageview($(this).attr('href'));
        })
    }
};


function buildCategoryURL(categoryId, categoryName) {
    var url = "";

    if(categoryId && categoryName) {
        var tidiedCategoryName = categoryName.replace(/ /g, "").replace(/&/g, "");

        url += sectionPrefix + "/detail/";
        url += tidiedCategoryName;
        url += "/vro_details.jsp";
        url += "?pageId=" + pageId;
        url += "&categoryId=" + categoryId;
        url += "&categoryName=" + tidiedCategoryName;

        if(sectionSuffix) {
            url += sectionSuffix;
        }
    }

    return url;
}

function buildMerchantURL(merchantId, merchantName) {
    var url = "";

    if(merchantId && merchantName) {
        var tidiedMerchantName = merchantName.replace(/ /g, "").replace(/&/g, "");

        url += sectionPrefix + "/detail/";
        url += tidiedMerchantName;
        url += "/vro_details.jsp";
        url += "?pageId=" + pageId;
        url += "&merchantId=" + merchantId;
        url += "&merchantName=" + tidiedMerchantName;

        if(sectionSuffix) {
            url += sectionSuffix;
        }

        $("#detail_offer_more_link:hidden").show();
    }
    else {
        $("#detail_offer_more_link:visible").hide();
    }

    return url;
}

function buildRedeemURL(offerId, offerName, redeemURL) {
    var url = "";

    if(offerId && offerName) {
        var tidiedOfferName = offerName.replace(/ /g, "").replace(/&/g, "");

        url += VISA.base_href;
        url += sectionPrefix + "/detail/";
        url += tidiedOfferName;
        url += "/vro_redeem.jsp";
        url += "?offerId=" + offerId;
        url += "&url=" + redeemURL;

        if(sectionSuffix) {
            url += sectionSuffix;
        }
    }

    return url;
}

function displayDetailOfferTooltip(event, offer) {
    $("#detail_tooltip_text img:visible").hide();
    $(".detail_offer_tooltip:visible").hide();
    $("#detail_tooltip_text:visible").hide();
    // 9.29.2009 by zng: unbind any links event before empty the div.  Used to force analytic with the clicked offer
    $(".detail_share_overlay_bottom a").unbind("click");
    $(".detail_share_overlay_bottom ul").html("");
    $(".detail_share_overlay").hide();
    $("#detail_btnShare").hide();
    $("#tooltip_progress:hidden").show();

    var offerURL = $("a", offer).attr("href");

    $.getJSON(offerURL + "&json=true", function(json) { populateDetailOfferTooltip(json, offerURL); });

    $("#detail_offer_logo img").unbind("load");
    $("#detail_offer_logo img").attr("src", "/img/spacer.gif");
    $("#detail_offer_logo img").load(function() {
		$(this).show();
	});

    $("#detail_offer_logo img").attr("src", offer.parent().find("img").eq(0).attr("src"));

	//carousel detail overlay positioning for IE6
	if ((offer.parent().hasClass('sig_carousel_offers') || offer.parent().parent().hasClass('sig_carousel_offers'))) {
	    //we're in a carousel
	    if (jQuery.browser.msie) {
	        //browser is IE
	        if ((window.XMLHttpRequest == undefined) && (ActiveXObject != undefined)) {
	            //version is IE6
	            varTop = 20;
	            varLeft = 20;
	        }
	        else {
	            varTop = 10;
	            varLeft = 10;
	        }
	    }
	    else {
	        varTop = 10;
	        varLeft = 10;
	    }
	}
	else {
	    varTop = -128;
	    varLeft = -20;
	}    

    $(".detail_offer_tooltip").css({ "left": offer.offset().left + varLeft, "top": offer.offset().top + varTop });

    // Always hide terms and conditions when opening an offer tooltip
    $("#detail_offer_tc:visible").hide();
    $("#detail_offer_tc_link").css("background-image", "none");

    $(".detail_offer_tooltip").show();
    
    $("head").append("<!--[if IE 6]><scr" + "ipt language='JavaScript' type='text/javascript' src='/js/DD_belatedPNG_0.0.7a-min.js'></scr" + "ipt><script>DD_belatedPNG.fix('.div.solid, div.detail_header, div.detail_footer');</scr" + "ipt><![endif]-->");       
	
	// Set up the print link
	$("#detail_offer_printable").html("<a href='" + $("a", offer).attr("href") + "&printable=yes' target='_blank'><img border='0' alt='Printable Page' src='/img/other/printable_page.gif' style='display: inline; cursor: auto;'/></a>");
}

function populateDetailOfferTooltip(json, offerURL) {

    // tracking variable for destination on share
	var randFLS = Math.random() + "";
	var cbFLS = randFLS * 10000000000000;    	
	var params = {};
	var offerName = '';
    var removeTimer;
    if ((/\?/).test(offerURL)) {
        var dest = offerURL.split(/\?/);
        //params.destination = dest[0];
        params.page = dest[0];
        params.query = dest[1];
		if (params.query.indexOf('offerName=') !== -1) {
			offerName = params.query.substring(params.query.indexOf('offerName=') + 10, params.query.indexOf('&offerId='));
			$('body').append('<iframe src="http://fls.doubleclick.net/activityi;src=2592736;type=visad678;cat=visad581;u2=197;u3=' + offerName + ';ord=' + cbFLS + '" height="1" width="1" frameborder="0"></iframe>');
		}
    }
    
    $("#detail_offer_logo img").attr("alt", json.merchantName);
    $("#detail_offer_desc").html(json.shortDescriptionFull);
    $("#detail_offer_related_link a").attr("href", buildCategoryURL(json.categoryId, json.categoryName));
    $("#detail_offer_more_link a").attr("href", buildMerchantURL(json.merchantId, json.merchantName));
    $("#detail_offer_content").html("<p>"+json.longDescriptionFull);
    $("#detail_offer_valid_date").html("Valid from " + json.startDate + " to " + json.endDate);
    
    //display share button - needs to check for variables in json
    
    if(json.share == 'Y') {
    	$("#detail_btnShare").show();
    	$("#detail_btnShare img").show();
    }

    if(json.offerLogo2)
    {
        $("#detail_offer_second_logo img").attr("src", json.offerLogo2);
        $("#detail_offer_second_logo:hidden").show();
        $("#detail_offer_second_logo img:hidden").show();
    }
    else
    {
        $("#detail_offer_second_logo:visible").hide();
    }

    $("#detail_offer_tc ul").html(json.additionalTerm + json.visaterms);

    $("#detail_offer_redeem a").unbind("click");

    if(json.redeemUrl)
    {
        // Setup redeem URL including analytics
        $("#detail_offer_redeem a").attr("href", unescape(json.redeemUrl));
        $("#detail_offer_redeem a").click(function() {
			if (offerName !== '') {
				$('body').append('<iframe src="http://fls.doubleclick.net/activityi;src=2592736;type=visad678;cat=visad778;u2=197;u3=' + offerName + ';ord=' + cbFLS + '" height="1" width="1" frameborder="0"></iframe>');
			}
            var request = $.ajax({ async: false, url: buildRedeemURL(json.id, json.name, json.redeemUrl) });
            var timeout = (new Date()).getTime() + 500;

            while (true) {
                if (request.readyState >= 2) break;
                if ((new Date()).getTime() >= timeout) break;
            }
        });

        $("#detail_offer_redeem:hidden").show();
    }
    else
    {
        $("#detail_offer_redeem:visible").hide();
    }

    $("#detail_offer_printable img:hidden, #detail_offer_closewindow img:hidden, #detail_offer_related_link img:hidden, #detail_offer_more_link img:hidden, #detail_offer_redeem img:hidden").show();
    $("#detail_offer_tc_link").css("background-image", "url('/img/other/sm_arrow_right.gif')");
    $("#tooltip_progress:visible").hide();
    $("#detail_tooltip_text:hidden").show();

	$("#detail_offer_printable img").unbind("hover").hover(function() {
		$(this).css("cursor", "pointer");
    }, function() {
		$(this).css("cursor", "auto");
	});

	/*$("#detail_offer_printable img").unbind("click").click(function() {
		$("body").addClass("print");
		print();
	});*/

	$("#detail_offer_closewindow img").unbind("hover").hover(function() {
		$(this).css("cursor", "pointer");
    }, function() {
		$(this).css("cursor", "auto");
	});
	

	$("#detail_offer_closewindow img").unbind("click").click(function() {
		$(".detail_offer_tooltip").hide();
		$(".dropBenefits").removeClass("hide");
		$("#card").removeClass("hide");
		$(".detail_share_overlay").hide();
	});

	$("#detail_offer_tc_link").unbind("click").click(function() {
        if($("#detail_offer_tc").is(":hidden")) {
            $("#detail_offer_tc").show();
            $(this).css({ "background-image": "url('/img/other/sm_arrow_down.gif')", "padding-bottom": "10px" });
        } else {
            $("#detail_offer_tc").hide();
            $(this).css({ "background-image": "url('/img/other/sm_arrow_right.gif')", "padding-bottom": "0" });
        }
	});

	$("#detail_offer_tc_link").unbind("hover").hover(function() {
		$(this).css({ "cursor": "pointer", "text-decoration": "underline" });
    }, function() {
		$(this).css({ "cursor": "auto", "text-decoration": "none" });
	});
	
	
	$("#detail_btnShare img").unbind("hover").hover(function() {
		$(this).attr("src", "/img/other/btn-share-over.gif");
		$(this).css("cursor", "pointer");
    	}, function() {
    		$(this).attr("src", "/img/other/btn-share.gif");
    		$(this).css("cursor", "auto");
	});
	
	$("#detail_btnShare img").unbind("click").click(function(e) {
		var panelOffset = $("#detail_btnShare").offset();
		$(".detail_share_overlay").css({ "left": panelOffset.left - 48, "top": panelOffset.top + 5, "width": "115px" });
		$(".detail_share_overlay").show();
		
        //force tracking to use offer URL param.  Remove after tracking is done otherwise it will be wrong on the whole page
        VISA.Analytics.addParameters(params);
        removeTimer = setTimeout(function(){VISA.Analytics.removeParameters(params)}, 200);
        
		e.preventDefault();
	});
	
	
	if(json.email) {
		emailLink = "/vro/templates/email_form.jsp?id=" + json.id + "&email=" + json.email;
		//console.log("Email: " + emailLink);
		$("<li><a id='share_email' href=\"javascript:pop_email(emailLink);\"></a></li>").appendTo(".detail_share_overlay_bottom ul");
	}
	
	if(json.facebook) {
		facebookLink = json.facebook;
		//console.log("Facebook: " + facebookLink);
		$("<li><a id='share_facebook' href=\"javascript:pop_facebook(facebookLink);\" class='facebook'></a></li>").appendTo(".detail_share_overlay_bottom ul");
	}
	
	/*if (json.myspace) {
		myspaceLink = json.myspace;
		$("<li><a id='share_myspace' href=" + myspaceLink +  " class='myspace' target='_blank'>MySpace</a></li>").appendTo(".detail_share_overlay_bottom ul");
	}*/
	
	if (json.twitter) {
		twitterLink = json.twitter;
		//console.log("Twitter: " + twitterLink);
		$("<li><a id='share_twitter' href=" + twitterLink +  " class='twitter' target='_blank'></a></li>").appendTo(".detail_share_overlay_bottom ul");
	}
	
	/*if(json.bebo) {
		beboLink = json.bebo;
		$("<li><a id='share_bebo' href=\"javascript:pop_bebo(beboLink);\" class='bebo'>Bebo</a></li>").appendTo(".detail_share_overlay_bottom ul");
	}*/	
	
	
	$(".detail_share_overlay_top").unbind("hover").hover(function() {
		$(this).css("cursor", "pointer");

    	}, function() {
    		$(this).css("cursor", "auto");
   		
	});	
	
	$(".detail_share_overlay_top").unbind("click").click(function(e) {
		$(".detail_share_overlay").hide();
		e.preventDefault();
	});
	
    // add click event listern to shars links so taht we can track analytics on offer id
    $('.detail_share_overlay_bottom a').bind("click", function(e){
        if(removeTimer) clearTimeout(removeTimer);
        VISA.Analytics.addParameters(params);
        removeTimer = setTimeout(function(){VISA.Analytics.removeParameters(params)}, 200);
    });	
	
}

function checkAllMerchants() {
	if(!allMerchantsReady) {
		if(typeof(merchantListAD) == "undefined") {
			window.setTimeout(checkAllMerchants, 1000);
		} else {
			allMerchantsReady = true;
			//setupAllMerchants();
			setupMDMerchants();
		}
	}
}

function setupMDMerchants() {
    $('#md_nav .open').next('ul').addClass('open');
    $('#md_nav ul li div.header').click(function () {
        
        var checkHeader = $(this).next();

        if ((checkHeader.is('ul')) && (checkHeader.is(':visible'))) {
            return false;
        }
        if ((checkHeader.is('ul')) && (!checkHeader.is(':visible'))) {
            $('#md_nav ul li div.header').removeClass('open').removeClass('closed');
            $('#md_nav ul li ul:visible').slideToggle(300).toggleClass('open');
            checkHeader.slideToggle(300).toggleClass('open');
            $(this).addClass('open');
            // if there is sub section, open it
            var $sub = $(checkHeader).find('.sub-header');
            if($sub.length > 0) {
                $($sub[0]).click();
            }
            return false;
        }
    });
    
    $('#md_nav .sub-header').click(function () {

		var checkHeader = $(this).next();
        if ((checkHeader.is('ul')) && (checkHeader.is(':visible'))) {
            return false;
        }
        if ((checkHeader.is('ul')) && (!checkHeader.is(':visible'))) {
            $('#md_nav ul li ul li ul:visible').slideToggle(300).toggleClass('open');
            checkHeader.slideToggle(300).toggleClass('open');
            return false;
        }
    });
    

    for (var i = 0; i < Math.round(merchantListAD.length); i++) {
        $("#all_merchants_a-d").append('<li><a href="' + buildMerchantURL(merchantListAD[i].id, merchantListAD[i].name) + '">' + merchantListAD[i].name + '</a></li>');
    }

    for (var i = 0; i < Math.round(merchantListEH.length); i++) {
        $("#all_merchants_e-h").append('<li><a href="' + buildMerchantURL(merchantListEH[i].id, merchantListEH[i].name) + '">' + merchantListEH[i].name + '</a></li>');
    }

    for (var i = 0; i < Math.round(merchantListIR.length); i++) {
        $("#all_merchants_i-r").append('<li><a href="' + buildMerchantURL(merchantListIR[i].id, merchantListIR[i].name) + '">' + merchantListIR[i].name + '</a></li>');
    }

    for (var i = 0; i < Math.round(merchantListSZ.length); i++) {
        $("#all_merchants_s-z").append('<li><a href="' + buildMerchantURL(merchantListSZ[i].id, merchantListSZ[i].name) + '">' + merchantListSZ[i].name + '</a></li>');
    }
}



// added for printable Offer pages 10/19/07
// modified initOfferPrintable 09/08/09

function initOfferPrintable(){
	var params = location.search;

	if (params.indexOf("printable=yes") != -1) {
		var nParams = "";
		if (params.indexOf("it=") != -1)  {
			nParams = ( params.substring(0,(params.indexOf("it=")-1)) );
		} else {
			nParams = (params.substring(0,(params.indexOf("printable=yes")-1)));
		}
		document.getElementById("footerPrintableLink").innerHTML = "<p>Find this page at: http://usa.visa.com" + location.pathname + nParams + "</p>";
		document.getElementById("footerPrintControls").innerHTML = document.getElementById("printControls").innerHTML;
	}
}

function printOffer(){
	var offerPrint = document.getElementById("emailprintModule");
	if (!offerPrint) return false;
	var wherepage = window.location.href;
	if (wherepage.match(/espanol/i))return false;
	else{offerPrint.innerHTML ="<ul><li class='printIcon'><a href='" +wherepage+ "&printable=yes' target='_blank'>Printable page</a></li></ul>";}
}

//popup email form
function pop_email(url) {
	var newwindow=window.open(url,'name','height=550, width=650, scrollbars=1');
	if (window.focus) {newwindow.focus()}
}

//popup facebook form
function pop_facebook(url) {
	var newwindow=window.open(url,'name','height=768,width=1024');
	if (window.focus) {newwindow.focus()}
}

//popup bebo form
function pop_bebo(url) {
	var newwindow=window.open(url,'name','height=768,width=1024');
	if (window.focus) {newwindow.focus()}
}

$.preloadImages = function() {
	for(var i = 0; i<arguments.length; i++) {
		$("<img>").attr("src", arguments[i]);
	}
};

function init() {
	initOfferPrintable();
	printOffer();
}

// copy coupon code to clipboard
function couponCopy() {
	var tooltipTimeout;
	$("body").append("<div id='tooltipWrapper'><div id='tooltipTop'></div><div id='tooltipContent'></div><div id='tooltipBot'></div></div>");
	function clearTooltips(){
        $('#tooltipWrapper').hide();
        $('#tooltipContent, #tooltipContent').empty();	
	}

	if($.browser.flash) {
		$('.coupon-code-cta').each(function() {
			var clip = new ZeroClipboard.Client(); // create new clipboard client
			var	clipText = $(this).text(); // text to be copied
			var	clipButton = $(this);

			clip.glue(clipButton[0]);
			clip.setText( clipText );

			//clip.addEventListener( 'onMouseOver', couponMouseOver );
			clip.addEventListener( 'onMouseOut', couponMouseOut );
			clip.addEventListener( 'complete', couponCopied );

			/*function couponMouseOver() {
				clearTimeout(tooltipTimeout);
				clearTooltips();
				var here = $(this).parent();
				var offset = clipButton.offset();
				console.log(offset);
				$('#tooltipContent').append('Click to copy');
				$('#tooltipWrapper').show();
				$('#tooltipWrapper').bgiframe();
				var contentHeight = $('#tooltipContent').height() + 27;
				$('#tooltipWrapper').css({'top' : offset.top-contentHeight, 'left' : offset.left});
			}*/
		
			function couponMouseOut() {
				/*$('#tooltipWrapper').hide();
				$('#tooltipContent').empty();*/
				 function hideTooltip(){$('#tooltipWrapper').hide();$('#tooltipContent').empty();}
				 tooltipTimeout = setTimeout(hideTooltip,350);
			}
		
			$(this).parent().hover(function() {
				clearTimeout(tooltipTimeout);
				clearTooltips();
				var here = $(this).parent();
				var offset = clipButton.offset();
				$('#tooltipContent').append('Click to copy');
				$('#tooltipWrapper').show();
				$('#tooltipWrapper').bgiframe();
				var contentHeight = $('#tooltipContent').height() + 27;
				$('#tooltipWrapper').css({'top' : offset.top-contentHeight, 'left' : offset.left});

			}, function() {
				function hideTooltip(){$('#tooltipWrapper').hide();$('#tooltipContent').empty();}
				 tooltipTimeout = setTimeout(hideTooltip,350);
			});
		
			function couponCopied() {
				clearTooltips();
				var here = $(this).parent();
				var offset = clipButton.offset();
				$('#tooltipContent').append('Copied!');
				$('#tooltipWrapper').show();
				$('#tooltipWrapper').bgiframe();
				var contentHeight = $('#tooltipContent').height() + 27;
				$('#tooltipWrapper').css({'top' : offset.top-contentHeight, 'left' : offset.left});
			}
		});
	} else {
		$('.coupon-code-container, .coupon-code-cta').css('cursor', 'default');
	}
}


function merchantSlider() {
	$('.more-cta').live('click',function() {
		if ( $('.hidden-features.first').is(':hidden') ) { 
			$('.hidden-features.first').slideDown(1000);
			//couponCopy();
		} else if ( $('.hidden-features.second').is(':hidden') ){
			$('.hidden-features.second').slideDown(1000);
			//couponCopy();
			$('.featured-bottom').hide();	
		}
	});  
}

window.onload = init;
