(function($) {
  var currentRadius, multiplier;

  function parseOptions(options) {
    return {
      RADIUS:     (options.radius    || 20),
      DURATION:   (options.duration  || 500),
      TEXT_COLOR: (options.textColor || '#fff'),
      HALO_COLOR: (options.haloColor || '#777')
    }
  }

  function currentRadius(elem) {
    if (prop = elem.style['text-shadow']) {
      return parseInt(prop.match(/0 0 (\d+)px/));
    } else {
      return 0;
    }
  }

  function stepTextShadow(fx) {
    if (fx.state == 0) {
      fx.start = currentRadius(fx.elem);
    }

    updatedRadius = fx.end.begin ?
      parseInt(fx.end.radius * fx.pos) :
      parseInt(fx.end.radius - (fx.end.radius * fx.pos))

    if (fx.end.begin || (fx.state < 1)) {
      $(fx.elem).css('text-shadow', fx.end.color + ' 0 0 ' + updatedRadius + 'px');
    } else {
      $(fx.elem).css('text-shadow', $(fx.elem).data('glow.originalGlow'));
    }
  }

  function addGlow(opts) {
    var opts = parseOptions(opts || { });

    function startGlow() {
      $(this).stop().animate({
        color: opts.TEXT_COLOR,
        textShadow: {
          begin: true,
          color: opts.HALO_COLOR,
          radius: opts.RADIUS
        }
      }, opts.DURATION);
    }

    function startFade() {
      $(this).stop().animate({
        color: $(this).data('glow.originColor'),
        textShadow: {
          begin: false,
          color: opts.HALO_COLOR,
          radius: opts.RADIUS
        }
      }, opts.DURATION);
    }

    with($(this)) {
      bind('mouseenter', startGlow);
      bind('mouseleave', startFade);
      data('glow.originColor', css('color'));
      data('glow.originalGlow', (css('text-shadow') || 'none'));
    }

    return this;
  }

  $.fx.step['textShadow'] = stepTextShadow;
  $.fn.addGlow = addGlow;
})(jQuery);

(function(jQuery) {
/*
 * jQuery Color Animations
 * Copyright 2007 John Resig
 * Released under the MIT and GPL licenses.
 */

// We override the animation for all of these color styles
jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
		jQuery.fx.step[attr] = function(fx){
				if ( fx.state == 0 ) {
						fx.start = getColor( fx.elem, attr );
						fx.end = getRGB( fx.end );
				}

				fx.elem.style[attr] = "rgb(" + [
						Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
						Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
						Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
				].join(",") + ")";
		}
});

// Color Conversion functions from highlightFade
// By Blair Mitchelmore
// http://jquery.offput.ca/highlightFade/

// Parse strings looking for color tuples [255,255,255]
function getRGB(color) {
		var result;

		// Check if we're already dealing with an array of colors
		if ( color && color.constructor == Array && color.length == 3 )
				return color;

		// Look for rgb(num,num,num)
		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
				return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];

		// Look for rgb(num%,num%,num%)
		if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
				return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];

		// Look for #a0b1c2
		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
				return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];

		// Look for #fff
		if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
				return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];

		// Look for rgba(0, 0, 0, 0) == transparent in Safari 3
		if (result = /rgba\(0, 0, 0, 0\)/.exec(color))
				return colors['transparent']

		// Otherwise, we're most likely dealing with a named color
		return colors[jQuery.trim(color).toLowerCase()];
}

function getColor(elem, attr) {
		var color;

		do {
				color = jQuery.curCSS(elem, attr);

				// Keep going until we find an element that has color, or we hit the body
				if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
						break;

				attr = "backgroundColor";
		} while ( elem = elem.parentNode );

		return getRGB(color);
};

// Some named colors to work with
// From Interface by Stefan Petre
// http://interface.eyecon.ro/

var colors = {
	aqua:[0,255,255],
	azure:[240,255,255],
	beige:[245,245,220],
	black:[0,0,0],
	blue:[0,0,255],
	brown:[165,42,42],
	cyan:[0,255,255],
	darkblue:[0,0,139],
	darkcyan:[0,139,139],
	darkgrey:[169,169,169],
	darkgreen:[0,100,0],
	darkkhaki:[189,183,107],
	darkmagenta:[139,0,139],
	darkolivegreen:[85,107,47],
	darkorange:[255,140,0],
	darkorchid:[153,50,204],
	darkred:[139,0,0],
	darksalmon:[233,150,122],
	darkviolet:[148,0,211],
	fuchsia:[255,0,255],
	gold:[255,215,0],
	green:[0,128,0],
	indigo:[75,0,130],
	khaki:[240,230,140],
	lightblue:[173,216,230],
	lightcyan:[224,255,255],
	lightgreen:[144,238,144],
	lightgrey:[211,211,211],
	lightpink:[255,182,193],
	lightyellow:[255,255,224],
	lime:[0,255,0],
	magenta:[255,0,255],
	maroon:[128,0,0],
	navy:[0,0,128],
	olive:[128,128,0],
	orange:[255,165,0],
	pink:[255,192,203],
	purple:[128,0,128],
	violet:[128,0,128],
	red:[255,0,0],
	silver:[192,192,192],
	white:[255,255,255],
	yellow:[255,255,0],
	transparent: [255,255,255]
};
})(jQuery);

$(function(){
$(".AspNet-Menu-Horizontal ul").hide();
$(".AspNet-Menu-Horizontal ul.sf-menu").show();
$(".AspNet-Menu-Horizontal ul.sf-menu").lavaLamp({ fx: "backout", speed: 700 });
$(".AspNet-Menu-Horizontal ul.sf-menu>li").hover(
	function(){
		if($(this).children("ul").is(":visible")){ $(".AspNet-Menu-Horizontal ul").hide();
			$(".AspNet-Menu-Horizontal ul.sf-menu").show();
			$(this).children("ul").animate({opacity: "show", height: "show"},"fast");}
		else{ $(this).children("ul").animate({opacity: "show", height: "show"},"fast"); }
	},function(){
		$(".AspNet-Menu-Horizontal ul").hide();
		$(".AspNet-Menu-Horizontal ul.sf-menu").show();
	});
if($.browser.msie){
	$(".AspNet-Menu-Horizontal ul.sf-menu li ul li.sf-with-ul").hover(
		function(){
			$(this).children("ul").css({left: "50"}); 
			$(this).children("ul").animate({opacity: "show", left: 0}, "fast");
		},function(){
			$(this).children("ul").animate({opacity: "hide", left: +50}, "fast");
		});
}else {
	$(".AspNet-Menu-Horizontal ul.sf-menu li ul li.sf-with-ul").hover(
		function(){
			if($(this).children("ul").offset().left===0){ $(this).children("ul").offset( {left: +50} );}
			$(this).children("ul").animate({opacity: "show", left: 0}, "fast");
		},function(){
			$(this).children("ul").animate({opacity: "hide", left: +50}, "fast");
		});
}
if($.browser.msie){
	$(".AspNet-TreeView .AspNet-TreeView-Root>a").each(function(){
		var aText = $(this);
		$(".AspNet-Menu-Horizontal li.sf-with-ul>a").each(function(){
			var bHtml = $(this);
			var textAuxA = jQuery.trim(aText.text());
			var textAuxB = jQuery.trim($(this).text());
			if(textAuxA == textAuxB){
				aText.parent("li").html(bHtml.parent("li").html());
			}
		})
	});
	$(".AspNet-TreeView ul ul").each(function(){
		$(this).css({display: "block"});
		$(this).css({visibility: "hidden"});
		$(this).css({position: "absolute"});
	});
	$(".AspNet-TreeView ul ul ul").addClass("2lvl");
}else{
	$(".AspNet-TreeView .AspNet-TreeView-Root>a").each(function(){
		var aText = $(this);
		$(".AspNet-Menu-Horizontal li.sf-with-ul>a").each(function(){
			var textAuxA = jQuery.trim(aText.text());
			var textAuxB = jQuery.trim($(this).text());
			if(textAuxA == textAuxB){
				aText.parent().html($(this).parent().html());
			}
		})
	});
}
//removeClass().addClass("AspNet-TreeView-Parent");

/*
$(".AspNet-TreeView .AspNet-TreeView-Root>a").each(function(){
	$(this).html("<span>&nbsp;</span>" + $(this).text());
});

$(".AspNet-TreeView .AspNet-TreeView-Parent>a").each(function(){
	$(this).html("<span>&nbsp;</span>" + $(this).text());
});*/



if($.browser.msie){
	$(".AspNet-TreeView ul>li").hover(function(){
		var child = $(this).children("ul");
		var lis = $(this).children("ul").children("li");
		var padding = 0 + parseInt(lis.css("padding-top")) + parseInt(lis.css("padding-bottom")) ;
		var childrenheight =  0;
		var totalHeight = 0;
		
		child.stop(true,true);
		child.clearQueue();
		
		child.css({display: "block"});
		child.css({visibility: "hidden"});
		child.css({position: ""});
		lis.each(function(){
			childrenheight = $(this).height();
			totalHeight += childrenheight + padding;
		});
		var spanHeight = parseInt(child.parent("li").children("span.node").height());
		child.css({display: "none"});
		child.css({visibility: "visible"});
		if(child.hasClass("2lvl")){
			child.parent("li").parent("ul").animate({opacity: "1",height: (child.parent("li").parent("ul").height() + totalHeight + spanHeight) }, 200);
			child.animate({opacity: "1",height: totalHeight}, 200, function() {
				$(this).parent().find(">span.node").addClass("nodeOpen");
			});	
		} else {
			child.delay(500).animate({opacity: "1",height: totalHeight}, 200, function() {
				$(this).parent().find(">span.node").addClass("nodeOpen");
			});
		}
	},function(){
		var child = $(this).children("ul");
		
		child.stop(true,true);
		child.clearQueue();

		var childHeight = child.height();
		var parentHeight = child.parent("li").parent("ul").height();
		var spanHeight  = child.parent("li").children("span.node").height();
		child.hide();
		child.parent().find(">span.node").removeClass("nodeOpen");
		if(child.hasClass("2lvl")){
			child.parent("li").parent("ul").animate({opacity: "1",height: parentHeight - childHeight - spanHeight}, 200);
		}
		
	});
}else {
	$(".AspNet-TreeView ul>li").hover(function(){
	$(this).children("ul").delay(500).animate({opacity: "show",height: "show"}, 200, function() {
		$(this).parent().find(">span.node").addClass("nodeOpen");
	});},function(){
		$(this).children("ul").stop(true, true);
		$(this).children("ul").animate({opacity: "hide",height: "hide"}, 200).parent().find(">span.node").removeClass("nodeOpen");
	});
}

$(".AspNet-TreeView ul>li").each(function(){
	if(!$(this).hasClass("AspNet-TreeView-Leaf"))
	{
		if($(this).hasClass("AspNet-TreeView-Root"))
			$(this).append('<span class="node">&nbsp;&nbsp;&nbsp;&nbsp;</span>');
	};
	
	if($(this).hasClass("sf-with-ul"))
	{
		$(this).append('<span class="node">&nbsp;&nbsp;&nbsp;&nbsp;</span>');
	}
	
});

$(".AspNet-TreeView a").addGlow({  textColor: '#ffffff', haloColor: '#ffffff', radius: 8, duration: 200 });

});
