﻿/// <reference path="jquery/jquery-1.3.2-vsdoc2.js"/>

$(document).ready(function() {
	/*
	Settings for curvy corners
	*/
	var settings = {
		tl: { radius: 20 },
		tr: { radius: 20 },
		bl: { radius: 20 },
		br: { radius: 20 },
		antiAlias: true,
		autoPad: false,
		validTags: ['div']
	}
	curvyCorners(settings, '#backBody');
	curvyCorners(settings, '#backGrad');
	settings.tl = { radius: 5 };
	settings.tr = { radius: 5 };
	settings.bl = { radius: 5 };
	settings.br = { radius: 5 };
	/*
	$('#searchbox_demo :text, #searchbox_demo :submit').css({ 'background': '#fff' });
	$('#searchbox_demo').css('width', '100%').css('text-align', 'right');
	$('#searchbox_demo div').css({ 'float': 'right', 'margin-left': '.5em' });
	//curvyCorners(settings, '#searchbox_demo input[type="submit"]');
	*/
	var depth = document.URL.lastIndexOf(document.domain) + document.domain.length + 1;
	var slashCount = document.URL.substring(depth).replace('crimson/', '').split('/').length - 1;
	ajaxMenu.pathDepth = '';
	for (i = 0; i < slashCount; ++i) ajaxMenu.pathDepth += '../';
	/*
	Unfortunately, curvy corners mess up drop down menus
	so will need to download the menu and then append it
	higher in the food chain so that it will show up.
	*/
	$.ajax({
		type: 'GET',
		url: ajaxMenu.pathDepth + 'menu.aspx',
		dataType: 'html',
		timeout: 10000,
		success: ajaxMenu.construct
	});
});

var ajaxMenu = {
	pathDepth: '',
	construct: function(data, status) {
		var oldMenu = $('#backMenu');
		oldMenu.remove();

		data = data.replace(/href=\"/g, 'href=\"' + ajaxMenu.pathDepth);

		$('#back').append('<div id="backMenu">' + data + '</div>');
		var style = {
			'float': 'none',
			'left': $('#topLogo').offset().left + $('#topLogo').width(),
			'padding': '0 0 0 1em',
			'position': 'absolute',
			'top': $.browser.msie ? '46px' : '48px'
		};
		$('#backMenu').css(style);
		ajaxMenu.setEvents();
		//debug();
		$('#debug').css('display', 'none');
	},
	/*
	Now that the menu is built, wire up the events
	*/
	setEvents: function() {
		$('#backMenu ul li').hover(
		//Enter
		function(ev) {
			var top = $(this).position().top + 14;
			var left = $(this).position().left;
			var style = {
				'background-color': '#405464',
				'left': left + 'px',
				'top':top + 'px',
				'position': 'absolute'
			}

		$('ul', $(this)).each(function() {
			$(this).css(style);
			$(this).fadeIn('500');
		});
	},
	//Out
		function(ev) {
			$(this).children('ul:eq(0)').fadeOut('10');
		});
}
}
