﻿// Closure protects my local variables
(function(){
	var clickThroughLink;
    YAHOO.util.Event.onAvailable("buy",init);
	function clickThrough (e) {
		clickThroughLink = this.href;
		YAHOO.util.Dom.addClass("buy-pop-up","active");
		YAHOO.util.Event.stopEvent(e);
	}
	function addPopUpEvents (e) {
		YAHOO.util.Event.on(this.document.getElementById("go_back"),"click",closeMe);
		YAHOO.util.Event.on(this.document.getElementById("leave"),"click",leavePage);
	}
	function leavePage (e) {
		window.location = clickThroughLink;
		closeMe(e);
	}
	function closeMe (e) {
		YAHOO.util.Dom.removeClass("buy-pop-up","active");
		YAHOO.util.Event.stopEvent(e);
        clickThroughLink = null;
	}
    function init(e) {
		var links = this.getElementsByTagName("a");
		YAHOO.util.Event.on(links,"click",clickThrough);
        var div = document.getElementById('buy-pop-up');
        YAHOO.util.Event.on(document.getElementById("go_back"),"click",closeMe);
		YAHOO.util.Event.on(document.getElementById("leave"),"click",leavePage);

    }
})();
