var currentPath = getPath();
var sitePath = getSitePath();
var isIndexPage = currentPath==(sitePath+"index.html");
var isIE = /*@cc_on!@*/false;
var flagsDropdown = null;
var solutions = null;
var newsItems = [
	{"title":"CALUMO Sponsors Villa Maria Charity Golf Day, 25 October 2010", "date":"25 October 2010", "image":"golf.png", "text":"Villa Maria will host its second annual Charity Golf Day at Southern Golf Club, Keysborough VIC to help raise funds for two very important programs to support young people with a disability and their families.", "href":"http://www.villamaria.com.au/search-event/event/43-villa-maria-charity-golf-day.html"},
	{"title":"IBM Business Analytics Forum, 3-5 November 2010", "date":"3-5 November 2010", "image":"ibm_analytics_forum2010.png", "text":"This is your opportunity to participate in the premier conference for the Business Analytics community in Asia Pacific.  Join your fellow professionals from IT, the office of finance, and lines of business and learn how to drive better, faster outcomes, increase your ROI, and lower your total cost of ownership.", "href":"http://www-01.ibm.com/software/au/data/2010-conference/index.html"},
	{"title":"CALUMO Maintains Customer Satisfaction", "date":"", "image":"graph_up.png", "text":"CALUMO is a Microsoft GOLD partner, a status that requires continued levels of excellence. The latest independent survey of CALUMO's customer satisfaction shows continued positive feedback.  Click ''Learn More'' to see the results.", "href":sitePath+"pdf/MS NSAT Results_CALUMO.pdf"},
	{"title":"CALUMO 11.5 Out Now", "date":"", "image":"calumo_logo.png", "text":"Our latest release includes some powerful additions to the CALUMO arsenal. Dimension Maintenance and Advanced Writeback Spreading are just two.", "href":"http://support.calumo.com/browse/INFO-71"},
	{"title":"CALUMO for TM1 10.4 Out Now", "date":"", "image":"calumo_logo.png", "text":"In addition to CALUMO 11.5, our development team has been working hard to complete CALUMO for TM1 10.4. Please check out the vast array of cool new features.", "href":"http://support.calumo.com/browse/INFO-74"},
	{"title":"CALUMO Training Academy", "date":"", "image":"light_bulb.png", "text":"The CALUMO Academy course offerings have been ramping up! We now offer our clients (and potential clients) the most professional and comprehensive courses for mastering CALUMO, TM1, Excel, MDX, Advanced Reporting and Analysis Services Cube Design.", "href":sitePath+"training.html"},
	{"title":"Microsoft SharePoint 2010 Out Now", "date":"", "image":"sharepoint.png", "text":"SharePoint 2010 is now out of BETA.  Check out what's new and download the free trial to experience the benefits.", "href":"http://sharepoint.microsoft.com"},
	{"title":"Introducing IBM Cognos Express", "date":"", "image":"ibm_logo.png", "text":"CALUMO is very excited to be partnering with IBM in support of the recently released IBM Cognos Express.", "href":"http://www-01.ibm.com/software/data/cognos/products/cognos-express/"}
];

var menuItems = [
	{"name":"SOLUTIONS", "level":"1", "href":"benefits_managers.html"},
		{"name": "How We Can Help", "level":"2" , "href" : "solutions.html", "hidden":"true"},
		{"name": "Benefits", "level":"2" , "href" : "benefits_managers.html"},
		{"name": "For Managers", "level":"3" , "href" : "benefits_managers.html"},
		{"name": "For Sales/Marketing", "level":"3" , "href" : "benefits_sales.html"},
		{"name": "For Finance", "level":"3" , "href" : "benefits_finance.html"},
		{"name": "For IT", "level":"3" , "href" : "benefits_it.html"},
		{"name": "For HR", "level":"3" , "href" : "benefits_hr.html"},
		{"name": "Solution Benefits", "level":"2" , "href" : "benefits_ra.html"},
		{"name": "Reporting & Analysis", "level":"3" , "href" : "benefits_ra.html"},
		{"name": "Planning & Forecasting", "level":"3" , "href" : "benefits_pf.html"},
		{"name": "Dashboards & KPIs", "level":"3" , "href" : "benefits_kpi.html"},
		{"name": "Testimonials", "level":"2" , "href" : "testimonials.html"},
		{"name": "Case Studies", "level":"2" , "href" : "case_studies.html"},
	{"name":"SERVICES", "level":"1", "href":"support.html"},
		{"name":"Overview", "level":"2", "href":"support.html"},
		{"name":"Consulting", "level":"2", "href":"consulting.html"},
		{"name":"Training Courses", "level":"2", "href":"training.html"},
		{"name":"Book Now", "level":"3", "href":"training_registration.html"},
		{"name":"Details Received", "level":"3", "href":"training_response.html", "hidden":"true"},
		{"name":"Venues", "level":"3", "href":"training_venues.html"},
		{"name":"Customer Support", "level":"2", "href":"support_online.html"},
	{"name":"TECHNOLOGY", "level":"1", "href":"tech_overview.html"},
		{"name": "Overview", "level":"2" , "href" : "tech_overview.html"},
		{"name": "CALUMO for SSAS", "level":"2" , "href" : "tech_calumo_ssas.html"},
		{"name": "CALUMO for TM1", "level":"2" , "href" : "tech_calumo_tm1.html"},
		{"name": "CALUMO Skylights", "level":"2" , "href" : "skylights/index.html","hidden":"true"},
		{"name": "CALUMO Sparks", "level":"2" , "href" : "tech_calumo_sparks.html"},
		{"name": "BI Platforms", "level":"2" , "href" : "partners.html"},
		{"name": "IBM", "level":"3" , "href" : "partners_ibm.html"},
		{"name": "Microsoft", "level":"3" , "href" : "partners_microsoft.html"},
	{"name":"COMPANY", "level":"1", "href":"company.html"},	
		{"name": "News", "level":"2" , "href" : "news.html"},	
		{"name": "About Us", "level":"2" , "href" : "company.html"},
		{"name": "Our Name", "level":"3" , "href" : "company_name.html"},
		{"name": "Executive Team", "level":"3" , "href" : "company_exec_team.html"},
		{"name": "Partnerships", "level":"3" , "href" : "partners.html"},
		{"name": "Community Support", "level":"3" , "href" : "company_community.html"},
		{"name": "Contact Us", "level":"2" , "href" : "contacts.html"},
		{"name": "Enquiry Form", "level":"3" , "href" : "contact_form.html", "hidden":"true"},
		{"name": "Enquiry Received", "level":"3", "href":"contact_response.html", "hidden":"true"},
		{"name": "Careers", "level":"2" , "href" : "company_careers.html"}	
];

function init() {
	buildHeader();
	buildMenus();
	buildFooter();
	addPageEnd();
	populateVars();
	bindEvents();
	if (isIndexPage) {
		$('body').fadeIn(700);
	} else {
		$('body').show();
	}
}

function getSitePath() {
	if (window.location.hostname=='forums.calumo.com') {
		return '/demo/';
	}
	if (startsWith(currentPath,'/C:/calumowebsite/')) {
		return '/C:/calumowebsite/';
	}
	return '/';
}

function bindEvents() {
	var me = this;
	$("#flags").bind("mouseover", function() { me.showContactsDropdown(); });
	$("#flags").bind("mouseout", function() { me.hideContactsDropdown(); });
}

function populateVars() {
	$('.mainPhone').html('+61 2 8985 7777');
	if (solutions!=null) {
		buildScenarios();
	}
}

function buildHeader() {
	$("#header").append('<div id="headeroptions"><div id="search" style="display:none"><input id="searchinput" type="text" value="Search"/><input id="searchbutton" type="submit" value=""/></div></div>');
	//$("#header").append('<div id="phoneNumber">02 8985 7777</div>');
	$("#headeroptions").append('<div id="flagsLabel">Contact:</div><div id="flags"></div>');
	$("#header").append('<a href="'+sitePath+'index.html" id="logobutton"></a><table id="menu"><tr></tr></table>');
}

function addPageEnd() {
	$("body").append("<div id='page_end'></div>");
}

function buildFooter() {
	$("#footer").addClass("footerGradient");
	$("#footer").append('<div id="footercontent"><div id="sitemap"></div></div>');
	var d = new Date();
	$("#footer").append('<div id="copyright">Copyright &copy;'+ d.getFullYear() +' CALUMO. All rights reserved</div>');
	$("#copyright").addClass("copyrightBorder");
	buildSiteMap();
}

function buildMenus() {
	var subMenu = $('#menu_panel');
	var mainMenu = $('#menu tr');
	var selectedMainItemIndex;
	var isIndexPage = subMenu.length==0 ? " style='visibility:hidden;'" : "";
	var tdClass = isIndexPage ? "" : " class='homeIcon'";
	mainMenu.append("<td" + tdClass + "><a id='homebutton' href='"+sitePath+"index.html'" + isIndexPage + ">&nbsp;&nbsp;</a></td>");

	// Find which main menu item the current page lives under
	for (index in menuItems) {
		if (menuItems[index].level=='1') {
			selectedMainItemIndex = index;
		}
		if ((sitePath+menuItems[index].href)==currentPath) {
			break;
		}
	}
	
	// Populate main menu items, plus sub menu items for selected main menu item
	var mainItemFound = false;
	var tabIndex = 0;
	var tabClass="";
	for (index in menuItems) {
		var item = menuItems[index];
		var nextItem = menuItems[Number(index)+1];
		var nextHref = nextItem == null ? "":nextItem.href;
		if (index == selectedMainItemIndex) {
			mainItemFound=true;
		}
		else if (mainItemFound && item.level=='1') {
			mainItemFound = false;
		}
		if (item.level=='1') {
			tabIndex++;
			if (index==selectedMainItemIndex && !isIndexPage) {
				tabClass="tab"+tabIndex;
				mainMenu.append("<td id='tab" + tabIndex + "' class='currenttab'>" + item.name + "</td>");
			} 
			else {
				mainMenu.append("<td id='tab" + tabIndex + "'><a href='" + sitePath + item.href + "'>" + item.name + "</a></td>");
			}
		}
		if (mainItemFound && !isIndexPage) {
			var element;
			if ((sitePath+item.href) == currentPath && item.level!='1' && item.href!=nextHref) {
				element = $("<div class='currentitem" + (item.level == '3' ? " indent":"") + "'>" + item.name + "</div>").appendTo(subMenu);
			}
			else if (item.hidden == null && item.level!='1') {
				element = $("<a " + (item.level == '3' ? "class='indent'":"") + " href='" + sitePath + item.href + "'>" + item.name + "</a>").appendTo(subMenu);
			}
		}
	}
	if (tabClass!="") {
		$("#menu").addClass(tabClass);
		mainMenu.append("<td></td>"); // Adds some space to the right for the tab shadow
	}
	if ($('#menu_panel .currentitem').length==0) {
		$("<div class='currentitem'>VIP Area</div>").appendTo(subMenu);
	}
}

function highlightRequiredFields() {
	// Used for validation on entry forms
	$('.required').each(function() {
			var val = $(this).val();
			if (val.length<2) {
				$(this).addClass('missing');
			} else {
				$(this).removeClass('missing');
			}
		}
	);
}

function buildSiteMap() {
	containerElement = $('#sitemap');
	var groupElement;
	for (index in menuItems) {
		var item = menuItems[index];
		if (item.level==1) {
			groupElement = $("<div class='siteMapGroup'></div>").appendTo(containerElement);
		}
		if (item.level<3 && item.hidden == null) {
			var classHtml = item.level==1 ? "class='siteMapHeading'" : "";
			groupElement.append("<a " + classHtml + " href='" + sitePath + item.href + "'>" + item.name + "</a>");
		}
	}
}

function getPath() {
	var path = window.location.pathname;
	if (path.substr(path.length-1,1)=="/") {  
		path = path + "index.html";
	}
	return path;
}

function showContactsDropdown() {
	if (flagsDropdown==null) {
		var html =  "\
			<div class='contactBox'>\n\
				<div class='contactTop'>Contact us:<p id='closeIfHoveringOverThisBit'></p></div>\n\
				<div class='contactMiddle'>\n\
					<table style='width:100%'>\n\
						<tr class='contactBorderBottom'><td><a href='" + sitePath + "contacts.html'>Sydney<br/>Head Office</a></td><td style='color:black' class='phone'><span class='intcode'>+61</span> &nbsp;<span style='display:none;'>NoSkype</span>2 8985 7777</td></tr>\n\
						<tr class='contactBorderTop contactBorderBottom'><td><a href='" + sitePath + "contacts.html'>London</a></td><td class='phone'><span class='intcode'>+44</span> <span style='display:none;'>NoSkype</span>20 7643 1751</td></tr>\n\
						<tr class='contactBorderTop'><td><a href='" + sitePath + "contacts.html'>Brisbane</a></td><td class='phone'><span class='intcode'>+61</span> &nbsp;7 3367 9300</td></tr>\n\
						<tr><td><a href='" + sitePath + "contacts.html'>Melbourne</a></td><td class='phone'><span class='intcode'>+61</span> &nbsp;3 9865 6400</td></tr>\n\
						<tr class='contactBorderBottom'><td><a href='" + sitePath + "contacts.html'>Canberra</a></td><td class='phone'><span class='intcode'>+61</span> &nbsp;2 6243 3692</td></tr>\n\
						<tr class='contactBorderBottom contactBorderTop'><td colspan='2'><a href='" + sitePath + "contacts.html'>Address and Fax Details</a></td></tr>\n\
						<tr class='contactBorderTop'><td colspan='2'><a href='" + sitePath + "contact_form.html'>Submit an Enquiry</a></td></tr>\n\
					</table>\n\
				</div>\n\
				<div class='contactBottom'></div>\n\
			</div>\n\
";
		flagsDropdown = $(html).appendTo("#flags");
		var me = this;
		$("#closeIfHoveringOverThisBit").bind("mouseover", function(e) { me.hideContactsDropdown(e); });
	}
	flagsDropdown.show();
}

function hideContactsDropdown(e) {
	flagsDropdown.hide();
	if (e!=null)
		e.stopImmediatePropagation();
}

function getDayText (day) {
	var weekday=new Array(7);
	weekday[0]="Sunday";
	weekday[1]="Monday";
	weekday[2]="Tuesday";
	weekday[3]="Wednesday";
	weekday[4]="Thursday";
	weekday[5]="Friday";
	weekday[6]="Saturday";
	return weekday[day];
}
function getMonthText (m) {
	var month=new Array(12);
	month[0]="January";
	month[1]="February";
	month[2]="March";
	month[3]="April";
	month[4]="May";
	month[5]="June";
	month[6]="July";
	month[7]="August";
	month[8]="September";
	month[9]="October";
	month[10]="November";
	month[11]="December";
	return month[m];
}
function rightString(text,pos) {
	return text.substr(text.length - pos);
}

function startsWith(text,startsWith) {
	return text.substring(0,startsWith.length)==startsWith;
}