/**
 * jQuery crop - takes (IMG) elements and crops them to the dimensions
 * given.  The result is the same image with a background image with the
 * height and width and an offset.  The new DIV should also carry across 
 * the existing style attributes of the image.
 *
 * @author Remy Sharp (leftlogic.com)
 * @date 2006-12-28
 * @example $("img").crop(x, y, height, width)
 * @example $("img").crop({ x: x, y: y, height: height, width: width })
 * @example $("img").crop(height, width)
 * @example $("img").crop(width)
 * @desc Crops image to dimensions given.  If only width (and height), 
 * x and y are selected randomly based on the image's height and width.
 *
 * @name crop
 * @type jQuery
 * @param Number x co-ordinate to start crop
 * @param Number y co-ordinate to start crop
 * @param Number height of final cropped image
 * @param Number width of final cropped image
 * @cat Plugin
 */
jQuery.fn.crop = function(x, y, height, width, transparentURL) {
	var o = {}
	
	if (x && typeof x == 'object') { // property object
		o['x'] = x['x'] || -1;
		o['y'] = x['y'] || -1;
		o['height'] = ((x['height'] || x['width']) || -1);
		o['width'] = x['width'] || x['height'] || -1;
		
		// note: this *will not* work in IE.
		o['transparentURL'] = x['transparentURL'] || "data:image/gif;base64,R0lGODlhAQABAIAAAMJ0IgAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==";
	} else if (arguments.length == 1) {
		o['x'] = -1;
		o['y'] = -1;
		o['height'] = x;
		o['width'] = x;
	} else if (arguments.length == 2) {
		o['x'] = -1;
		o['y'] = -1;
		o['height'] = x;
		o['width'] = y;
	} else {
		o['x'] = x;
		o['y'] = y;
		o['height'] = height;
		o['width'] = width || height;
		o['transparentURL'] = transparentURL;
	}
				
	return this.each(function() {
		var x = o.x;
		var y = o.y;
		var t = jQuery(this);
		
		if (o.x == -1) {
			x = Math.round((this.width - o.width + 1) * Math.random())
			if (this.width - x < o.width) x = 0;
		}
		if (o.y == -1) {
			y = Math.round((this.height - o.height + 1) * Math.random())
			if (this.height - y < o.height) y = 0;
		}

		t.height(o.height + 'px');
		t.width(o.width + 'px');
		
		var background = { 
			height: o.height + 'px', 
			width: o.width + 'px', 
			background: 'url(' + this.src + ') no-repeat -' + Math.abs(x) + 'px -' + Math.abs(y) + 'px' 
		};
		
		this.origSrc = this.src;
		this.src = o['transparentURL']; // transparent gif to fill image
		
		t.css(background); // crop!
	})
}



/*
 * jQuery corner plugin
 *
 * version 1.7 (1/26/2007)
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

/**
 * The corner() method provides a simple way of styling DOM elements.  
 *
 * corner() takes a single string argument:  $().corner("effect corners width")
 *
 *   effect:  The name of the effect to apply, such as round or bevel. 
 *            If you don't specify an effect, rounding is used.
 *
 *   corners: The corners can be one or more of top, bottom, tr, tl, br, or bl. 
 *            By default, all four corners are adorned. 
 *
 *   width:   The width specifies the width of the effect; in the case of rounded corners this 
 *            will be the radius of the width. 
 *            Specify this value using the px suffix such as 10px, and yes it must be pixels.
 *
 * For more details see: http://methvin.com/jquery/jq-corner.html
 * For a full demo see:  http://malsup.com/jquery/corner/
 *
 *
 * @example $('.adorn').corner();
 * @desc Create round, 10px corners 
 *
 * @example $('.adorn').corner("25px");
 * @desc Create round, 25px corners 
 *
 * @example $('.adorn').corner("notch bottom");
 * @desc Create notched, 10px corners on bottom only
 *
 * @example $('.adorn').corner("tr dog 25px");
 * @desc Create dogeared, 25px corner on the top-right corner only
 *
 * @example $('.adorn').corner("round 8px").parent().css('padding', '4px').corner("round 10px");
 * @desc Create a rounded border effect by styling both the element and its parent
 * 
 * @name corner
 * @type jQuery
 * @param String options Options which control the corner style
 * @cat Plugins/Corner
 * @return jQuery
 * @author Dave Methvin (dave.methvin@gmail.com)
 * @author Mike Alsup (malsup@gmail.com)
 */
jQuery.fn.corner = function(o) {
    function hex2(s) {
        var s = parseInt(s).toString(16);
        return ( s.length < 2 ) ? '0'+s : s;
    };
    function gpc(node) {
        for ( ; node && node.nodeName.toLowerCase() != 'html'; node = node.parentNode  ) {
            var v = jQuery.css(node,'backgroundColor');
            if ( v.indexOf('rgb') >= 0 ) { 
                rgb = v.match(/\d+/g); 
                return '#'+ hex2(rgb[0]) + hex2(rgb[1]) + hex2(rgb[2]);
            }
            if ( v && v != 'transparent' )
                return v;
        }
        return '#ffffff';
    };
    function getW(i) {
        switch(fx) {
        case 'round':  return Math.round(width*(1-Math.cos(Math.asin(i/width))));
        case 'cool':   return Math.round(width*(1+Math.cos(Math.asin(i/width))));
        case 'sharp':  return Math.round(width*(1-Math.cos(Math.acos(i/width))));
        case 'bite':   return Math.round(width*(Math.cos(Math.asin((width-i-1)/width))));
        case 'slide':  return Math.round(width*(Math.atan2(i,width/i)));
        case 'jut':    return Math.round(width*(Math.atan2(width,(width-i-1))));
        case 'curl':   return Math.round(width*(Math.atan(i)));
        case 'tear':   return Math.round(width*(Math.cos(i)));
        case 'wicked': return Math.round(width*(Math.tan(i)));
        case 'long':   return Math.round(width*(Math.sqrt(i)));
        case 'sculpt': return Math.round(width*(Math.log((width-i-1),width)));
        case 'dog':    return (i&1) ? (i+1) : width;
        case 'dog2':   return (i&2) ? (i+1) : width;
        case 'dog3':   return (i&3) ? (i+1) : width;
        case 'fray':   return (i%2)*width;
        case 'notch':  return width; 
        case 'bevel':  return i+1;
        }
    };
    o = (o||"").toLowerCase();
    var keep = /keep/.test(o);                       // keep borders?
    var cc = ((o.match(/cc:(#[0-9a-f]+)/)||[])[1]);  // corner color
    var sc = ((o.match(/sc:(#[0-9a-f]+)/)||[])[1]);  // strip color
    var width = parseInt((o.match(/(\d+)px/)||[])[1]) || 10; // corner width
    var re = /round|bevel|notch|bite|cool|sharp|slide|jut|curl|tear|fray|wicked|sculpt|long|dog3|dog2|dog/;

    var fx = ((o.match(re)||['round'])[0]);
    var edges = { T:0, B:1 };
    var opts = {
        TL:  /top|tl/.test(o),       TR:  /top|tr/.test(o),
        BL:  /bottom|bl/.test(o),    BR:  /bottom|br/.test(o)
    };
    if ( !opts.TL && !opts.TR && !opts.BL && !opts.BR )
        opts = { TL:1, TR:1, BL:1, BR:1 };
    var strip = document.createElement('div');
    strip.style.overflow = 'hidden';
    strip.style.height = '1px';
    strip.style.backgroundColor = sc || 'transparent';
    strip.style.borderStyle = 'solid';
    return this.each(function(index){
        var pad = {
            T: parseInt(jQuery.css(this,'paddingTop'))||0,     R: parseInt(jQuery.css(this,'paddingRight'))||0,
            B: parseInt(jQuery.css(this,'paddingBottom'))||0,  L: parseInt(jQuery.css(this,'paddingLeft'))||0
        };

        if (jQuery.browser.msie) this.style.zoom = 1; // force 'hasLayout' in IE
        if (!keep) this.style.border = 'none';
        strip.style.borderColor = cc || gpc(this.parentNode);
        var cssHeight = jQuery.curCSS(this, 'height');

        for (var j in edges) {
            var bot = edges[j];
            strip.style.borderStyle = 'none '+(opts[j+'R']?'solid':'none')+' none '+(opts[j+'L']?'solid':'none');
            var d = document.createElement('div');
            var ds = d.style;

            bot ? this.appendChild(d) : this.insertBefore(d, this.firstChild);

            if (bot && cssHeight != 'auto') {
                if (jQuery.css(this,'position') == 'static')
                    this.style.position = 'relative';
                ds.position = 'absolute';
                ds.bottom = ds.left = ds.padding = ds.margin = '0';
                if (jQuery.browser.msie)
                    ds.setExpression('width', 'this.parentNode.offsetWidth');
                else
                    ds.width = '100%';
            }
            else {
                ds.margin = !bot ? '-'+pad.T+'px -'+pad.R+'px '+(pad.T-width)+'px -'+pad.L+'px' : 
                                    (pad.B-width)+'px -'+pad.R+'px -'+pad.B+'px -'+pad.L+'px';                
            }

            for (var i=0; i < width; i++) {
                var w = Math.max(0,getW(i));
                var e = strip.cloneNode(false);
                e.style.borderWidth = '0 '+(opts[j+'R']?w:0)+'px 0 '+(opts[j+'L']?w:0)+'px';
                bot ? d.appendChild(e) : d.insertBefore(e, d.firstChild);
            }
        }
    });
};

/*
@author: Remy Sharp / http://remysharp.com
@date: 2007-04-21
@usage:
$('img').zoom('200%', '200%');
$('img').zoom('300px', '200px');
$('img').zoom(300);
*/
jQuery.fn.zoom = function(height, width) {
  if (!width && height) {
    width = height;
  } else if (!width && !height) {
    width = height = '100%';
  }
  
  function toem(px) {
    px = parseFloat(px);
    return (px * 0.0626).toString() + 'em';
  }
  
  function getLen(elm, side, target) {
    var l = 1;
    if (target.indexOf('%') === -1) {
      l = toem(target);
    } else {
      l = toem(elm[side] * (parseFloat(target)/100));
    }
    
    return l;
  }
  
  return this.each(function() {
    var hem = getLen(this, 'height', height);
    var wem = getLen(this, 'width', width);
    
    jQuery(this).css({ height: hem, width: wem });
  });
};





/* EZPZ Tooltip v1.0;
Copyright (c) 2009 Mike Enriquez
http://theezpzway.com;
Released under the MIT License*/

(function($){
	$.fn.ezpz_tooltip = function(options){
		var settings = $.extend({}, $.fn.ezpz_tooltip.defaults, options);
		
		return this.each(function(){
			var	content = $("#" + getContentId(this.id));
			var targetMousedOver = $(this).mouseover(function(){
				settings.beforeShow(content, $(this));
			}).mousemove(function(e){
				contentInfo = getElementDimensionsAndPosition(content);
				targetInfo = getElementDimensionsAndPosition($(this));
				contentInfo = $.fn.ezpz_tooltip.positions[settings.contentPosition](contentInfo, e.pageX, e.pageY, settings.offset, targetInfo);
				contentInfo = keepInWindow(contentInfo);
				
				content.css('top', contentInfo['top']);
				content.css('left', contentInfo['left']);
				
				settings.showContent(content);
			});
			
			if (settings.stayOnContent && this.id != "") {
				$("#" + this.id + ", #" + getContentId(this.id)).mouseover(function(){
					content.css('display', 'block');
				}).mouseout(function(){
					content.css('display', 'none');
					settings.afterHide();
				});
			}
			else {
				targetMousedOver.mouseout(function(){
					settings.hideContent(content);
					settings.afterHide();
				})
			}
			
		});
		
		function getContentId(targetId){
			if (settings.contentId == "") {
				var name = targetId.split('-')[0];
				var id = targetId.split('-')[2];
				return name + '-content-' + id;
			}
			else {
				return settings.contentId;
			}
		};
		
		function getElementDimensionsAndPosition(element){
			var height = element.outerHeight(true);
			var width = element.outerWidth(true);
			var top = $(element).offset().top;
			var left = $(element).offset().left;
			var info = new Array();
			
			// Set dimensions
			info['height'] = height;
			info['width'] = width;
			
			// Set position
			info['top'] = top;
			info['left'] = left;
			
			return info;
		};
		
		function keepInWindow(contentInfo){
			var windowWidth = $(window).width();
			var windowTop = $(window).scrollTop();
			var output = new Array();
			
			output = contentInfo;
			
			if (contentInfo['top'] < windowTop) { // Top edge is too high
				output['top'] = windowTop;
			}
			if ((contentInfo['left'] + contentInfo['width']) > windowWidth) { // Right edge is past the window
				output['left'] = windowWidth - contentInfo['width'];
			}
			if (contentInfo['left'] < 0) { // Left edge is too far left
				output['left'] = 0;
			}
			
			return output;
		};
	};
	
	$.fn.ezpz_tooltip.positionContent = function(contentInfo, mouseX, mouseY, offset, targetInfo) {
		contentInfo['top'] = mouseY - offset - contentInfo['height'];
		contentInfo['left'] = mouseX + offset;
		
		return contentInfo;
	};
	
	$.fn.ezpz_tooltip.positions = {
		aboveRightFollow: function(contentInfo, mouseX, mouseY, offset, targetInfo) {
			contentInfo['top'] = mouseY - offset - contentInfo['height'];
			contentInfo['left'] = mouseX + offset;

			return contentInfo;
		}
	};
	
	$.fn.ezpz_tooltip.defaults = {
		contentPosition: 'aboveRightFollow',
		stayOnContent: false,
		offset: 10,
		contentId: "",
		beforeShow: function(content){},
		showContent: function(content){
			content.show();
		},
		hideContent: function(content){
			content.hide();
		},
		afterHide: function(){}
	};
	
})(jQuery);

// Plugin for different content positions.

(function($){
		
	$.fn.ezpz_tooltip.positions.ads = function(contentInfo, mouseX, mouseY, offset, targetInfo) {
		contentInfo['top'] = targetInfo['top'] + targetInfo['height'] + offset;
		contentInfo['left'] = (targetInfo['left'] + 80);
		
		return contentInfo;
	};
	
	$.fn.ezpz_tooltip.positions.stdads = function(contentInfo, mouseX, mouseY, offset, targetInfo) {
		contentInfo['top'] = targetInfo['top'] + targetInfo['height'] + offset;
		contentInfo['left'] = (targetInfo['left'] + 50);
		
		return contentInfo;
	};
	
})(jQuery);