// SMOOTH SCROLLING

$(document).ready(function() {
  function filterPath(string) {
  return string
    .replace(/^\//,'')
    .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
    .replace(/\/$/,'');
  }

  var locationPath = filterPath(location.pathname);
  $('body').click(function(event) {
    var $tgt = $(event.target);
    var $link = ($tgt.is('a') && $tgt) || ($tgt.parents('a').length && $tgt.parents('a:first')) || null  ;
    //stop if it's not a link
    if (!$link || $link.parent().is('.reply')) { return; }
  
    var link = $link[0];
    var thisPath = filterPath(link.pathname) || locationPath;
    if (  locationPath == thisPath
    && (location.hostname == link.hostname || !link.hostname)
    && link.hash.replace(/#/,'') ) {
      event.preventDefault();
      var $target = $(link.hash), target = link.hash;
      if ($target.length) {
        var targetOffset = $target.offset().top;

        $('html, body').animate({scrollTop: targetOffset}, 400, function() {
          location.hash = target;
        });
      }
    }

  });
  $('a[href*=#]').each(function() {
    var thisPath = filterPath(this.pathname) || locationPath;
  });
});

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel();
});

// CODA BUBBLE

$(document).ready(function() {
	$(function(){
	   opts = {
	      distances : [15,15,15],
	      leftShifts : [-90,-92,-91],
	      bubbleTimes : [500,500,500],
	      hideDelays : [30,30,30],
	      bubbleWidths : [183,203,203],
	      bubbleImagesPath : "YOUR RELATIVE PATH TO SKIN FOLDER",
	      msieFix : true
	   };
	   $('.coda_bubble').codaBubble(opts);
	});
});

// TWITTER UPDATES

$(document).ready(function(){

	$("p").click( function() {
		$("#player_div").empty();
		$("#player_div").prepend(insertPlayer());


	 } );

	 $("h2").dblclick( function() {
	 	$("#player_div").empty();
		$("#player_div").prepend(insertPlayer());
	 } );


    });

	/**
	 * render the flash embed for those crazy mp3 soundz ... yeah rock?n roll
	 *
	 */
	function insertPlayer(){

		var soundz = ['gimme_money.mp3','hu_babe.mp3','oh_dude.mp3','again.mp3','script_4me.mp3']

	    var playerpath	= 'flash/singlemp3player.swf';
		var path		= 'soundz/';
		var filename	= path + soundz.random();

		var mp3html = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
		mp3html += 'width="1" height="1" ';
		mp3html += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">';
		mp3html += '<param name="movie" value="'+playerpath+'?';
		mp3html += 'showDownload=false&file=' + filename + '&autoStart=true';
		mp3html += '&backColor=ffffff&frontColor=ffffff';
		mp3html += '&repeatPlay=false&songVolume=50" />';
		mp3html += '<param name="wmode" value="transparent" />';
		mp3html += '<embed wmode="transparent" width="1" height="1" ';
		mp3html += 'src="' + playerpath + '?'
		mp3html += 'showDownload=false&file=' + filename + '&autoStart=true';
		mp3html += '&backColor=ffffff&frontColor=ffffff';
		mp3html += '&repeatPlay=false&songVolume=50" ';
		mp3html += 'type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		mp3html += '</object>';
		return mp3html;

	}
/* takes an array and returns a random element*/
Array.prototype.random = function( r )
{
	var i = 0, l = this.length;
	if( !r ) { r = this.length; }
	else if( r > 0 ) { r = r % l; }
	else { i = r; r = l + r % l; }
	return this[ Math.floor( r * Math.random() - i ) ];
};

// FLICKR FEED
    
$(document).ready(function(){
    $(".myPics").flickr({
    	api_key: "f0d61c8724a791671f8896cad5cf252a",
    	type: "photoset",
    	photoshop_id: "72157621916682302",
    	per_page: 4
    	});
	});
	
// SLIDESHOWS

$(document).ready(function(){
 	$('#nyq .slideshow').cycle({ fx: 'scrollUp', prev: '#nyq .previous',next: '#nyq .next', timeout:  0, delay:  0, speed:  500 });
 	$('#rms .slideshow').cycle({ fx: 'scrollUp', prev: '#rms .previous',next: '#rms .next', timeout:  0, delay:  0, speed:  500 }); 
 	
});

