/*
 * Droppy 0.1.2
 * (c) 2008 Jason Frame (jason@onehackoranother.com)
 */
$.fn.droppy = function(options) {
    
  options = $.extend({speed: 250}, options || {});
  
  this.each(function() {
    
    var root = this, zIndex = 30000;
    
    function getSubnav(ele) {
      if (ele.nodeName.toLowerCase() == 'li') {
        var subnav = $('> div, > ul', ele);
        return subnav.length ? subnav[0] : null;
      } else {
        return ele;
      }
    }
    
    /*function getActuator(ele) {
		alert(ele.nodeName);
      if (ele.nodeName.toLowerCase() == 'div') {
        return $(ele).parents('li')[0];
      } else {
        return ele;
      }
    }*/
    
    function hide() {
      var subnav = getSubnav(this);
      if (!subnav) return;
	  var thethis = this
	  
      $.data(subnav, 'cancelHide', false);
      setTimeout(function() {
        if (!$.data(subnav, 'cancelHide')) {
			
          $(thethis).removeClass('hover'); $('> a', thethis).removeClass('hover');
		  
		  $(subnav).slideUp(options.speed);
		  
		  
        }
      }, 500);
    }
  
    function show() {
      var subnav = getSubnav(this);
      if (!subnav) return;
      $.data(subnav, 'cancelHide', true);
      $(subnav).css({zIndex: zIndex++}).slideDown(options.speed);
	 
	  $(subnav).parent().css({zIndex: zIndex});//ie adds a bloody margin!?!?!
	  
	  $(this).addClass('hover'); $('> a', this).addClass('hover');
      
	  /*alert(this.nodeName);
	  if (this.nodeName.toLowerCase() == 'li') {
        var li = getActuator(this);
        $(li).addClass('hover');
        $('> a', li).addClass('hover');
      }*/
	  
	  
    }
    
    $('li', this).hover(show, hide);
    //$('li', this).hover(
      //function() { $(this).addClass('hover'); $('> a', this).addClass('hover');}
    //);
    
  });
  
};


//APPEND DOM TARGET = BLANK TO ALL <A>'S WITH REL=EXTERNAL
function exttarget(s) { 
if (!document.getElementsByTagName) return; 
var ql = document.getElementsByTagName("a"); 
for (var i = 0; i < ql.length; i++ ) { 
if (ql[i].getAttribute("rel")) {
	
	if(ql[i].getAttribute("rel") == "external" || ql[i].getAttribute("rel") == "external nofollow"){
		ql[i].target = "_blank";
	}
}}}



$(function(){

	$('.nav ul').droppy();
	
	
	
	//clear default
	$('.textfield').bind('focus',function(){
		if (this.defaultValue==this.value) this.value = "";
	}).bind('blur',function(){
		if (this.value=="") this.value = this.defaultValue;
	});
	
	
	
	$('.locationlink').bind('click',function(){
											 
		$('.locationdrop').slideToggle();
		return false;							 
	});
	
	
	//external links
	exttarget();
	
	
});

