// Remove this
function openInNewTab ( url ) {
	window.open( url );
}

// Insert flash with SWFObject
var flashvars = {};
var params = {
	menu: "false",
	scale: "noScale",
	allowFullscreen: "true",
	allowScriptAccess: "always",
	bgcolor: "#f9f9f9",
	wmode: "opaque"
};
var attributes = {
	id:"coin"
};
swfobject.embedSWF("coin.swf", "altContent", "100%", "100%", "10.0.0", null, flashvars, params, attributes);




$(function(){
	// Setting content position from grid of coins
	var gridCeilSize = 41;
	var $body = $("body");
	var $content = $("#body");
	function resizeWindow () {
		$content.
			css({
				left: Math.round($body.width()/2 - $content.width()/2)
			}).
			css({
				left:  Math.floor($content.offset().left / gridCeilSize) * gridCeilSize - 2
			});
	}
	resizeWindow ();
	$(window).resize(resizeWindow);

	// Changing flash quality, if window isn’t active
	// IE is bluring window even when user clicked on Flash
	if ( !/msie/i.test(navigator.userAgent.toLowerCase()) ) {
		$(window).
			focus(function(){
				try {
					$("#coin").get(0).DEactivateMovie ("off");
				}catch(e){}
			}).
			blur(function(){
				try {
					$("#coin").get(0).DEactivateMovie ("on");
				}catch(e){}
			});
	}

	

	var $closeContent = $("#content .close:eq(0)");

	function showPopup ( $popup ) {
		hidePopup( $(".popup").not($popup) );
		
		$closeContent.fadeOut(700);
		var $embed = $popup.find("embed").hide();
		$popup.slideDown(700, function(){
			$embed.show();
		});
	}
	function hidePopup ( $popup ) {
		$closeContent.fadeIn(700);
		var $embed = $popup.find("embed").hide();
		$popup.slideUp(700, function(){
			$embed.show();
		});
	}

	$(".popup .close").click(function(){
		hidePopup( $(this).closest(".popup") );
	});

	$("#want-more").click(function(){
		showPopup( $("#popup-want-more") );
		return false;
	});
	$("#faq").click(function(){
		showPopup( $("#popup-faq") );
		return false;
	});
	$("#video-instruction").click(function(){
		showPopup( $("#popup-video") );
		return false;
	});


	// Collapsing content to a coin
	var contentWidth = $("#body").width();
	var contentHeight = $("#body").height();
	$closeContent.click(function(){

		$("#bg").animate({
			height:0,
			width:0,
			left:"100%",
			opacity:0
		}, 700, function(){
			$(this).css({
				display: "none"
			});
		});
		$("#body").animate({
			width:"41px",
			height:"41px",
			marginLeft: contentWidth-41
		});
		$("#sibset-coin").fadeIn(700);
	});
	$("#sibset-coin").click(function(){
		$("#bg").animate({
			height:"100%",
			width:"100%",
			left:0,
			opacity:1
		}, 700);
		$("#sibset-coin").fadeOut(700);
		$("#body").animate({
			width:contentWidth,
			height:contentHeight,
			marginLeft: 0
		})
	});

});

Cufon.replace('.neoSans');

