var redirectURL = '';

$(document).ready(function() {
	$(".salesDemoINT001").click(function(e) {
		e.preventDefault();
		loadDemo('http://www.sagehealthcustomerlearning.com/files/Demos/content_int/SALES_INT_main.swf', '920', '720');
		redirectURL = $(this).hasClass("no_redirect") ? '' : 'http://www.sagehealth.com/tools/Pages/demo_intergy_request_info_1.aspx';
		try {
			dcsMultiTrack('DCS.dcsuri','WT.ti','Intergy Product Demo','WT.cg_n','Products; Demos','WT.cg_s','Practice Management; Intergy Demo','WT.si_n','Intergy Demo','WT.si_p','Intergy Product Demo');
		} catch(e) {}
	});
	$(".salesDemoEHR001").click(function(e) {
		e.preventDefault();
		loadDemo('http://www.sagehealthcustomerlearning.com/files/Demos/content_ehr/SALES_EHR_main.swf', '920', '720');
		redirectURL = $(this).hasClass("no_redirect") ? '' : 'http://www.sagehealth.com/tools/Pages/demo_intergy_ehr_request_info_1.aspx';
		try {
			dcsMultiTrack('DCS.dcsuri','WT.ti','Intergy EHR Demo','WT.cg_n','Products; Demos','WT.cg_s','Electronic Health Records; Intergy EHR Demo','WT.si_n','','WT.si_p','');
		} catch(e) {}
	});
	$(".salesDemoPA001").click(function(e) {
		e.preventDefault();
		loadDemo('http://www.sagehealthcustomerlearning.com/files/Demos/content_pa/SALES_PA_main.swf', '920', '720');
		redirectURL = $(this).hasClass("no_redirect") ? '' : 'http://www.sagehealth.com/tools/Pages/demo_practice_analytics_request_info_1.aspx';
		try {
			dcsMultiTrack('DCS.dcsuri','WT.ti','Practice Analytics Product Demo','WT.cg_n','Products; Demos','WT.cg_s','Business Intelligence; Practice Analytics Demo','WT.si_n','Practice Analytics Demo','WT.si_p','Practice Analytics Product Demo');
		} catch(e) {}
	});
	$(".salesDemoSMM001").click(function(e) {
		e.preventDefault();
		loadDemo('http://www.sagehealthcustomerlearning.com/files/Demos/content_smm/SALES_SMM_main.swf', '920', '720');
		redirectURL = $(this).hasClass("no_redirect") ? '' : 'http://www.sagehealth.com/tools/Pages/demo_medical_manager_request_info_1.aspx';
		try {
			dcsMultiTrack('DCS.dcsuri','WT.ti','Sage Medical Manager Product Demo','WT.cg_n','Products; Demos','WT.cg_s','Practice Management; Sage Medical Manager Demo','WT.si_n','Sage Medical Manager Demo','WT.si_p','Sage Medical Manager Product Demo');
		} catch(e) {}
	});
    $(".salesDemoOB001").click(function(e) {
		e.preventDefault();
		loadDemo('http://www.sagehealthcustomerlearning.com/files/Demos/content_ob/SALES_OB_main.swf', '920', '720');
		redirectURL = $(this).hasClass("no_redirect") ? '' : 'http://www.sagehealth.com/tools/Pages/demo_intergy_ehr_obgyn_request_info_1.aspx';
		try {
			dcsMultiTrack('DCS.dcsuri','WT.ti','Sage Intergy EHR for OB Product Demo','WT.cg_n','Products; Demos','WT.cg_s','Electronic Health Records; Sage Intergy EHR for OB Demo','WT.si_n','Intergy EHR for OB/GYN Demo Request Info','WT.si_p','Intergy EHR for OB/GYN Demo Request Info Form Entered');
		} catch(e) {}
	});
});

function loadDemo(location, width, height)
{
	$("body").append("<div id='salesDemo'></div><div id ='overlay'></div>");	
	$("#salesDemo:first").each(function() {
		$(this).css("width",width + "px");
		$(this).css("height",parseInt(height) + "px");
		$(this).css("top",($(document).height()-$(window).scrollTop() >= parseInt(height) ? $(window).scrollTop() : $(document).height()-parseInt(height)) + "px");
		if($(document).height() < parseInt(height)) { $(this).css("top", "0px"); }
		$(this).css("margin-left",-parseInt(width) / 2 + "px");
		$(this).append("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='" + width + "' height='" + height + "' ID='loadedDemo'><param name='movie' value='" + location + "'><param name='wmode' value='transparent'><param name='quality' value='high'><param name='loop' value='2'><param name='allowScriptAccess' value='always'><embed src='" + location + "' width='" + width + "' height='" + height + "' loop='2' quality='high' wmode='transparent' allowScriptAccess='always' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' menu='false' name='loadedDemo'></embed></object>");
		$("#overlay:first").css("display","block");
		$(this).css("display","block");
	});
}

function unloadDemo(cancelRedirect)
{
	$("#salesDemo, #overlay").text("&nbsp;").remove();
	if(cancelRedirect != "true" && redirectURL) {
		window.location = redirectURL;
		return false;
	}
}