jQuery.noConflict();

jQuery(document).ready(function() {
	
	jQuery("a[rel^='prettyPhoto']").prettyPhoto();
jQuery("a[rel^='facebox']").facebox();
	
	jQuery(".tip").tooltip();
	jQuery("form#search-full, form#search-sidebar").inputHintOverlay(4, 5);

	
// 	jQuery("#listings-home li a").hover(function() {
// jQuery(this).next(".pop").stop(true, true).animate({opacity: "show", left: "-275"}, "slow");
// }, function() {
// jQuery(this).next(".pop").animate({opacity: "hide", left: "-300"}, "slow");
// });

// 	jQuery("#listings-home li a").hover(function() {
// jQuery(this).next(".pop").fadeIn("fast");
// }, function() {
// jQuery(this).next(".pop").fadeOut("fast");
// });

jQuery('.field:empty').each(function() {
	jQuery(this).next(".clear").remove();
	jQuery(this).prev(".label").remove();
	jQuery(this).remove();
});
           
	jQuery('#nashville-updates>div.short-post').each(function() {
	jQuery(this).find('img.size-full').remove();
});
jQuery('.sidebar>div.short-post').each(function() {
	jQuery(this).find('img.size-full').parent().remove();
	jQuery(this).find('br').remove();

});
jQuery('.post img.size-full').each(function() {
	var imgsrc = jQuery(this).attr('src');
	jQuery(this).attr('src',imgsrc+"?w=590");
});

// jQuery('ul.menu>li a').each(function() {
// 	var newtoplink = jQuery(this).next('ul.sub-menu li.menu-item a:first').attr('href');
//	jQuery(this).attr('href',newtoplink);
// });

 jQuery('li','#menu-nav').each(function() {   
   var submenu = jQuery(this).find('.sub-menu');
   if (submenu.length > 0) {
    var newtoplink = jQuery(this).find('.sub-menu a:first').attr('href')
    jQuery(this).find('a:first').attr('href',newtoplink);
 }   
 });
 
jQuery(".post:first").addClass("first");

    // DROPDOWN
	jQuery('#menu-nav li').hover(
		function () {
			jQuery('ul', this).slideDown(200);
		}, 
		function () {
			jQuery('ul', this).slideUp(100);			
		}
	);
	
	jQuery('#gallery-frame').cycle({
		fx:     'fade',
		speed:  'slow',
		timeout: 4000,
		pause: 'true',
		pager:  '#gallery-thumbs',
		pagerAnchorBuilder: function(idx, slide) {
			// return sel string for existing anchor
			return '#gallery-thumbs li:eq(' + (idx) + ') a';
		}
	});

	
	// EQUAL COL HEIGHT
	var max_height = 0;
	jQuery("li.listing-box").each(function(){
	if (jQuery(this).height() > max_height) { max_height = jQuery(this).height(); }
	});
	jQuery("li.listing-box").height(max_height);

	// CLICKABLE CONTAINER
	jQuery('.container').click(function() {
        var href = jQuery(this).find("a").attr("href");
        if(href) {
            window.location = href;
        }
    });
	
	// STIPED TABLES
	jQuery("table.striped tr:odd").addClass("alt-row");
	
// jQuery('ul.vendor-list').makeacolumnlists({cols:2,colWidth:0,equalHeight:false,startN:1});
// jQuery('ul.vendor-links').makeacolumnlists({cols:2,colWidth:0,equalHeight:false,startN:1});

jQuery('.vendor-links').easyListSplitter({ colNumber: 3 });

// Define: Linkify plugin
(function($){

  var url1 = /(^|&lt;|\s)(www\..+?\..+?)(\s|&gt;|$)/g,
      url2 = /(^|&lt;|\s)(((https?|ftp):\/\/|mailto:).+?)(\s|&gt;|$)/g,

      linkifyThis = function () {
        var childNodes = this.childNodes,
            i = childNodes.length;
        while(i--)
        {
          var n = childNodes[i];
          if (n.nodeType == 3) {
            var html = $.trim(n.nodeValue);
            if (html)
            {
              html = html.replace(/&/g, '&amp;')
                         .replace(/</g, '&lt;')
                         .replace(/>/g, '&gt;')
                         .replace(url1, '$1<a href="http://$2">$2</a>$3')
                         .replace(url2, '$1<a href="$2">Visit Website</a>$5');
              $(n).after(html).remove();
            }
          }
          else if (n.nodeType == 1  &&  !/^(a|button|textarea)$/i.test(n.tagName)) {
            linkifyThis.call(n);
          }
        }
      };

  $.fn.linkify = function () {
    return this.each(linkifyThis);
  };

})(jQuery);

// Usage example:
jQuery('ul.vendor-list,.vendor-details').linkify();
});

function bookmarksite( title, url )
{
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print)
	{ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}

