var preloadedImages = [];
function preloadSideNavigationImages(type) {
	var nav_img = {
		products: ["overview.jpg", "phone.jpg", "mobile.jpg", "conference.jpg", "pushntalk.jpg", "facebook.jpg", "bulkcallssms.jpg", "cdr.jpg", "schedule.jpg", "callerid.jpg", "ivr.jpg", "carriergrade.jpg", "enterprise.jpg", "unblockable.jpg"],
		samples: ["back_icon.png", "php.png", "developers.jpg", "account.jpg", "phone.jpg", "conference.jpg", "sms.jpg", "flash.png"],
		about: ["company.jpg", "team.jpg", "blog.jpg", "press.jpg", "contact.jpg"],
		pricing: ["reseller.jpg", "developers.jpg", "enterprise.jpg"],
		developer: ["overview.jpg", "developers.jpg", "phone.jpg", "sms.jpg", "conference.jpg", "sip.jpg", "ivr.jpg", "monitor.jpg", "cdr.jpg", "apidoc.jpg", "samples.jpg", "demo.jpg", "bulkcalls.jpg", "authentication.jpg"],
		api: ["back_icon.png", "developers.jpg", "specificapi.jpg"],
		restapi: ["back_icon.png", "developers.jpg", "specificapi.jpg"]
	};
	var pImg = null;
	pImg = PreloadIconImage(getAbsolutePath("images/tringmelogo.png"));
	preloadedImages.push(pImg);
	var iconPath = "images/icons/";
	if(nav_img[type]) {
		for(var i=0; i<nav_img[type].length; i++) {
			pImg = PreloadIconImage(getAbsolutePath(iconPath + nav_img[type][i]));
			preloadedImages.push(pImg);
		}
	}
}

function sideNavigationProducts(elId, active) {
	if(null==$(elId))
		return;
	var nav_obj = { overview: {ref: 'howitworks.html', text: "Overview", img: "images/icons/overview.jpg"},
		c2c: {ref: "callfromanywhere.html", text: "Call from Anywhere", img: "images/icons/phone.jpg"},
		mvoip: {ref: "mobilevoip.html", text: "Mobile VoIP", img: "images/icons/mobile.jpg"},
		conf: {ref: "conferencing.html", text: "Audio Conferencing", img: "images/icons/conference.jpg"},
		pnt: {ref: "pushntalk.html", text: "Push-N-Talk Widgets", img: "images/icons/pushntalk.jpg"},
		fb: {ref: "facebook.html", text: "Call from Facebook", img: "images/icons/facebook.jpg"},
		bulkcallssms: {ref: "bulkcalls.html", text: "Bulk Calls, SMS", img: "images/icons/bulkcallssms.jpg"},
		cdr: {ref: "cdr.html", text: "Online Call Records", img: "images/icons/cdr.jpg"},
		callSMS: {ref: "schedulecallsms.html", text: "Schedule Calls & SMS", img: "images/icons/schedule.jpg"},
		callerid: {ref: "callerid.html", text: "Personalize your Caller-id", img: "images/icons/callerid.jpg"},
		ivr: {ref: "ivrvoicephp.html", text: "IVRs & VoicePHP", img: "images/icons/ivr.jpg"},
		carrier: {ref: "carriergrade.html", text: "Carrier Grade", img: "images/icons/carriergrade.jpg"},
		enterprise: {ref: "enterpriseready.html", text: "Enterprise Ready", img: "images/icons/enterprise.jpg"},
		unblockable: {ref: "unblockable.html", text: "It's Unblockable!", img: "images/icons/unblockable.jpg"}
	};

	sideNavigation(elId, active, nav_obj);
}

function sideNavigationSamples(elId, active) {
	if(null==$(elId))
		return;
	var nav_obj = { back: {ref:'developers.html', 'text': 'Back to Developers', img: "images/icons/back_icon.png" },
		php: {ref: 'phpsamples.html', text: "PHP Samples", img: "images/icons/php.png", child: {
			'create': {ref: "#create", img: "images/icons/developers.jpg", text: "Create Account"},
			'login': {ref: "#login", img: "images/icons/account.jpg", text: "Login"},
			'call': {ref: "#call", img: "images/icons/phone.jpg", text: "Call"},
			'conference': {ref: "#conf", img: "images/icons/conference.jpg", text: "Conference"},
			'sms': {ref: "#sms", img: "images/icons/sms.jpg", text: "SMS"}
		} },
		flash: {ref:'flashsamples.html', 'text': 'Flash Samples', img: "images/icons/flash.png" }
	};

	sideNavigation(elId, active, nav_obj);
}

function sideNavigationAbout(elId, active) {
	if(null==$(elId))
		return;
	var nav_obj = { company: {ref: 'company.html', text: "Company", img: "images/icons/company.jpg" },
		team: {ref: 'team.html', text: "Team", img: "images/icons/team.jpg" },
		blog: {ref: 'http://blog.tringme.com', text: "Blog", img: "images/icons/blog.jpg" },
		press: {ref: 'press.html', text: "Press", img: "images/icons/press.jpg" },
		contact: {ref: 'contact.html', text: "Contact", img: "images/icons/contact.jpg" }
	};

	sideNavigation(elId, active, nav_obj);
}

function sideNavigationPricing(elId, active) {
	if(null==$(elId))
		return;
	var nav_obj = { resellers: {ref: 'resellerpricing.html', text: "Resellers", img: "images/icons/reseller.jpg"},
		developer: {ref: 'developerpricing.html', text: "Developers", img: "images/icons/developers.jpg"},
		enterprise: {ref: 'enterprisepricing.html', text: "Enterprise", img: "images/icons/enterprise.jpg"}
	};

	sideNavigation(elId, active, nav_obj);
}

function sideNavigationDevelopers(elId, active) {
	if(null==$(elId))
		return;
	var nav_obj = { developers: {ref:'developers.html', 'text': 'Overview', img: "images/icons/overview.jpg", drawBorder: true},
		apibasics: {ref: 'gettingstarted.html', text: "Basics", img: "images/icons/developers.jpg"},
		callsec: {ref: 'telephony.html', text: "Telephony", img: "images/icons/phone.jpg"},
		smssec: {ref: 'messaging.html', text: "Messaging", img: "images/icons/sms.jpg"},
		confsec: {ref: 'conference.html', text: "Conferencing", img: "images/icons/conference.jpg"},
		rtm: {ref: 'realtimemonitoring.html', 'text': 'Real Time Notifications', img: "images/icons/monitor.jpg", drawBorder: true},
		apisec: {ref: '#', 'text': 'API Documentation', img: "images/icons/apidoc.jpg", child: {
			rest: {ref:'api/restapi.html', 'text': 'REST API', img: "images/icons/developers.jpg"},
			flash: {ref:'api/flashapi.html', 'text': 'Flash API', img: "images/icons/developers.jpg"},
			js: {ref:'api/jsapi.html', 'text': 'JavaScript API', img: "images/icons/developers.jpg"}
		}, drawBorder: true, noNext: true },

		apipricing: {ref: 'developerpricing.html', 'text': 'Pricing', img: "images/icons/pricing.jpg" },
		apitos: {ref: 'tringmeapitos.html', 'text': 'Terms Of Services (API)', img: "images/icons/apitos.jpg" },
		//apisec: {ref: 'api.html', 'text': 'API Documentation', img: "images/icons/apidoc.jpg" },
		samples: {ref: 'phpsamples.html', 'text': 'Samples & Demos', img: "images/icons/samples.jpg", noNext: true },
		usecase: {ref: 'usecases.html', 'text': 'Use Cases', img: "images/icons/demo.jpg", child: {
			//vbroadcast:{ref: '#voice-broadcasting', text: "Voice Broadcasting", img: "images/icons/voicebroadcast.jpg"},
			bulkcalls:{ref: '#bulk-calls', text: "Bulk Calls", img: "images/icons/bulkcalls.jpg"},
			authentication:{ref: '#authentication', text: "Phone Authentication", img: "images/icons/authentication.jpg"}//,
			//matrimonial:{ref: '#matrimonial', text: "Matrimonial", img: "images/icons/matrimonial.jpg"},
			//booking:{ref: '#travel-booking', text: "Travel Booking", img: "images/icons/travel.jpg"}
		} }
		//sipsec: {ref: 'sipintegration.html', text: "SIP Integration", img: "images/icons/sip.jpg"},
		//ivr: {ref: 'ivr.html', 'text': 'IVR', img: "images/icons/ivr.jpg" },
		//records: {ref: 'transparentrecords.html', 'text': 'Transparent Records', img: "images/icons/cdr.jpg", drawBorder: true},
	};
/*
	if($('dynamic-content')) {
		var div = new Element('div', { style: "float: right;" });
		var link = new Element('a', { 'class': "more", href: "api/restapi.html", text: "API Documentation"});
		link.inject(div);
		div.inject($('dynamic-content'), 'top');
	}
*/

	addNextLink(nav_obj, active);
	sideNavigation(elId, active, nav_obj);
}

function sideNavigationAPI(elId, active) {
	if(null==$(elId))
		return;
	var nav_obj = {
		back: {ref:'developers.html?open=true', 'text': 'Back to API', img: "images/icons/back_icon.png" },
		api: {ref:'api.html', 'text': 'API Documentation', img: "images/icons/developers.jpg" },
		rest: {ref:'api/usermanagementapi.html', 'text': 'REST API', img: "images/icons/developers.jpg" },
		flash: {ref:'api/flashapi.html', 'text': 'Flash API', img: "images/icons/developers.jpg", child: {
			makingcall: {ref: "#makingcall", img: "images/icons/specificapi.jpg", text: "Making a Call"},
			netconnection: {ref: "#NetConnection", img: "images/icons/specificapi.jpg", text: "Net Connection"},
			endingcall: {ref: "#endingcall", img: "images/icons/specificapi.jpg", text: "End Call"},
			callstatus: {ref: "#callstatus", img: "images/icons/specificapi.jpg", text: "Call Status"},
			flashwidgets: {ref: "#flashwidgets", img: "images/icons/specificapi.jpg", text: "TringMe Flash Widgets"}
		 } },
		js: {ref:'api/jsapi.html', 'text': 'JavaScript API', img: "images/icons/developers.jpg", child: {
			callnumber: {ref: "#call", img: "images/icons/specificapi.jpg", text: "Call a number"},
			dtmf: {ref: "#dtmf", img: "images/icons/specificapi.jpg", text: "Sending DTMF"},
			endcall: {ref: "#endcall", img: "images/icons/specificapi.jpg", text: "End Call"},
			notif: {ref: "#notification", img: "images/icons/specificapi.jpg", text: "Call Status Notification"}
		} }//,
		//mv: {ref:'mvapi.html', 'text': 'Mobile VoIP API(TBD)', img: "images/icons/developers.jpg" }
	};

	sideNavigation(elId, active, nav_obj);
}

function sideNavigationFlashAPI(elId, active) {
	if(null==$(elId))
		return;
	var nav_obj = {
		back: {ref:'developers.html?open=true', 'text': 'Back To Developers Page', img: "images/icons/back_icon.png" },
		flash: {ref:'api/flashapi.html', 'text': 'Flash APIs', img: "images/icons/developers.jpg", child: {
			makingcall: {ref: "#makingcall", img: "images/icons/specificapi.jpg", text: "Making a Call"},
			netconnection: {ref: "#NetConnection", img: "images/icons/specificapi.jpg", text: "Net Connection"},
			endingcall: {ref: "#endingcall", img: "images/icons/specificapi.jpg", text: "End Call"},
			callstatus: {ref: "#callstatus", img: "images/icons/specificapi.jpg", text: "Call Status"},
			flashwidgets: {ref: "#flashwidgets", img: "images/icons/specificapi.jpg", text: "TringMe Flash Widgets"}
		 } }
	};

	sideNavigation(elId, active, nav_obj);
}
function sideNavigationJSAPI(elId, active) {
	if(null==$(elId))
		return;
	var nav_obj = {
		back: {ref:'developers.html?open=true', 'text': 'Back To Developers Page', img: "images/icons/back_icon.png" },
		js: {ref:'api/jsapi.html', 'text': 'JavaScript APIs', img: "images/icons/developers.jpg", child: {
			callnumber: {ref: "#call", img: "images/icons/specificapi.jpg", text: "Call a number"},
			dtmf: {ref: "#dtmf", img: "images/icons/specificapi.jpg", text: "Sending DTMF"},
			endcall: {ref: "#endcall", img: "images/icons/specificapi.jpg", text: "End Call"},
			notif: {ref: "#notification", img: "images/icons/specificapi.jpg", text: "Call Status Notification"}
		} }
	};

	sideNavigation(elId, active, nav_obj);
}

function sideNavigationRESTAPI(elId, active) {
	if(null==$(elId))
		return;
	var nav_obj = {
		back: {ref:'developers.html?open=true', 'text': 'Back To Developers Page', img: "images/icons/back_icon.png" },
		restapi: {ref:'api/restapi.html', 'text': 'REST API', img: "images/icons/developers.jpg", child: {
			overview: {ref: 'api/restapi.html#overview', 'text': 'Overview', img: "images/icons/specificapi.jpg" },
			invokingrestapi: {ref: 'api/restapi.html#invokingrestapi', 'text': 'Invoking REST API', img: "images/icons/specificapi.jpg" },
			restapiusage: {ref: 'api/restapi.html#restapiusage', 'text': 'API Usage', img: "images/icons/specificapi.jpg" },
			phphelper: {ref: 'api/phphelper.html', 'text': 'PHP Helper', img: "images/icons/specificapi.jpg" }
		} },
		acc: {ref: 'api/usermanagementapi.html', text: "Account Management", img: "images/icons/developers.jpg", child: {
			createuser: {ref: "#createuser", img: "images/icons/specificapi.jpg", text: "Create Account"},
			activateuser: {ref: "#activateuser", img: "images/icons/specificapi.jpg", text: "Activate Account"},
			reactivateuser: {ref: "#reactivateuser", img: "images/icons/specificapi.jpg", text: "Reactivate Account"},
			loginuser: {ref: "#loginuser", img: "images/icons/specificapi.jpg", text: "Login"},
			logout: {ref: "#logout", img: "images/icons/specificapi.jpg", text: "Logout"},
			getuser: {ref: "#getuser", img: "images/icons/specificapi.jpg", text: "User Information"},
			resetpassword: {ref: "#resetpassword", img: "images/icons/specificapi.jpg", text: "Reset Password"},
			changepassword: {ref: "#changepassword", img: "images/icons/specificapi.jpg", text: "Change Password"}
		} },
		calls: {ref:'api/callconfsmsapi.html', 'text': 'Calls, Conferencing & SMS', img: "images/icons/developers.jpg", child: {
			placingcall: {ref: '#placingcall', 'text': 'Placing Call', img: "images/icons/developers.jpg" },
			sendsms: {ref: '#sendsms', 'text': 'Send SMS', img: "images/icons/developers.jpg" },
			cancelschedule: {ref: '#cancelschedule', 'text': 'Cancel Scheduled Ops', img: "images/icons/developers.jpg" },
			getvoicemails: {ref: '#getvoicemails', 'text': 'Get Voicemail', img: "images/icons/developers.jpg" },
			deletevoicemails: {ref: '#deletevoicemails', 'text': 'DeleteVoicemail', img: "images/icons/developers.jpg" },
			createconf: {ref: '#createconf', 'text': 'Conference', img: "images/icons/developers.jpg" },
			setcallerid: {ref: '#setcallerid', 'text': 'Set CallerID', img: "images/icons/developers.jpg" },
			verifycallerid: {ref: '#verifycallerid', 'text': 'Verify CallerID', img: "images/icons/developers.jpg" },
			deletecallerid: {ref: '#deletecallerid', 'text': 'Delete CallerID', img: "images/icons/developers.jpg" }
		} },
		destinations: {ref:'api/destinations.html', 'text': 'Destinations', img: "images/icons/developers.jpg" },
		channel: {ref:'api/channelapi.html', 'text': 'Channels', img: "images/icons/developers.jpg", child: {
			setchannel: {ref: '#setchannel', 'text': 'Set Channel', img: "images/icons/developers.jpg" },
			getchannel: {ref: '#getchannel', 'text': 'Get Channel Info', img: "images/icons/developers.jpg" },
			delchannel: {ref: '#deletechannel', 'text': 'Delete Channel', img: "images/icons/developers.jpg" },
			accesschannel: {ref: '#accesschannel', 'text': 'SIP URI', img: "images/icons/developers.jpg" }
		} },
		sip: {ref:'api/sipanddid.html', 'text': 'SIP & Inward Dialing', img: "images/icons/developers.jpg", child: {
			addingsip: {ref: '#addingsip', 'text': 'Set SIP Settings', img: "images/icons/developers.jpg" },
			deletingsip: {ref: '#deletingsip', 'text': 'Delete SIP Settings', img: "images/icons/developers.jpg" },
			mapchanneltodid: {ref: '#mapchanneltodid', 'text': 'Inward Dialing', img: "images/icons/developers.jpg" }
		} },
		billing: {ref:'api/billingchargingcdrapi.html', 'text': 'Billing, Charging & CDR', img: "images/icons/developers.jpg", child: {
			getcdr: {ref: '#getcdr', 'text': 'Get Call Records', img: "images/icons/developers.jpg" },
			getfile: {ref: '#getfile', 'text': 'Retrieve Saved File', img: "images/icons/developers.jpg" },
			setnotifyurl: {ref: '#setnotifyurl', 'text': 'Set Notification URL', img: "images/icons/developers.jpg" },
			setphonecredits: {ref: '#setphonecredits', 'text': 'Setting Phone Credits', img: "images/icons/developers.jpg" },
			buysipcredits: {ref: '#buysipcredits', 'text': 'Buy SIP Credits', img: "images/icons/developers.jpg" },
			getrates: {ref: '#getrates', 'text': 'Get Phone & SMS Rates', img: "images/icons/developers.jpg" },
			getrate: {ref: '#getrate', 'text': 'Get Phone/SMS Rates', img: "images/icons/developers.jpg" }
		} },
		rtsn: {ref:'api/realtimenotificationsapi.html', 'text': 'Real-time Notifications', img: "images/icons/developers.jpg" }
	};

	sideNavigation(elId, active, nav_obj);
}

function addNextLink(nav_obj, active) {

	var keys = Object.keys(nav_obj);
	var showNext = true;
	var lastKey = null;
	for(var i=0; i<keys.length; i++) {
		if(active==keys[i] && (keys.length-1)==i) {
			showNext = false;
			lastKey = keys[i];
			break;
		}
	}
	if(null==lastKey) {
		lastKey = keys[keys.length - 1];
		keys = Object.keys(nav_obj[lastKey].child);
		for(var i=0; i<keys.length; i++) {
			if(active==keys[i]) {
				showNext = false;
				lastKey = keys[i];
				break;
			}
		}
	}

	if($('dynamic-content') && showNext) {
		var nextLink = new Element('a', { id: "next", 'class': "next", href: "", text: "Next"});
		var nextImg = new Element('img', { src: "images/arrow_right_org.png"});
		nextImg.inject(nextLink);
		nextLink.addEvent('click', ShowPage);
		nextLink.inject($('dynamic-content'));
	}
}
