/*
 * Superfish - jQuery menu widget
 *
 * Copyright (c) 2007 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
 *
 */

(function($){
	$.fn.superfish = function(o){
		var defaults = {
			hoverClass	: "sfHover",
			delay		: 500,
			animation	: {opacity:"show"},
			speed		: "fast"
		},
			over = function(){
				var $$ = $(this);
				clearTimeout(this.sfTimer);
				if (!$$.is("."+o.hoverClass)) {
					$$.addClass(o.hoverClass)
						.find("ul")
							.animate(o.animation,o.speed)
							.end()
						.siblings()
						.removeClass(o.hoverClass);
				}
			},
			out = function(){
				var $$ = $(this);
				this.sfTimer=setTimeout(function(){
					$$.removeClass(o.hoverClass)
					.find("iframe", this)
						.remove();
				},o.delay);
			};
		o = $.extend(defaults, o || {});
		var sfHovAr=$("li",this)
			.hover(over,out)
			.find("a").each(function() {
				var $a = $(this), $li = $a.parents("li");
				$a.focus(function(){ $li.each(over); })
				  .blur(function(){ $li.each(out); });
			}).end();
		$(window).unload(function() {
			sfHovAr.unbind("mouseover").unbind("mouseout");
		});
		return this;
	};
})(jQuery);

	$.fn.bgIframe = $.fn.bgiframe = function(o) {
		// This is only for IE6
		if ( !($.browser.msie && typeof XMLHttpRequest == 'function') ) return this;
		o = $.extend({
			top     : 'auto', // auto == .currentStyle.borderTopWidth
			left    : 'auto', // auto == .currentStyle.borderLeftWidth
			width   : 'auto', // auto == offsetWidth
			height  : 'auto', // auto == offsetHeight
			opacity : true,
			src     : 'javascript:false;'
		}, o || {});
		var prop = function(n){return n&&n.constructor==Number?n+"px":n;},
		    html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+o.src+'"'+
		               'style="display:block;position:absolute;z-index:-1;'+
			               (o.opacity !== false?'filter:Alpha(Opacity=\'0\');':'')+
					       'top:'+(o.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(o.top))+';'+
					       'left:'+(o.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(o.left))+';'+
					       'width:'+(o.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(o.width))+';'+
					       'height:'+(o.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(o.height))+';'+
					'"/>';
		return this.each(function() {
			if ( !$('iframe.bgiframe', this)[0] )
				this.insertBefore( document.createElement(html), this.firstChild );
		});
	};
	
$(document).ready(function(){

			$("#menu ul")
			.superfish({
				animation : { opacity:"show",height:"show"}
			})
			.find(">li[ul]")
				.mouseover(function(){
					$("ul", this).bgIframe({opacity:false});
				})
				.find("a")
					.focus(function(){
						$("ul", $(".nav>li[ul]")).bgIframe({opacity:false});
					});
					
});


 (function($){
$.fn.selectCombo = function(url, target, settings){
var defaults = {hidetarget: true, indicator: false, pageload: false};
$.extend(defaults, settings);
return this.each(function(){
var qobj = this;
var targetlabel = target.replace(/#/, '');
	targetlabel = "label[@for='" + targetlabel + "']";

if(defaults.indicator != false)
	$(defaults.indicator).hide();
	
hidetargetinfo = function(){
	if($(qobj).attr('id') != $(target).attr('id')){
		$(targetlabel).hide();
		$(target).hide();
	}
}
if(defaults.hidetarget && ($(target).val() == '' || $(target).val() == null))
	hidetargetinfo();
loadOptions = function(){
	qval = $(qobj).val();
	if(defaults.indicator != false)
		$(defaults.indicator).show();
	if($(qobj).attr('id') != $(target).attr('id'))
		$(target).empty();
	$.getJSON(url, {item: qval}, function(j){
		var setoptions = '';
		if(j.length > 0){
			for (var i = 0; i < j.length; i++) 
				setoptions += '<option value="' + j[i].oV + '">' + j[i].oT + '</option>';
			$(target).html(setoptions);
			$("option:first", target).attr("selected","selected");
			$(targetlabel).show();
			$(target).show();
		}
		else if(defaults.hidetarget){
			hidetargetinfo();
			$(target).html(setoptions);
		}
		if(defaults.indicator != false)
			$(defaults.indicator).hide();
	});//end JSON
}

$(this).change(loadOptions);//end change fn

if(defaults.pageload && $(qobj).val() != ''){
	loadOptions();
}

});//end return for each
}
})(jQuery);

