function get(element) {
	if(document.getElementById(element)) {
		return true;
	}
}


$(document).ready(function(){
	// hovers for inputs + images
	function hoverBind() {
		$('.hover').hover(function(){
			$(this).attr('src', $(this).attr('src').replace(/\.gif/g, "Hover.gif"));
		},function() {
			$(this).attr('src', $(this).attr('src').replace(/Hover\.gif/g, ".gif"));
		});	
	}
	hoverBind();

	

	////////// Explorer //////////
	$('#eWrap').css({left: "-202px"});
	$('#eNav').fadeTo('fast', 0);
	
	//toggle
	$('#eToggle').hover(function(){
		$(this).css("backgroundColor", "#1d4da2").children('img').attr('src', $(this).children('img').attr('src').replace(/\.gif/g, "Hover.gif"));
	}, function() {
		$(this).css("backgroundColor", "#6082be").children('img').attr('src', $(this).children('img').attr('src').replace(/Hover\.gif/g, ".gif"));
	}).click(function(){
		if($('#eWrap').css('left') == '-202px') {
			$(this).children('img').attr('src', '/images/explorer/toggleIn.gif');
			$('#eWrap').animate({left: "0px"}, "fast");
			$('#eNav').fadeTo('fast', 1);
			
		} else {
			$(this).children('img').attr('src', '/images/explorer/toggleOut.gif');
			$('#eWrap').animate({left: "-202px"}, "fast");
			$('#eNav').fadeTo('fast', 0);
			
		}
	});
	if(get('contactForm')) {
		$('#contactForm').sitVal();
		
	}
	
	
	
	
	$('#eNav ul li ul').hide();
	$('.ePlus').click(function(){
		if($(this).attr('state') == "plus") {
            if($(this).children('img').hasClass('hover')) {
            	$(this).attr('state', 'minus').siblings('ul').slideDown('fast').end()
            	.siblings('a').attr('state', 'minus').end()
            	.children('img').attr("src", "/images/explorer/minus.gif");
            } else {
                $(this).attr('state', 'minus').siblings('ul').slideDown('fast').end()
                .siblings('a').attr('state', 'minus').end()
                .siblings('a').children('img').attr("src", "/images/explorer/minus.gif");
            }
	
		} else {
		    if($(this).children('img').hasClass('hover')) {
              	$(this).attr('state', 'plus').siblings('ul').slideUp('fast').end()
              	.siblings('a').attr('state', 'plus').end()
              	.children('img').attr("src", "/images/explorer/plus.gif");
              } else {
                  $(this).attr('state', 'plus').siblings('ul').slideUp('fast').end()
                  .siblings('a').attr('state', 'plus').end()
                  .siblings('a').children('img').attr("src", "/images/explorer/plus.gif");
              }
		}
	});
	
	$('.eplusSub').click(function(){
		if($(this).attr('state') == "plus") {
            if($(this).children('img').hasClass('hover')) {
            	$(this).attr('state', 'minus').siblings('ul').slideDown('fast').end()
            	.siblings('a').attr('state', 'minus').end()
            	.children('img').attr("src", "/images/explorer/minusSub.gif");
            } else {
                $(this).attr('state', 'minus').siblings('ul').slideDown('fast').end()
                .siblings('a').attr('state', 'minus').end()
                .siblings('a').children('img').not('.homeLink').attr("src", "/images/explorer/minusSub.gif");
            }
	
		} else {
		    if($(this).children('img').hasClass('hover')) {
              	$(this).attr('state', 'plus').siblings('ul').slideUp('fast').end()
              	.siblings('a').attr('state', 'plus').end()
              	.children('img').attr("src", "/images/explorer/plusSub.gif");
              } else {
                  $(this).attr('state', 'plus').siblings('ul').slideUp('fast').end()
                  .siblings('a').attr('state', 'plus').end()
                  .siblings('a').children('img').not('.homeLink').attr("src", "/images/explorer/plusSub.gif");
              }
		}
	});
	
	
	


	
	// search bar default value
	sDefault = $('#topSearch').val();
	$('#topSearch').click(function(){
		if(this.value == sDefault) {
			this.value = "";
		}
	}).blur(function(){
		if(this.value == "") {
			this.value = sDefault;
		}
	});
	
	//search page:
	
	//////// check / uncheck for the search page ////////
	
	boxes = new Array(); // will store as properties jquery arrays
	$('.checkControl').each(function(i){
		boxes[i] = $(this).prev().children().children().children().children('input');
				
		$(this).children().children('a').click(function(){
			if($(this).html() == "Check all") {
				$(boxes[i]).each(function(){
					$(this)[0].checked = true;
				});
			} else {
				$(boxes[i]).each(function(){
					$(this)[0].checked = false;
				});
			}
			return false;
		});

	});
	
	//results tabs 
	if(get('sResults')) {
		$('#videoWrap,#docsWrap').hide();
		$('#sResults li:first').css({backgroundImage: $('#sResults li:first').css("backgroundImage").replace(/\.gif/g, "On.gif"), backgroundColor: '#1d4da2'});

		$('#sResults li').css('cursor', 'pointer')

		.click(function(){
			$('#sResults li').each(function(){
				$(this).css({backgroundImage: $(this).css("backgroundImage").replace(/On\.gif/g, ".gif"), backgroundColor: '#a7a9ac'});
			});	
			theBox = "#"+$(this).attr('box');
			$(this).css({backgroundImage: $(this).css("backgroundImage").replace(/\.gif/g, "On.gif"), backgroundColor: '#1d4da2'});
			$('#videoWrap,#docsWrap,#fullDetailsWrap').hide();
			$(theBox).show();
			return false;
		});
		
	}
	
	
	// potential contributor stuff
	$('#potBox').hide();
	$('#cPotentialContributor').click(function(){
		if($('#cPotentialContributor')[0].checked == true) {
			$('#potBox').show('fast');
			
		} else {
			$('#potBox').hide('fast');
		}
	});

});
