var isMobile = navigator.userAgent.toLowerCase().indexOf("mobile") != -1 ? true : false;

/*****************************/
paddingTop = 0;
difference = 0;
layout_height = $("body").attr("clientHeight"); // initial constant, the true height of the content at page load.
function verticalCentering() {
	viewable_height = $("html").attr("clientHeight"); // should be checked every page resize
	if (viewable_height > layout_height) { // if our layout is smaller than the window
		difference = Math.floor((viewable_height - layout_height) / 2); // split the difference
	}
	$("body").css("padding-top",difference); // and pad the top
};

if (!$("body.popup").length && !isMobile) {
	verticalCentering(); // page load fire
	$(window).resize(function(){
		verticalCentering(); // resize fire
	});
}
/*****************************/

// Display an external page using an iframe
if (!$("body.popup").length && !isMobile) {
	$(".modal").click(function(){ // links intended for modal display need the modal class
		$('<iframe src="' + $(this).attr("href") + '" style="height:550px; width:830px; border:0px;" frameBorder="0">').modal({

			opacity:66,
			overlayCss: {
				backgroundColor:"#000"
			},
			overlayClose:true,

			containerCss:{
				backgroundColor:"#fff",
				height:"550px",
				width:"830px",
				padding:0,
				margin:0,
				border:0
			},

			onOpen: function (dialog) {
				dialog.data.show();
				dialog.overlay.fadeIn("slow",function () {
					dialog.container.slideDown("slow");
				});
			},

			onClose: function (dialog) {
				dialog.container.slideUp("fast",function(){
					dialog.overlay.fadeOut("fast",function(){
						$.modal.close();
					});
				});
			}

		});
		return false;
	});
}



$("#dState").change(function(){ 
	if (!$("body.popup").length && !isMobile) {
		$('<iframe src="found.php?dState=' + $(this).val() + '" style="height:550px; width:830px; border:0px;" frameBorder="0">').modal({

			opacity:66,
			overlayCss: {
				backgroundColor:"#000"
			},
			overlayClose:true,

			containerCss:{
				backgroundColor:"#fff",
				height:"550px",
				width:"830px",
				padding:0,
				margin:0,
				border:0
			},

			onOpen: function (dialog) {
				dialog.data.show();
				dialog.overlay.fadeIn("slow",function () {
					dialog.container.slideDown("slow");
				});
			},

			onClose: function (dialog) {
				dialog.container.slideUp("fast",function(){
					dialog.overlay.fadeOut("fast",function(){
						$.modal.close();
					});
				});
			}

		});
		return false;
	} else {
		$(window).attr("location",'found.php?dState=' + $(this).val());
	}
});

