/* HOMEPAGE SLIDER */
jQuery(function() {
    jQuery('#homepage_slider')
	.cycle({
        fx:     'fade',
    	speed:  'slow',
    	timeout: 7000,
    	//next:   '.feature_next',
    	//prev:   '.feature_prev',
        pager:  '.feature_nav',
		pagerAnchorBuilder: function(index, el) {
        return '<a href="#">&nbsp;</a>'; //hides text
 		}
    });
	
	function onBefore() { 
		var val = jQuery(this).attr('rel');
		jQuery.address.value(val);
		//jQuery.address.title('Fender&#174; Guitar: ' + jQuery(this).attr('title'))
    }; 
	
});


	
jQuery(document).ready(function() {
	jQuery('#home_promos').jcarousel({
		wrap: 'circular',
		scroll:1,
		// Uncomment when more than 3 sub-features auto:4  
		auto: 0	
	});
	var carousel = jQuery('#home_promos').data('jcarousel');

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
	
	jQuery('.carousel_next').bind('click', function() {
        carousel.next();
        carousel.startAuto(0);
        return false;
    });

    jQuery('.carousel_prev').bind('click', function() {
        carousel.prev();
        carousel.startAuto(0);
        return false;
    });	
	
});	
	


/* Sub Feature B/W Hover */
jQuery(document).ready(function() {

	jQuery("ul.gallery li").hover(function() { //On hover...

		var thumbOver = jQuery(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'

		//Set a background image(thumbOver) on the <a> tag - Set position to bottom
		jQuery(this).find("a.thumb").css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});

		//Animate the image to 0 opacity (fade it out)
		jQuery(this).find("span").stop().fadeTo('normal', 0 , function() {
			jQuery(this).hide() //Hide the image after fade
		});
	} , function() { //on hover out...
		//Fade the image to full opacity 
		jQuery(this).find("span").stop().fadeTo('normal', 1).show();
	});

});
	
/** TWITTER MENTIONS */
(function($){
  /** public methods **/

  $.fn.twitterMentions = function (user, options) {
   try
   {
    var
      opts = $.extend({}, $.fn.twitterMentions.defaults, options),
      c = $.isFunction(opts.callback) ? opts.callback: _build,
      url = 'http://search.twitter.com/search.json'
      params = { q : _query(user), page : opts.page, rpp : opts.maximum };

    return this.each(function(i, e) {
      $.ajax({
        url: url,
        data: params,
        dataType: 'jsonp',
        success: function (o) {
          c.apply(this, [(o.results) ? o.results: o, e, opts]);
        }
      });
    });
   } catch (e){}
  };
  /** defaults **/
  $.fn.twitterMentions.defaults = {
    user: null,
    callback: null,
    page : 1,
    maximum : 10,
	avatar : true,
    ulClass : 'twitter-mentions',
	odd : true,
	oddClass : 'odd'
  };

  /** private methods **/
  var _build = function (object, element, opts)
  {
    var html = '<ul class="'+ opts.ulClass +'">';
    for ( var i = 0; i < object.length; i++ )
    {
        current = object[i];
		user = current.from_user;
		text = current.text.replace(/(https?:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/, function (u) {
            var shortUrl = (u.length > 30) ? u.substr(0, 30) + '...': u;
            return '<a href="' + u + '">' + shortUrl + '</a>';
		}).replace(/@([a-zA-Z0-9_]+)/g, '@<a href="http://twitter.com/$1">$1</a>').replace(/(?:^|\s)#([^\s\.\+:!]+)/g, function (a, u) {
            return ' <a href="http://twitter.com/search?q=' + encodeURIComponent(u) + '">#' + u + '</a>';
        });
        html += '<li'+( (opts.odd && i%2 ) ? ' class="'+opts.oddClass+'"' : '')+'>'+( opts.avatar ? '<a href="http://twitter.com/'+user+'"><img src="'+ current.profile_image_url +'"></a>' : '')+'<strong>'+ user + '</strong> '+ text +'</li>' ;
    }
    html+='</ul>';
    $(element).html(html);
  };
  
  var _query = function(q)
  {
    if( typeof q == 'string' )
        return '@'+q;
    else if( typeof q == 'object' )
        return '@'+q.join(' OR @');
    throw 'data type not supported';
  }
})($);
	
	




