/*global $, window 
*/

(function() {

$(document).ready(function() {

	var click_to_show, click_to_hide;
	var marketo_url = $("#marketo_callback_form").attr("href");
	
	click_to_show = function() {
		$("#marketo_callback_form").unbind("click.marketo");
		
		$("#marketo_callback_form").bind("click.marketo", click_to_hide);
		
		$(document).bind("click.marketo_body", function() {
			$("#marketo_callback_form").unbind("click.marketo");
			$("#marketo_callback_form").bind("click.marketo", click_to_show);
			$(document).unbind("click.marketo_body");
			$("#marketo_callback_placeholder").empty();
		});
		
		$("#marketo_callback_placeholder").append(
			'<iframe src="' + marketo_url + '"  frameborder="0" class="callBackFrame" scrolling="no" allowtransparency="allowtransparency"></iframe>'
		);
		return false;
	};

	click_to_hide = function() {
		$("#marketo_callback_placeholder").empty();
		$("#marketo_callback_form").unbind("click.marketo");
		$("#marketo_callback_form").bind("click.marketo", click_to_show);
		return false;
	};

	$("#marketo_callback_form").bind("click.marketo", click_to_show);
});

})();

