
/*
 * Superfish v1.4.8 - jQuery menu widget
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 */

;(function($){
	$.fn.superfish = function(op){

		var sf = $.fn.superfish,
			c = sf.c,
			$arrow = $(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
			over = function(){
				var $$ = $(this), menu = getMenu($$);
				clearTimeout(menu.sfTimer);
				$$.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function(){
				var $$ = $(this), menu = getMenu($$), o = sf.op;
				clearTimeout(menu.sfTimer);
				menu.sfTimer=setTimeout(function(){
					o.retainPath=($.inArray($$[0],o.$path)>-1);
					$$.hideSuperfishUl();
					if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}
				},o.delay);	
			},
			getMenu = function($menu){
				var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
				sf.op = sf.o[menu.serial];
				return menu;
			},
			addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); };
			
		return this.each(function() {
			var s = this.serial = sf.o.length;
			var o = $.extend({},sf.defaults,op);
			o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){
				$(this).addClass([o.hoverClass,c.bcClass].join(' '))
					.filter('li:has(ul)').removeClass(o.pathClass);
			});
			sf.o[s] = sf.op = o;
			
			$('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
				if (o.autoArrows) addArrow( $('>a:first-child',this) );
			})
			.not('.'+c.bcClass)
				.hideSuperfishUl();
			
			var $a = $('a',this);
			$a.each(function(i){
				var $li = $a.eq(i).parents('li');
				$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
			});
			o.onInit.call(this);
			
		}).each(function() {
			var menuClasses = [c.menuClass];
			if (sf.op.dropShadows  && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
			$(this).addClass(menuClasses.join(' '));
		});
	};

	var sf = $.fn.superfish;
	sf.o = [];
	sf.op = {};
	sf.IE7fix = function(){
		var o = sf.op;
		if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity!=undefined)
			this.toggleClass(sf.c.shadowClass+'-off');
		};
	sf.c = {
		bcClass     : 'sf-breadcrumb',
		menuClass   : 'sf-js-enabled',
		anchorClass : 'sf-with-ul',
		arrowClass  : 'sf-sub-indicator',
		shadowClass : 'sf-shadow'
	};
	sf.defaults = {
		hoverClass	: 'sfHover',
		pathClass	: 'overideThisToUse',
		pathLevels	: 1,
		delay		: 800,
		animation	: {opacity:'show'},
		speed		: 'normal',
		autoArrows	: true,
		dropShadows : true,
		disableHI	: false,		// true disables hoverIntent detection
		onInit		: function(){}, // callback functions
		onBeforeShow: function(){},
		onShow		: function(){},
		onHide		: function(){}
	};
	$.fn.extend({
		hideSuperfishUl : function(){
			var o = sf.op,
				not = (o.retainPath===true) ? o.$path : '';
			o.retainPath = false;
			var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
					.find('>ul').hide().css('visibility','hidden');
			o.onHide.call($ul);
			return this;
		},
		showSuperfishUl : function(){
			var o = sf.op,
				sh = sf.c.shadowClass+'-off',
				$ul = this.addClass(o.hoverClass)
					.find('>ul:hidden').css('visibility','visible');
			sf.IE7fix.call($ul);
			o.onBeforeShow.call($ul);
			$ul.animate(o.animation,o.speed,function(){ sf.IE7fix.call($ul); o.onShow.call($ul); });
			return this;
		}
	});

})(jQuery);
$.DD_belatedPNG = (function ($) {
	var doc = document, ie = (!window.opera && (ie = navigator.userAgent.match(/MSIE (\d)/))) ? parseInt(ie[1].replace('5', '6'), 10) : false, nameSpace = 'DD_belatedPNG';
	if (!ie) {
		return {
			fixPng: function () {
				return true;
			}
		};
	}

	if (doc.namespaces && !doc.namespaces[nameSpace]) {
		doc.namespaces.add(nameSpace, 'urn:schemas-microsoft-com:vml');
	}

	return {
		resize: function (elem) {
			this.updateVmlDimensions(elem);
		},

		interceptPropertyChanges: function (elem) {
			if (/background/.test(event.propertyName)) {
				this.updateVmlFill(elem);
			}
		},

		handlePseudoHover: function (elem) {
			var self = this;

			setTimeout(function () {
				elem.runtimeStyle.backgroundColor = '';
				elem.runtimeStyle.backgroundImage = '';
				self.updateVmlFill(elem);
			}, 1);
		},

		fixPng: function (elem) {
			var bgSizeFinderStyle, each, elemName = elem.nodeName, handlers = {
				propertychange: 'interceptPropertyChanges',
				resize: 'resize',
				move: 'resize'
			}, moreForAs = {
				mouseleave: 'handlePseudoHover',
				mouseenter: 'handlePseudoHover',
				focus: 'handlePseudoHover',
				blur: 'handlePseudoHover'
			}, onHandler = function () {
				self[handlers[each]](elem);
			}, self = this;

			elem.style.behavior = 'none';
			if (/^(BODY|TR|TD)$/.test(elemName)) {
				return;
			}
			elem.bgSizeFinder = doc.createElement('IMG');
			bgSizeFinderStyle = elem.bgSizeFinder.style;
			bgSizeFinderStyle.position = 'absolute';
			bgSizeFinderStyle.top = '-10000px';
			bgSizeFinderStyle.visibility = 'hidden';
			bgSizeFinderStyle.zIndex = -1;
			elem.bgSizeFinder.attachEvent('onload', function () {
				self.updateVmlDimensions(elem);
			});
			doc.body.insertBefore(elem.bgSizeFinder, doc.body.firstChild);
			elem.imgRect = doc.createElement(nameSpace + ':rect');
			elem.imgRect.style.position = 'absolute';
			elem.imgFill = doc.createElement(nameSpace + ':fill');
			elem.colorRect = doc.createElement(nameSpace + ':rect');
			elem.colorRect.style.position = 'absolute';
			elem.rects = [elem.imgRect, elem.colorRect];
			for (each = 0; each < 2; each++) {
				elem.rects[each].stroked = false;
			}
			elem.parentNode.insertBefore(elem.colorRect, elem);
			elem.imgRect.appendChild(elem.imgFill);
			elem.parentNode.insertBefore(elem.imgRect, elem);
			elem.imgRect.addBehavior('#default#VML');
			elem.imgFill.addBehavior('#default#VML');
			elem.colorRect.addBehavior('#default#VML');
			if (elemName === 'A') {
				for (each in moreForAs) {
					handlers[each] = moreForAs[each];
				}
			}
			for (each in handlers) {
				elem.attachEvent('on' + each, onHandler);
			}
			self.updateVmlFill(elem);
		},

		updateVmlFill: function (elem) {
			var bAtts = {
				Style: true,
				Width: true,
				Color: true
			}, bg, each, elemName = elem.nodeName, elemStyle = elem.currentStyle, giveLayout = function (elem) {
				elem.style.zoom = 1;
				if (elem.currentStyle.position === 'static') {
					elem.style.position = 'relative';
				}
			}, knownZ;

			if (elemStyle.backgroundImage) {
				knownZ = (elemStyle.zIndex !== '0') ? elemStyle.zIndex : -1;
				elem.colorRect.style.zIndex = knownZ;
				elem.imgRect.style.zIndex = knownZ;
				giveLayout(elem);
				giveLayout(elem.parentNode);
				bg = elemStyle.backgroundImage.split('"')[1];
			}
			if (elem.src) {
				bg = elem.src;
			}
			if (elemStyle.backgroundImage || elem.src) {
				elem.bgSizeFinder.src = bg;
				elem.imgFill.src = bg;
				elem.imgFill.type = 'tile';
			}
			elem.imgRect.filled = true;
			elem.colorRect.filled = false;
			elem.colorRect.style.backgroundColor = elemStyle.backgroundColor;
			elem.runtimeStyle.backgroundImage = 'none';
			elem.runtimeStyle.backgroundColor = 'transparent';
			if (elemName === 'IMG') {
				if (elemStyle.position === 'static') {
					elem.style.position = 'relative';
				}
				for (each in bAtts) {
					elem.imgRect.style['border' + each] = elemStyle['border' + each];
					elem.colorRect.style['border' + each] = elemStyle['border' + each];
				}
				elem.width = elem.clientWidth;
				elem.height = elem.clientHeight;
				elem.style.visibility = 'hidden';
			}
		},

		updateVmlDimensions: function (elem) {
			var altC = {
				X: {
					b1: 'L',
					b2: 'R',
					d: 'W'
				},
				Y: {
					b1: 'T',
					b2: 'B',
					d: 'H'
				}
			}, bg = {
				X: 0,
				Y: 0
			}, bgR, corner, dC, each, elemName = elem.nodeName, elemStyle = elem.currentStyle, fraction = true, horz, position, size, v;

			size = {
				W: elem.clientWidth,
				H: elem.clientHeight,
				w: elem.bgSizeFinder.width,
				h: elem.bgSizeFinder.height,
				L: elem.offsetLeft,
				T: elem.offsetTop,
				bLW: parseInt(elemStyle.borderLeftWidth, 10),
				bTW: parseInt(elemStyle.borderTopWidth, 10)
			};
			if (isNaN(size.bLW) || elemName === 'IMG') {
				size.bLW = 0;
			}
			if (isNaN(size.bTW) || elemName === 'IMG') {
				size.bTW = 0;
			}
			if (size.W >= doc.body.clientWidth) {
				--size.W;
			}
			for (each = 0; each < 2; each++) {
				elem.rects[each].style.width = size.W + 'px';
				elem.rects[each].style.height = size.H + 'px';
				elem.rects[each].style.left = (size.L + size.bLW) + 'px';
				elem.rects[each].style.top = (size.T + size.bTW) + 'px';
			}
			for (each in bg) {
				position = elemStyle['backgroundPosition' + each];
				switch (position) {
				case 'left':
				case 'top':
					bg[each] = 0;
					break;
				case 'center':
					bg[each] = 0.5;
					break;
				case 'right':
				case 'bottom':
					bg[each] = 1;
					break;
				default:
					if (/%/.test(position)) {
						bg[each] = parseInt(position, 10) * 0.01;
					}
					else {
						fraction = false;
					}
				}
				horz = (each === 'X');
				bg[each] = Math.ceil(fraction ? ((size[horz ? 'W' : 'H'] * bg[each]) - (size[horz ? 'w': 'h'] * bg[each])) : parseInt(position, 10));
			}
			elem.imgFill.position = (bg.X / size.W) + ',' + (bg.Y / size.H);
			bgR = elemStyle.backgroundRepeat;
			dC = {
				T: 0,
				R: size.W,
				B: size.H,
				L: 0
			};
			if (bgR !== 'repeat') {
				corner = {
					T: bg.Y,
					R: bg.X + size.w + ((size.bLW === 0) ? 1 : 0),
					B: bg.Y + size.h,
					L: bg.X + ((size.bLW === 0) ? 1 : 0)
				};
				if (/repeat-/.test(bgR)) {
					v = bgR.split('repeat-')[1].toUpperCase();
					corner[altC[v].b1] = 0;
					corner[altC[v].b2] = size[altC[v].d];
				}
				elem.imgRect.style.clip = 'rect(' + [corner.T, corner.R, corner.B, corner.L, ''].join('px ') + ')';
			}
			else {
				elem.imgRect.style.clip = 'rect(auto)';
			}
		}
	};
}(jQuery));

$.fn.DD_belatedPNG = (function ($) {
	return function () {
		var $each, each = 0;
		while (($each = this.eq(each++))[0]) {
			if ($.browser.msie) {
				$each[0].setExpression('behavior', $.DD_belatedPNG.fixPng($each[0]));
			}
		}	
	};
}(jQuery));
