﻿/// <reference path="../jquery/jquery-1.3.2.js" />
/// <reference path="../jquery/jquery-1.3.2-vsdoc.js" />

RampUp.GetTabs = function(tabID)
{
	//RampUp.PageMethod("/webservices/DataService.asmx/GetTabs", jQuery.toJSON({}),
	RampUp.PageMethod("/webservices/DataService.asmx/GetNonCachedTabs", jQuery.toJSON({}),
	function(result) // Callback
	{
		//alert(result);
		RampUp.TabInfo = {};
		if (result.d === undefined)
			RampUp.TabInfo = eval('(' + result + ')');
		else
			RampUp.TabInfo = eval('(' + result.d + ')');
	}, false);
};

RampUp.BindMenu = function()
{
	var qs = (window.location.toString()).split("/");
	RampUp.ActiveTab = qs[3];
	var lastSubTab = "", currentSubTab = RampUp.ActiveTab;

	for (var i = 0; i < RampUp.TabInfo.length; i++)
	{
		var t = RampUp.TabInfo[i];
		findActiveTab();
		buildMenu();
		bindFooter();
	}

	jQuery('#menuCont #menu li').each(function()
	{
		jQuery(this).find('ul').append('<li class="lastLI" style="height:0px; width:160px; margin-left:-10px"></li>');
	});

	function bindFooter()
	{
		jQuery('#footer li').each(function()
		{
			if (this.id == t.TabName && t.OrderNum < 2)
				jQuery('#' + this.id).find(' a').attr('href', '/' + t.TabName + '/tabid/' + t.DnnTabID + '/Default.aspx');

			if (this.id == 'copyright')
				jQuery('#dlgCopyright').text(t.Desc);
		});
	};

	function buildMenu()
	{
		jQuery('#menuCont > #menu > li').each(function()
		{
			if (this.id == t.TabName)
			{
				jQuery(this).find('a:first').attr('href', '/' + t.TabName + '/tabid/' + t.DnnTabID + '/Default.aspx');
				buildSubNav(this.id);
			}
		});
	};

	function buildSubNav(id)
	{
		if (t.SubTabName !== null)
		{
			if (i > 1 && t.SubTabName == RampUp.TabInfo[i - 1].SubTabName) { return; }

			var html = '<li style="display: list-item; height: 17px;"><a href="/' + t.TabName + '/tabid/' + t.DnnTabID + '/Default.aspx?s=' + t.SubTabName + '">' + t.SubTabName + '</a></li>';
			jQuery('#menuCont #' + id).find('.down-list').append(html);
		}
		else
			jQuery('#' + id).find('.down-list').remove();
	};

	function findActiveTab()
	{
		if (RampUp.ActiveTab == t.TabName)
		{
			switch (RampUp.ActiveTab)
			{
				case 'tech':
				case 'hosting':
				case 'devel':
				case 'staff':
					jQuery('#menuCont > #menu #' + t.TabName).addClass('active');
					break;
			}
		}
	};
};

jQuery(document).ready(function()
{
	var h = jQuery('#mainCont').height();
	jQuery('#footer').css('top', (h-50).toString() + 'px');

	/* Registrations */

	jQuery('#dlgCopyright').dialog(
	{
		autoOpen: false,
		bgiframe: true,
		resizable: false,
		modal: true,
		width: 500,
		height: 300,
		buttons: {
			"Ok": function()
			{
				jQuery(this).dialog('close');
			}
		}
	});

	/* Events */

	jQuery('#copyright').live('click', function()
	{
		jQuery('#dlgCopyright').dialog('open');
	});

	jQuery('#logo').click(function()
	{
		window.location = "/";
	});

	jQuery('#menu > li').hover(
	  function()
	  {
	  	jQuery('.down-list', this).slideDown(100);
	  },
	  function()
	  {
	  	jQuery('.down-list', this).slideUp(100);
	  }
	);
});