/* --------------- UNAVAILABLE-OUTSIDE-USDM PRODUCT MODAL -------
 * 
 * The site will bounce back to the US version if a product (only available
 * USDM) has its page toggled to a market in which it is not available.
 * This code controls a pop-up notifying the user that the product is not
 * available in whatever language they're trying to view it in.
 *
 */

 function getParameterByName( name ) {		// grabs URL query string params
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null )
		return "";
	else
		return decodeURIComponent(results[1].replace(/\+/g, " "));
}

var countryCode	= getParameterByName( "notIn" );
var missingCAeng = "The product you've requested is not available in Canada.";
var missingCAfr = "The product you've requested is not available in Canada.";
var missingFallback = "The product you've requested is not available.";

var content		= "<div class = \"modal alert\"><h2>Product Not Available</h2><p>" + ( countryCode == "ca,eng" ? missingCAeng : countryCode == "ca,fr" ? missingCAfr : missingFallback ) + "</p><p style = \"text-align:center;\"><a href = \"#\" class = \"close\">OK</a></p></a>";

$(document).ready(function() {
	if( getParameterByName("notIn") ) {
		$("body").append(content);
		content = $(".modal");
		$(content).overlay({

			// custom top position
			top: 260,

			// some mask tweaks suitable for facebox-looking dialogs
			mask: {
				// you might also consider a "transparent" color for the mask
				color: '#ffffff',
				// load mask a little faster
				loadSpeed: 500,
				// very transparent
				opacity: 0.5
			},

			// disable this for modal dialog-type of overlays
			closeOnClick: false,
			// load it immediately after the construction
			load: true

		});
	};
 
});
