function showR()
{
	document.getElementById('resourcesSearch').style.display = '';
	document.getElementById('findAttorneyBar').style.display = 'none';
	document.getElementById('aTab').className = 'attTab2';
	document.getElementById('rTab').className = 'reTab';

}
function showA()
{
	document.getElementById('resourcesSearch').style.display = 'none';
	document.getElementById('findAttorneyBar').style.display = '';
	document.getElementById('aTab').className = 'attTab';
	document.getElementById('rTab').className = 'reTab2';
}
function showR2()
{
	document.getElementById('qs').className = 'inactive';
	document.getElementById('rs').className = 'active';
	document.getElementById('qualified-search').className = 'inactive';
	document.getElementById('resource-search').className = 'active';
}
function showA2()
{
	document.getElementById('qs').className = 'active';
	document.getElementById('rs').className = 'inactive';
	document.getElementById('qualified-search').className = 'active';
	document.getElementById('resource-search').className = 'inactive';
}


document.getElementsByTagName("html")[0].className = "js"; // provide a class to check for js existence in CSS
var LawInfo = {};
(function(law, $) { // using function scope
    /*
        Accordion
        Maybe should go into the homepage.js file?
    */
    function Accordion(h, d, options) {
        var h = h, d = $(d), self = this;
		var foo;
        var rel = options.rel || "sibling";
        var start = typeof(options.start) != "undefined" ? options.start : null;
		var linkclicked = false;
		h.each(function() {
			$(this).bind("click.accordion", function(e) {
				if(!linkclicked) {
				self.openn(this);
				}
				linkclicked = false;
			});
			$(this).children('ul').children('li').children('a').bind('click',function() {
				linkclicked = true;
			});
		});
        // methods
        this.openn = function(elem) {
            var elem = rel == "parent" ?  elem.parentNode : elem;
            var data = $("#" + elem.id + "-data");
            if (data.hasClass("active")) {
                this.close();
				if(elem.id == 'how-to') { // remove flash player
					data.empty();
				}
                return true; // allow links to work
            }
			if(elem.id == 'how-to') { // add flash player
				foo = new SWFObject('/vids/demo-xml.swf', '', '878', '345', '4', '#FFFFFF');
				foo.addParam('wmode', 'transparent');
				foo.write('how-to-data');
			}
            this.close();
            data.slideDown().addClass("active");
            $(elem).removeClass("open").addClass("close");
        };
        this.close = function() {
            $(".active").slideUp().removeClass("active");
            $('.close').removeClass("close").addClass("open");
        };
        if (start !== null) {
            this.open(h[start]);
        };
        return;
    }
    
    /*
        TABS
    */
    function Tabs (tabs, contentselector) {
        var self = this,
            tabs = tabs,
            content = $(contentselector),
            cn = "inactive";
            
        var activeTab = tabs.not(".inactive"),
            activeContent = content.not(".inactive");
            
        tabs.bind("click.tabs", function(e) {
            this.blur();
            if (this == activeTab[0]) {
                return false;
            }
            var hash;
            if (!e.target.href) {
                hash = $(e.target).parent("[href]").attr("href").split("#")[1];
            }else {
                hash = e.target.href.split("#")[1];
            }
            // activate
            activeTab.addClass(cn);
            activeContent.addClass(cn);
            // deactiveate
            activeTab = $(this).removeClass(cn);
            activeContent = $("#" + hash).removeClass(cn);
            return false; // prevent default
        });
        
        return tabs;
    }
    $.extend($.fn, { // put things you will want to use publicly here
        accordion: function(d, options) {
            return Accordion(this, d, options);
        },
        tabs: function(content) {
            return Tabs(this, content);
        }
    });
    
    /* quick jQuery plugin to put the label value into a form element */
    $.fn.label = function() {
        return this.each(function() {
            var input = $(this),
                label = $("label[for=" + this.id + "]").hide(); // select the proper label element and hide.
            input
                .val(label.text())
                .focus(function() {
                    if (this.value === label.text()) this.value = "";
					//alert($(this).parents('form').children(":submit").length());
                })
                .blur(function() {
                    if (this.value === "") this.value = label.text();
                });
            // clear the value on the parent form submit
            input.parents('form').bind("submit.label", function() {
                if (input.val() === (label.text() || "") ) {
                    input.val("");
                }
            });
        });
    };
    
    
    $(function() { // run on document ready
        // setup the search tabs
		var off;
		var body_width_adj = $('body').width();
		
		$('a').focus(function() {
			$(this).blur();
		});
		
        $("#tabs li").tabs("#search-forms form");
        
        // setup hover state listeners
		$(".hoverable").each(function() {
			if($(this).children('div.sub').children('ul').length == 1) {
				$(this).addClass("short");
			}
			var off = $(this).offset();
			off = off.left + $(this).children('div.sub').width() + 14;
			if(off > body_width_adj) {
				$(this).addClass("rev");
				//alert('oops');
			}
			$(this).hover(function() {
				$(this).addClass("hover");
			}, function() {
				$(this).removeClass("hover");
			});
		});
        // put labels into elements
        $("input.labelize").label();
        //$("a[rel]").overlay({effect:'apple',expose:'#789'});
    });
})(LawInfo, jQuery);

