/* CODA BUBLE 
 * TINYSLIDER
 * METADATA
*/

/** * CodaBubble extension for jQuery library * * Creates tooltips "coda bubble" style * * @author Carlo Tasca * @version 1.0 * * OPTIONS: * * @param {array} distances Distances of bubbles from their triggers  * @param {array} leftShifts Left positions of bubbles * @param {array} bubbleTimes Life times for bubbles * @param {array} hideDelays Hide delay times for bubbles * @param {array} bubbleWidths Hide delay times for bubbles * @param {string} bubbleImagesPath Path to skin for bubbles * @param {boolean} msieFix Fix for IE png rendering. Replaces pngs with gifs if true (default) * @param {boolean} msiePop If false removes bubble in IE */jQuery.fn.codaBubble = function(opts){		var bubble = this;		opts = jQuery.extend({			distances : [20],			leftShifts : [0],	  		bubbleTimes : [400],	  		hideDelays : [0],	  		bubbleWidths : [66],	  		bubbleImagesPath : "",	  		msieFix : true,	  		msiePop : true		},opts||{});		  	    function bubbleHtmlWrapper(bubbleHtml) {	       return '<div class="popup" style="opacity: 0; top: -120px; left: -33px; display: none;">' +  bubbleHtml  + '</div>';	    }  		return jQuery(bubble).each(function (i) {	    var bubbleHtml = jQuery('.bubble_html', this).html(); 	    jQuery('.bubble_html', this).hide().after(bubbleHtmlWrapper(bubbleHtml));	    jQuery('.popup td.bottom img', this).attr('src', opts.bubbleImagesPath  + '/bubble-tail2.png');	    
   var distance = opts.distances[i];	    var time = opts.bubbleTimes[i];	    var hideDelay = opts.hideDelays[i];	    var hideDelayTimer = null;	    var beingShown = false;	    var shown = false;	    var trigger = jQuery('.trigger', this);	    var popup = jQuery('.popup', this).css('opacity', 0);	    	    jQuery([trigger.get(0), popup.get(0)]).mouseover(function () {	      jQuery(popup).css("width", opts.bubbleWidths[i] + "px");	      var triggerWidth = jQuery(trigger.get(0)).css('width');	      	      if (hideDelayTimer) clearTimeout(hideDelayTimer);	      if (beingShown || shown) {	        return;	      } else {	        beingShown = true;		        popup.css({	          top: -100,	          left: opts.leftShifts[i],	          display: 'block'	        })	        .animate({	          top: '-=' + distance + 'px',	          opacity: 1	        }, time, 'swing', function() {	          beingShown = false;	          shown = true;	        });	      }	    }).mouseout(function () {	      if (hideDelayTimer) clearTimeout(hideDelayTimer);	      	      hideDelayTimer = setTimeout(function () {	        hideDelayTimer = null;	        popup.animate({	          top: '-=' + distance + 'px',	          opacity: 0	        }, time, 'swing', function () {	          shown = false;	          popup.css('display', 'none');	        });	      }, hideDelay);	    });	    if (!opts.msiePop && $.browser.msie)	  	{	     jQuery(popup).remove();	  	}	  });}

var TINY={};function T$(i){return document.getElementById(i)}function T$$(e,p){return p.getElementsByTagName(e)}TINY.slider=function(){function slide(n,p){this.n=n;this.init(p)}slide.prototype.init=function(p){var s=T$(p.id),u=this.u=T$$('ul',s)[0],c=T$$('li',u),l=c.length,i=this.l=this.c=0;if(p.navid&&p.activeclass){this.g=T$$('li',T$(p.navid));this.s=p.activeclass}this.a=p.auto||0;this.p=p.resume||0;this.v=p.vertical||0;s.style.overflow='hidden';for(i;i<l;i++){if(c[i].parentNode==u){this.l++}}if(this.v){;u.style.top=0;this.h=p.height||c[0].offsetHeight;u.style.height=(this.l*this.h)+'px'}else{u.style.left=0;this.w=p.width||c[0].offsetWidth;u.style.width=(this.l*this.w)+'px'}this.pos(p.position||0,this.a?1:0)},slide.prototype.auto=function(){this.u.ai=setInterval(new Function(this.n+'.move(1,1)'),this.a*5000)},slide.prototype.move=function(d,a){var n=this.c+d,i=d==1?n==this.l?0:n:n<0?this.l-1:n;this.pos(i,a)},slide.prototype.pos=function(p,a){clearInterval(this.u.ai);clearInterval(this.u.si);var d=p>this.c?1:-1,o=this.v?p*this.h:p*this.w;o=o*-1;this.c=p;if(this.g){for(var i=0;i<this.l;i++){this.g[i].className=i==p?this.s:''}}this.u.si=setInterval(new Function(this.n+'.slide('+o+','+d+','+a+')'),50)},slide.prototype.slide=function(t,d,a){var o=this.v?parseInt(this.u.style.top):parseInt(this.u.style.left);if(o==t){clearInterval(this.u.si);if(a||(this.a&&this.p)){this.auto()}}else{var v=o-Math.ceil(Math.abs(t-o)*.15)*d+'px';this.v?this.u.style.top=v:this.u.style.left=v}};return{slide:slide}}();



(function($) {

$.extend({
	metadata : {
		defaults : {
			type: 'class',
			name: 'metadata',
			cre: /({.*})/,
			single: 'metadata'
		},
		setType: function( type, name ){
			this.defaults.type = type;
			this.defaults.name = name;
		},
		get: function( elem, opts ){
			var settings = $.extend({},this.defaults,opts);
			// check for empty string in single property
			if ( !settings.single.length ) settings.single = 'metadata';
			
			var data = $.data(elem, settings.single);
			// returned cached data if it already exists
			if ( data ) return data;
			
			data = "{}";
			
			if ( settings.type == "class" ) {
				var m = settings.cre.exec( elem.className );
				if ( m )
					data = m[1];
			} else if ( settings.type == "elem" ) {
				if( !elem.getElementsByTagName )
					return undefined;
				var e = elem.getElementsByTagName(settings.name);
				if ( e.length )
					data = $.trim(e[0].innerHTML);
			} else if ( elem.getAttribute != undefined ) {
				var attr = elem.getAttribute( settings.name );
				if ( attr )
					data = attr;
			}
			
			if ( data.indexOf( '{' ) <0 )
			data = "{" + data + "}";
			
			data = eval("(" + data + ")");
			
			$.data( elem, settings.single, data );
			return data;
		}
	}
});

/**
 * Returns the metadata object for the first member of the jQuery object.
 *
 * @name metadata
 * @descr Returns element's metadata object
 * @param Object opts An object contianing settings to override the defaults
 * @type jQuery
 * @cat Plugins/Metadata
 */
$.fn.metadata = function( opts ){
	return $.metadata.get( this[0], opts );
};

})(jQuery);
