/* Markus Design Group : markusdesigngroup.com : 2010 */
//Google Analytics start
var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-6124957-2']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })(); 
//Google Analytics end
var hs_portalid = 54067; var hs_salog_version = '2.00'; var hs_ppa = 'intellisoftgroup.app5.hubspot.com'; //HubSpot Analytics (call w/in "footer")
var ITG = {}; //IntelliSoft Group namespace

ITG.page = function() {
	
	var _info = {};	//ssl: encryption (boolean); host: hostname (string); port: port (string); path: pathname (string); patharray: pathname (array);
					//querystring: query (string); query: query (object); referrer: referring url (string); live: live server (boolean);
					//template: "page" & "footbody" CSS class ('default' || 'topper' || 'banner' || 'nolnav' || 'toprnolnav');
					//type: content type ('default' || 'gallery' || 'popups' || 'hubform' || 'gcse')
	
	var onInit = function() {
		loadInfo();
		
		ITG.utils.loadJSFile('/includes/js/site.js');
		ITG.utils.loadJSFile('/includes/js/display.js');
		ITG.utils.loadJSFile('/includes/js/forms.js');
		if(_info.type == 'gallery') {ITG.utils.loadJSFile('/includes/js/gallery.js');}
		
		loadOPCs();
	}
	
	var onLoad = function() { //window.onload
		ITG.display.onLoad();
		ITG.forms.onLoad();
		
		switch(_info.type) {
			case 'gallery':
				ITG.gallery.onLoad(); break;
			case 'gcse': //Google CSE
				ITG.utils.loadJSFile('http://www.google.com/afsonline/show_afs_search.js', true, 'content'); break;
			default: break;
		}
		
		//ShareThis
		var objShare = SHARETHIS.addEntry({title:document.title, url:document.URL}, {button:false});
		objShare.attachButton(document.getElementById('sharethis'));
	}
	
	var loadOPCs = function() { //loads "other people's code" sources
		var strFile;
		
		//swfobject
		//ITG.utils.loadJSFile('/includes/opc/swfobject/swfobject.js');
		
		switch(_info.type) {
			case 'popups': //Shadowbox
				ITG.utils.loadCSSFile('/includes/opc/shadowbox/shadowbox.css');
				ITG.utils.loadJSFile('/includes/opc/shadowbox/shadowbox.js'); //"Shadowbox.init" added to file
				break;
			case 'gcse': //Google CSE
				ITG.utils.loadJSFile('/includes/opc/googlecse/googlecse.js'); break;
			default: break;
		}
		
		//ShareThis
		ITG.utils.loadJSFile('http://w.sharethis.com/button/sharethis.js#publisher=0ebe5ff7-b33a-4c99-b0a5-c98eff41b4db&type=website&embeds=true&linkfg=#373680&onmouseover=false&button=false');
		
			
		//Google Analytics
		if(_info.live) {
			strFile = _info.ssl ? 'https://ssl' : 'http://www'; strFile += '.google-analytics.com/ga.js';
			ITG.utils.loadJSFile(strFile, true, 'head');
		}
	}
	
	var loadInfo = function() { //loads "info" object
		var strPath; var arrPath;
		var strQuery; var arrQuery; var objQuery;
		var i; var arrTemp;
		
		//window object properties
		_info.ssl = (window.location.protocol == 'https:') ? true : false;
		_info.host = window.location.hostname;
		_info.port = window.location.port;
		
		strPath = window.location.pathname;
		arrPath = strPath.slice(1).split('/');
		if(arrPath[(arrPath.length - 1)] == '') {arrPath[(arrPath.length - 1)] = 'index.html'; strPath += 'index.html';}
		_info.path = strPath; _info.patharray = arrPath;
		
		
		
		strQuery = window.location.search; objQuery = {};
		if(strQuery != '') {
			strQuery = strQuery.slice(1); arrQuery = strQuery.split('&');
			for(i=0; i<arrQuery.length; i++) {
				arrTemp = arrQuery[i].split('='); objQuery[arrTemp[0]] = arrTemp[1];
			}
		}
		_info.querystring = strQuery; _info.query = objQuery
		
		//document object properties
		_info.referrer = document.referrer;
		
		//live server?
		_info.live = (_info.host.indexOf('intellisoftgroup.com') != -1) ? true : false;
		
		//"page" & "footbody" CSS class
		switch(_info.path) {
			case '/index.html':
				_info.template = 'topper'; break;
			case '/solutions/credential-management/index.html':
			case '/solutions/payer-provider-enrollment/index.html':
			case '/solutions/contract-management/index.html':
			case '/products/intellicred/index.html':
			case '/products/intelliapp/index.html':
			case '/products/intelliappsmart/index.html':
			case '/products/intellicontract/index.html':
				_info.template = 'banner'; break;
			case '/search-results.html':
				_info.template = 'nolnav'; break;
			case '/solutions/index.html':
				_info.template = 'toprnolnav'; break;
			default:
				_info.template = 'default'; break;
		}
		
		//content type
		switch(_info.path) {
			case '/index.html':
				_info.type = 'gallery'; break;
			case '/products/video-demos.html':
				_info.type = 'popups'; break;
			case '/contact-us.html':
				_info.type = 'hubform'; break;
			case '/search-results.html':
				_info.type = 'gcse'; break;
			default:
				_info.type = 'default'; break;
		}
	}
	
	var getInfo = function() { //gets copy of "info" object
		var objTemp = {}; var x;
		for(x in _info) {objTemp[x] = _info[x];}
		return(objTemp);
	}
	
	return {
		init: onInit, onLoad: onLoad,
		getInfo: getInfo
	}
	
}();

ITG.utils = function() {
	
	var loadJSFile = function(file, asyn, node) { //loads external js file
		file = (typeof(file) == 'string') ? file : '';
		asyn = (typeof(asyn) == 'boolean') ? asyn : false;
		node = (asyn && (typeof(node) == 'string')) ? node : 'head';
		
		var objFile; var objNode;
		
		if(asyn) {
			objFile = document.createElement('script');
			objFile.type = 'text/javascript';
			objFile.loaded = false;
			
			if(objFile.readyState) { //IE & Opera
				objFile.onreadystatechange = function() {
					if((objFile.readyState == 'loading' || objFile.readyState == 'complete') && !objFile.loaded) {objFile.loaded = true; onJSFileLoad();}
				}
			} else {
				objFile.onload  = function() {
					if(!objFile.loaded) {objFile.loaded = true; onJSFileLoad();}
				}
			}
			
			objFile.src = file;
			objFile.async = true;
			
			objNode = document.getElementsByTagName(node)[0];
			objNode = (objNode == null) ? document.getElementById(node) : objNode;
			if(objNode != null) {objNode.appendChild(objFile);}
		} else {document.write('<script type="text/javascript" src="' + file + '"><\/script>');}
	}
	
	var onJSFileLoad = function() {} //callback: "loadJSFile" (asynchronous)
	
	var loadCSSFile = function(file, asyn, node) { //loads external css file
		file = (typeof(file) == 'string') ? file : '';
		asyn = (typeof(asyn) == 'boolean') ? asyn : false;
		node = (asyn && (typeof(node) == 'string')) ? node : 'head';
		
		var objFile; var objNode;
		
		if(asyn) {
			objFile = document.createElement('link');
			objFile.rel = 'stylesheet';
			objFile.type = 'text/css';
			objFile.href = file;
		
			objNode = document.getElementsByTagName(node)[0];
			objNode = (objNode == null) ? document.getElementById(node) : objNode;
			if(objNode != null) {objNode.appendChild(objFile);}
		} else {document.write('<link rel="stylesheet" type="text/css" href="' + file + '" />');}
	}
			
	return {
		loadJSFile: loadJSFile, loadCSSFile: loadCSSFile
	}
	
}();

var trace = function(text) {alert(text);} //allows "trace" to be used in place of "alert"
window.onload = ITG.page.onLoad;
ITG.page.init();
