/** age verification functions and variables */
var cookieName = 'csm.age_verification';

function checkCookie() {
	return $.cookie(cookieName);
}


function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}


function passValidation(checked) {
	if (checked != false) {
		// They checked the box; the cookie is set for 30 days
		$.cookie(cookieName,true, { expires: 30,path: '/', domain: 'ste-michelle.com' });
	} else {
		$.cookie(cookieName,true,{path: '/', domain: 'ste-michelle.com'});
	}
	
	var ver = getInternetExplorerVersion();

	if ( ver > -1 ) {
		// or, force a reload of the page to enable Flash (if necessary)
		location.reload(true);
	} else {
		// get rid of the modal and they're on their way:
		$.closeDOMWindow();
	}

}

function displayVerification() {

	$.openDOMWindow({ 
			borderSize: 0,
			overlayColor: '#261C16',
			overlayOpacity:'75',
			draggable: 0,
			modal: 1,
			width: 450,
			height: 387,
			loader:1,
			modal:1, 
			loaderImagePath:'/img/verify/spinner.gif', 
			loaderHeight:16, 
			loaderWidth:17, 
			windowSource:'iframe',
			windowPadding:0,
			windowSourceURL: '/verify/' 
		});

}

$(document).ready(function(){
	
	$("#leftCol").css("background","none");
	
	// if there is no cookie put up the age verification modal
	if(!checkCookie(cookieName)) {
		displayVerification();
	}

});
