/* INPUTHINT */
(function($) {
    $.fn.inputhint = function(options) {
        // iterate and reformat each matched element
        return this.each(function() {
            // cache this:
            var obj = $(this);
            // get value hint
            var ogval = obj.val();
            obj.focus(function(){
                if( obj.val() == ogval ){
                    obj.val('');
                } else { null; };
            });
            obj.blur(function(){
                if( obj.val() == "" ){
                    obj.val(ogval);
                };
            });
        });
    };
})(jQuery);


/* NAVTREE */
 (function($) {
  $.fn.navtree = function() {
    return this.each(function() {
      var $obj = $(this);
      var $parents = $obj.children('li:has(ul)');
      $parents.each(function(){
        var $thisparent = $(this);
	//alert($thisparent.val());
        $thisparent.click(function(){
	 //    if($thisparent.css('display','none')){
	          $thisparent.children('ul').toggle();
		  //$.cookie($thisparent.val(),"1");
		  //alert($.cookie("example"));
		  //$thisparent.children('ul').css('display','block');
		  return false;
	    // }
	     //else {
             //  $thisparent.css('display','none');
	       //$thisparent.children('ul').toggle();
	      // return false;
	     //}
        });
	$thisparent.find('li').click(function(e){
	  e.stopPropagation();
	}); 
      });
    });
  };
})(jQuery);

/* Form Validate*/
(function($) {
  $.fn.validateform = function() {
    return this.each(function() {
      var $obj = $(this);
      
        var $parentform = $obj.parents("form").attr("id");
	
	$("#" + $parentform).submit(function(){ 
	  $('#keywords').val('');
	  var $ret = true;
	  var $inputs = $("#" + $parentform + " :input");
	    $inputs.each(function(){
	      $attrib = $(this)[0].type;
	        if ($attrib == 'text') {
		  var $defVal = $(this)[0].defaultValue;
		    if ($(this).val() == $defVal || $(this).val() == "") {
		      $("#" + $parentform).find('.error').show();
		      $ret = false;
		    }
		    else {
			 $('#keywords').val($('#keywords').val() + " " + $(this).val());
		    };
		  };    
	        });
	    
	     if ($ret == false) {
	       return false;    
	     }
	     else {
               return true;    
	     }
	});
     });
   };
})(jQuery);

/* featured-business-gallery */
(function($) {
  $.fn.bizgallery = function() {
    return this.each(function() {
      var obj = $(this);
      var featureditem = obj.find('.featured-item');
      var openbtn = obj.find('.featured-item-toggle');
      var closebtn = featureditem.find('.close-btn'); 
      openbtn.hover(function(){
        featureditem.show();
      });
      closebtn.click(function(){
        featureditem.hide();
        return false;
      });
    });
  };
})(jQuery);
