var _dashboard_ads = new Array();

var _videoX = 456;
var _videoY = 259;
var _counterX = 0;
var _counterY = 0;
var _newsletter_visible = false;
var _counter_visible = false;
var _enableAnimations = false;
var _temp_main_content = '';
var _loggedIn = false;
var _expoView = true;
var _disableHistoryLoad = false;
var _newsLetterX = 0;
var _newsLetterY = 0;

//jQuery.fx.off = true;


$(document).ready(function() {	

	embedFlash();
	
	var x = $('#newsletter_signup').css('left');
	var y = $('#newsletter_signup').css('top');
	_newsLetterX = x.substr(0,x.length-2); //remove "px"
	_newsLetterY = y.substr(0,y.length-2); //remove "px"
	_newsletter_visible = $('#newsletter_signup').css('display')!='none';
	$('#newsletter_signup').hide();
	
	x = $('#visitor_count').css('left');
	y = $('#visitor_count').css('top');
	_counterX = x.substr(0,x.length-2); //remove "px"
	_counterY = y.substr(0,y.length-2); //remove "px"
	_counter_visible = $('#visitor_count').css('display')!='none';
	$('#visitor_count').hide();
	
	centerGateItems();

});

$(window).resize(function() {
	centerVideo();
	centerGateItems();
});

//History.js
(function(window,undefined){

    // Prepare
    var History = window.History; // Note: We are using a capital H instead of a lower h
    if ( !History.enabled ) {
         // History.js is disabled for this browser.
         // This is because we can optionally choose to support HTML4 browsers or not.
		 alert('History Disabled');
        return false;
    }

    // Bind to StateChange Event
    History.Adapter.bind(window,'statechange',function(){ // Note: We are using statechange instead of popstate
		if (_disableHistoryLoad) {
			_disableHistoryLoad = false;
			return;
		}
        var State = History.getState(); // Note: We are using History.getState() instead of event.state
		//alert(State.data.id);
		//alert('History loadpage call '+State.data.client_id+' | '+State.data.id+' | '+State.data.type);
		if(State.data.id==undefined) {
			return;
		}
		if(State.data.id=='expo') {
			hideShowcase();
			thisMovie("expo").callGotoBooth(State.data.client_id);
		} else if(State.data.id!=-1) {
			if(_expoView==true) {
				_expoView=false;
				$("#showcase").show();
				hideFlash();
				thisMovie("expo").hideFlash();
			}
			if(_loggedIn==true) {
				_loggedIn = false;
				
				$('#main_area').html(_temp_main_content);
			}
			loadPage(State.data.client_id,State.data.id,State.data.type);
			
		} else if (State.data.type=='dashboard') {
			if(_expoView==true) {
				_expoView=false;
				$("#showcase").show();
				hideFlash();
				thisMovie("expo").hideFlash();
			}
			_loggedIn = true;
			setupDashboard();
		}
        //History.log(State.data, State.title, State.url);
    });

})(window);

function centerGateItems() {
	var posX = Math.round($(window).width()/2);
	posX = posX+Math.ceil(_newsLetterX)-630;
	$('#newsletter_signup').css('left',posX+"px");
	$('#newsletter_signup').css('top',Math.ceil(_newsLetterY)+"px");
	
	posX = Math.round($(window).width()/2);
	posX = posX+Math.ceil(_counterX)-630;
	$('#visitor_count').css('left',posX+"px");
	$('#visitor_count').css('top',Math.ceil(_counterY)+"px");
}


<!--Start AliveChat Live Site Monitor Code-->
function wsa_include_js(){
	var wsa_host = (("https:" == document.location.protocol) ? "https://" : "http://");
	var js = document.createElement('script');
	js.setAttribute('language', 'javascript');
	js.setAttribute('type', 'text/javascript');
	js.setAttribute('src',wsa_host + 'a1.websitealive.com/3496/Visitor/vTracker_v2.asp?websiteid=0&groupid=3496');
	document.getElementsByTagName('head').item(0).appendChild(js);
}
if (window.attachEvent) {window.attachEvent('onload', wsa_include_js);}
else if (window.addEventListener) {window.addEventListener('load', wsa_include_js, false);}
else {document.addEventListener('load', wsa_include_js, false);}
<!--End AliveChat Live Site Monitor Code-->


function loadGallery() {
	$('#photos').galleryView({
		panel_width: 460,
		panel_height: 600,
		frame_width: 100,
		frame_height: 100,
		filmstrip_position: 'right'
	});
}

function loadShowcase(pId){ 
	//alert('loadShowcase '+pId);
	$.get("client_page.php", {id : pId, headers : 0}, function(data){
		if (data.length>0){ 
			
			$("#showcase").html(data);
			$("#home_btn").click(
				function(event){
					event.preventDefault();
					hideShowcase();
				}
			);
		} 
	}) 

	hideFlash();
	loadGallery();
}

function initClientPage(pClientId,pClientName,pClientURL) {	
		//alert('initClientPage '+pClientId+" | "+pClientName+" | "+pClientURL);
		_expoView = false;
		_client_id = pClientId;
		//alert(pClientName);
		loadBanner();
		//loadPage("all","article");
		var title = _baseTitle;
		
		if(_loadShowcaseFirst==false) {
			if (pClientName!='') {
				title = pClientName+' | '+title;
			}
			// can't remember why this was necessary but it was causing problems so i commented it out - 1/26/12
			//_disableHistoryLoad = true; //prevents history state change from loading page twice
			History.pushState({id:'all',type:'default',client_id:pClientId}, title, pClientURL);
		}
		
		$('.nav_btn_bg').click( function(event){
			
			var href = event.target.getAttribute("href",2);
			var target = event.target.getAttribute("target");
			var page_id=this.id.toString;
			
			var title = _baseTitle;
			if (this.innerHTML!='') {
				title = this.innerHTML+' | '+title;
			}
			if (pClientName!='') {
				title = pClientName+' | '+title;
			}
			if (href.substr(0,7) == "http://" && (href.indexOf(_baseUrl)==-1 || target=='_blank' ) ) {
				//do nothing
				//alert('1');
				return;
			} else if (href=="#") {
				event.preventDefault();
				History.pushState({id:this.id,type:this.type,client_id:pClientId}, title, href);
			} else {
				if(href.indexOf('http://'+_baseUrl)==0) {
					href = href.substr(_baseUrl.length+7,999);
				}
				event.preventDefault();
				//alert('pushState '+this.id);
				History.pushState({id:this.id,type:this.type,client_id:pClientId}, title, href);
			}
			
		});
		
		$('.nav_btn_bg').hover(function() {
			if(this.style.backgroundImage != 'url("../_assets/button_selected.png")') {
			  this.style.backgroundImage = "url(../_assets/button_hover.png)";
			}
		}, 
		function() {
			if(this.style.backgroundImage != 'url("../_assets/button_selected.png")') {
			  this.style.backgroundImage = "url(../_assets/button.png)";
			}
		})
		
		$("#home_btn").click(
			function(event){
				event.preventDefault();
				hideShowcase();
			}
		);

		$('#dashboard').click(function(event) {
			event.preventDefault();
			
			_temp_main_content = $('#main_area').html();
			
			$.get("dashboard-login.html", {} , function(data){
				if (data.length>0){ 

					$('#page_content').html(data);

					$('#dashboard-password input#dashboard-login').click(function(event) {
						if($('#dashboard-password input#password').attr('value')=='doctor') {
							_loggedIn = true;
							History.pushState({id:-1,type:'dashboard',client_id:_client_id}, ' Dashboard | '+_baseTitle, pClientURL+'/Dashboard');
							setupDashboard();

						} else {
							alert('Unknown password. Please try again.');
						}
						event.preventDefault();
					});
					
					window.scrollTo(0,250);
				} 
			})
			
			

		});
		
		$('#photos').galleryView({
			panel_width: 460,
			panel_height: 600,
			frame_width: 100,
			frame_height: 100,
			filmstrip_position: 'right',
			transition_interval: 99999999,
			panel_scale:'crop'
		});

}

function loadPage(pClientId,pPageId,pType){
	//alert('loadPage '+pClientId+" | "+pPageId+" | "+pType);
	$('.nav_btn_bg').css('background-image', "url(../_assets/button.png)");
	$('#'+pPageId+'.nav_btn_bg').css('background-image', "url(../_assets/button_selected.png)");

	if (pType=='photoGallery') {
		$.get("client_page_content.php", {page_id : pPageId, client_id : pClientId, type : pType, ajax : 1}, function(data){		
			if (data.length>0){ 
				$("#page_content").html(data);
				$('#page_content').find('#photos').galleryView({
					panel_width: 460,
					panel_height: 600,
					frame_width: 100,
					frame_height: 100,
					filmstrip_position: 'right',
					transition_interval: 99999999,
					panel_scale:'crop'
				});
			} 
		})
	} else if (pType=='videoGallery') {
		loadFlash("videoGallery.swf",pPageId);
	} else if (pType=='mediaSingle') {
		loadFlash("mediaSingle.swf",pPageId);
	} else {
		
		$.get("client_page_content.php", {page_id : pPageId, client_id : pClientId, type : pType, ajax : 1}, function(data){
			if (data.length>0){ 
				//$("#page_content").empty();
				//$("#page_content").append(data); 
				$("#page_content").html(data);

			} 
		})


	}

} 

function hideShowcase(){ 
	if(_expoView==false) {
		_expoView=true;
		if (_enableAnimations) {
			$('#main_content').animate({
				height: '640'
			}, 2000, function() {
				// Animation complete. 
				$("#showcase").hide();
			});
		} else {
			$('#main_content').css('height','640');
			$("#showcase").hide();
		}
		
		//$('#showcase').slideUp();
		//alert("hideShowCase");
		thisMovie("expo").backToExpo();
	}
} 


function onBoothIntro(pBoothId,pClientName,pClientURL) {
	//alert("booth intro "+pBoothId+"|"+pClientName+"|"+pClientURL);
	History.pushState({id:'expo',type:'expo',client_id:pBoothId}, pClientName+' | '+_baseTitle, pClientURL);
	
}

function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}

function hideFlash() {
	$('#showcase').slideDown();
	
	if (_enableAnimations) {
		$('#main_content').animate({
			height: '60'
		}, 2000, function() {
			//on complete
		});
	} else {
		$('#main_content').css('height','60');
	}
}

function onFlashInit() {
	if (_newsletter_visible) {
		$('#newsletter_signup').show();
	}
	if (_counter_visible) {
		$('#visitor_count').show();
	}
}



function onEnter(){
	$('#newsletter_signup').hide();
	$('#visitor_count').hide();
	$("#showcase").empty();
}

function playVzaar(pId,pX,pY) {

	if(pId!=''){
		var html = '<div class="vzaar_media_player"><object id="video" width="195" height="144" type="application/x-shockwave-flash" data="http://view.vzaar.com/'+pId+'.flashplayer"><param name="movie" value="http://view.vzaar.com/'+pId+'.flashplayer"><param name="allowScriptAccess" value="always"><param name="allowFullScreen" value="true"><param name="wmode" value="transparent"><param name="flashvars" value="autoplay=true&amp;border=none"><embed src="http://view.vzaar.com/'+pId+'.flashplayer" type="application/x-shockwave-flash" wmode="transparent" width="195" height="144" allowScriptAccess="always" allowFullScreen="true" flashvars="autoplay=true&amp;border=none"><video width="195" height="144" src="http://view.vzaar.com/'+pId+'.mobile" poster="http://view.vzaar.com/'+pId+'.image" controls onclick="this.play()"></video></object></div>';

		_videoX = Math.round(pX);
		_videoY = Math.round(pY);
		
		$('#video_overlay').css('display','inline');
		$('#video_overlay').html(html);
		showVideo();
		centerVideo();
		
	} else {
		
		$('#video_overlay').css('display','none');
		if(BrowserDetect.browser == 'Opera' || (BrowserDetect.browser == 'Firefox' && BrowserDetect.OS == 'Mac')) {
			$('#video_overlay').html('<div></div>');
			$('#video_overlay').empty();
		} else {
			$("#embed_iframe").attr("src","");
		}
	}
}

function playVideoEmbedCode(pEmbedCode,pX,pY) {
	if(pEmbedCode!=''){
		_videoX = Math.round(pX);
		_videoY = Math.round(pY);
		
		$('#video_overlay').css('display','inline');
		$('#video_overlay').html(pEmbedCode);
		
		showVideo();
		centerVideo();
		
	} else {
		
		$('#video_overlay').css('display','none');
		if(BrowserDetect.browser == 'Opera' || (BrowserDetect.browser == 'Firefox' && BrowserDetect.OS == 'Mac')) {
			$('#video_overlay').html('<div></div>');
			$('#video_overlay').empty();
		} else {
			$("#embed_iframe").attr("src","");
		}
	}
}

function playVideoEmbed(pEmbedId,pX,pY) {
	if(pEmbedId!=''){
		_videoX = Math.round(pX);
		_videoY = Math.round(pY);
		
		$('#video_overlay').css('display','inline');
		$('#video_overlay').html('<iframe id="embed_iframe" name="embed_iframe" src="http://www.iplayerhd.com/playerframe/progressive/'+pEmbedId+'.aspx?autostart=true&width=195&height=145&cbartype=none" width="195" height="145" frameborder="no" scrolling="no"></iframe>');

		showVideo();
		centerVideo();
		
	} else {
		
		$('#video_overlay').css('display','none');
		if(BrowserDetect.browser == 'Opera' || (BrowserDetect.browser == 'Firefox' && BrowserDetect.OS == 'Mac')) {
			$('#video_overlay').html('<div></div>');
			$('#video_overlay').empty();
		} else {
			$("#embed_iframe").attr("src","");
		}
	}
}

function hideVideo(){
	$('#video_overlay').css('z-index','-10');
}

function showVideo(){
	$('#video_overlay').css('z-index','100');
}

function centerVideo() {
	$('#video_overlay').css('left',Math.round($(window).width()/2)+_videoX-641);
	$('#video_overlay').css('top',_videoY);
}

function checkIEVersion() {
	var msg = "You're not using Windows Internet Explorer.";
	var ver = getInternetExplorerVersion();
	if ( ver == 6.0 ) {
		msg = "You're using an old version of Internet Explorer. Some features of this website may not work correctly.  We recommend that you upgrade to the latest version of Internet Explorer at www.microsoft.com/downloads or switch to FireFox at www.mozilla.com";
		alert( msg );
	}
}

function getInternetExplorerVersion() {
// Returns the version of Windows 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;
}

var BrowserDetect = {
	init: function () {
		this.agentString = navigator.userAgent;
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

