/*! jquery.sifr.license.txt *//*

jQuery sIFR Plugin v3.0.1 <http://jquery.thewikies.com/sifr/>
Copyright (c) 2008 Jonathan Neal
This software is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
This software is released under the GPL License <http://www.opensource.org/licenses/gpl-2.0.php>

jQuery SWFObject Plugin v1.0.3 <http://jquery.thewikies.com/swfobject/>
Copyright (c) 2008 Jonathan Neal
This software is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
This software is released under the GPL License <http://www.opensource.org/licenses/gpl-2.0.php>

Scalable Inman Flash Replacement (sIFR) v3.0 <http://novemberborn.net/sifr3>
Copyright (c) 2008 Mike Davidson, Shaun Inman, Tomas Jogin and Mark Wubben
This software is released under the LGPL License <http://www.opensource.org/licenses/lgpl-2.1.php>

SWFObject v2.1 <http://code.google.com/p/swfobject/>
Copyright (c) 2007-2008 Geoff Stearns, Michael Williams, and Bobby van der Sluis
This software is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>

jQuery v1.2.6 <http://jquery.com/>
Copyright (c) 2008 John Resig
This software is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
This software is released under the GPL License <http://www.opensource.org/licenses/gpl-2.0.php>

*//*jslint
	passfail: false,
	white: true,
	browser: true,
	widget: false,
	sidebar: false,
	rhino: false,
	safe: false,
	adsafe: false,
	debug: false,
	evil: false,
	cap: false,
	on: false,
	fragment: false,
	laxbreak: false,
	forin: true,
	sub: false,
	css: false,
	undef: true,
	nomen: false,
	eqeqeq: true,
	plusplus: false,
	bitwise: true,
	regexp: false,
	onevar: true,
	strict: false
*//*global
	jQuery
*/

(function ($) {

	/* $.fn.sIFR */
	$.fn.sIFR = function (options) {
		var call = arguments.callee, $this = this, $each, each = 0, flashvars = {}, $alt, $swf, a, b, arrA, arrB, attachOptions = {}, o;

		// Build options
		options = $.extend({}, call.save, options);

		// Save options
		if (options.save === true) {
			delete options.save;
			call.save = $.extend(call.save, options);
			$.extend(options, call.save);
		}

		// Get cached 'o' functions
		o = call.options = call.options || {
			asHex: function (x) {
				var d = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];
				return isNaN(x) ? '00' : d[(x - x % 16) / 16] + d[x % 16];
			},
			colors: {
				aqua: [0, 255, 255],
				azure: [240, 255, 255],
				beige: [245, 245, 220],
				black: [0, 0, 0],
				blue: [0, 0, 255],
				brown: [165, 42, 42],
				cyan: [0, 255, 255],
				darkblue: [0, 0, 139],
				darkcyan: [0, 139, 139],
				darkgrey: [169, 169, 169],
				darkgreen: [0, 100, 0],
				darkkhaki: [189, 183, 107],
				darkmagenta: [139, 0, 139],
				darkolivegreen: [85, 107, 47],
				darkorange: [255, 140, 0],
				darkorchid: [153, 50, 204],
				darkred: [139, 0, 0],
				darksalmon: [233, 150, 122],
				darkviolet: [148, 0, 211],
				fuchsia: [255, 0, 255],
				gold: [255, 215, 0],
				green: [0, 128, 0],
				indigo: [75, 0, 130],
				khaki: [240, 230, 140],
				lightblue: [173, 216, 230],
				lightcyan: [224, 255, 255],
				lightgreen: [144, 238, 144],
				lightgrey: [211, 211, 211],
				lightpink: [255, 182, 193],
				lightyellow: [255, 255, 224],
				lime: [0, 255, 0],
				magenta: [255, 0, 255],
				maroon: [128, 0, 0],
				navy: [0, 0, 128],
				olive: [128, 128, 0],
				orange: [255, 165, 0],
				pink: [255, 192, 203],
				purple: [128, 0, 128],
				violet: [128, 0, 128],
				red: [255, 0, 0],
				silver: [192, 192, 192],
				white: [255, 255, 255],
				yellow: [255, 255, 0],
				transparent:  [255, 255, 255]
			},
			toHex: function (color) {
				var rgb;
				if (!color) {
					return false;
				}
				return (rgb = color.match(/rgb\(([0-9]+),\s([0-9]+),\s([0-9]+)\)/)) ? '#' + this.asHex(rgb[1]) + this.asHex(rgb[2]) + this.asHex(rgb[3]) : (rgb = this.colors[color]) ? '#' + this.asHex(rgb[0]) + this.asHex(rgb[1]) + this.asHex(rgb[2]) : (color.length === 4) ? color.replace(/\#([0-9A-z])([0-9A-z])([0-9A-z])/, '#$1$1$2$2$3$3') : color;
			}
		};

		// Exit if nothing passed into sIFR
		if ($this[0] === document || !$.hasFlashPlayer) {
			return this;
		}

		// Build sifted attachOptions
		for (a in options) {
			if (!(/color|css|cursor|delayRun|events|filter|fitExactly|fixHover|font|forceSingleLine|gridFitType|opacity|over|path|preventWrap|selectable|textTransform|tuneHeight|tuneWidth|version|zoom/.test(a))) {
				attachOptions[a] = options[a];
			}
		}

		// Build filters options
		if (typeof options.filter === 'object') {
			arrA = [];
			for (a in options.filter) {
				if (typeof options.filter[a] === 'object') {
					arrB = [];
					for (b in options.filter[a]) {
						arrB.push(b.replace(/([A-Z])/, '-$1').toLowerCase() + ':' + ((/color/.test(b)) ? '"0x' + o.toHex(options.filter[a][b]).substr(1) + '"' : options.filter[a][b]));
					}
					options.filter[a] = arrB.join(',');
				}
				arrA.push(a + ',' + options.filter[a]);
			}
			options.filter = arrA.join(',');
		}

		// Build font path and name
		o.font = (options.path || '').replace(/([^\/])$/, '$1/') + (options.font || $this.eq(0).css('fontFamily').replace(/^\s+|\s+$|,[\S|\s]+|'|"|(,)\s+/g, '$1')).replace(/([^\.][^s][^w][^f])$/, '$1.swf');

		// sIFR function
		while (($each = $this.eq(each++))[0]) {
			if ($each.hasClass('sIFR-replaced')) {
				$each.unsIFR();
			}

			// Re-sort HTML
			$each.addClass('sIFR-replaced')[0].innerHTML = '<span style="display:inline-block;position:relative;"><span class="sIFR-alternate" style="' + (($.browser.msie) ? 'zoom:1;filter:alpha(opacity=0)' : 'opacity:0') + ';">' + $each[0].innerHTML + '</span><span class="sIFR-flash" style="position:absolute;top:0;left:0;right:0;bottom:0;"></span></span>';

			$alt = $each.children().children().eq(0);
			$swf = $each.children().children().eq(1);

			o.content = options.content || $alt[0].innerHTML.replace(/(^|>)\s+|\s+(<|$)/g, '$1$2');

			// Configure dimensions
			o.zoomX = (options.zoomX || 1) * (options.zoom || 1);
			o.zoomY = (options.zoomY || 1) * (options.zoom || 1);
			o.overX = (options.overX || 1) * (options.over || 1);
			o.overY = (options.overY || 1) * (options.over || 1);

			o.old = ((options.version = parseInt(options.version, 10) || 2) === 2);

			attachOptions.height = (options.height || Math.max($each.height(), (parseInt($alt.css('lineHeight'), 10) || 0))) * o.overY;
			attachOptions.width = options.width || $alt.width() || $alt[0].clientWidth;

			$swf.css('marginLeft', (attachOptions.width - (attachOptions.width = attachOptions.width * o.overX)) / 2);

			// TextTransform options
			switch ((options.textTransform || $alt[0].style.textTransform).toLowerCase()) {
			case 'lowercase':
				o.content = o.content.toLowerCase();
				break;

			case 'uppercase':
				o.content = o.content.toUpperCase();
				break;

			case 'capitalize':
				a = o.content.split(/(\s|\>)/);
				o.content = '';
				for (b in a) {
					o.content += a[b].charAt(0).toUpperCase() + a[b].substr(1);
				}
			}

			// Build style attributes
			o.color = o.toHex(options.color || $alt.css('color'));
			o.fontWeight = (options.fontWeight || $alt[0].style.fontWeight.toString()).replace('400', 'normal').replace('700', 'bold');
			o.fontSize = (options.fontSize || parseInt($alt.css('fontSize'), 10)) * o.zoomY;
			o.lineHeight = parseInt((options.lineHeight || ($alt[0].style.lineHeight === 'normal') ? attachOptions.height : (/px/.test($alt[0].style.lineHeight)) ? parseInt($alt[0].style.lineHeight, 10) : o.fontSize * parseInt($alt[0].style.lineHeight, 10)), 10) || attachOptions.height;
			o.textAlign = options.textAlign || $alt[0].style.textAlign.toString();

			if (o.old) {
				flashvars = {
					textColor: o.color,
					leading:  o.lineHeight - o.fontSize,
					offsetTop: (o.lineHeight - o.fontSize) / 2
				};
				flashvars.linkColor = o.toHex(options.linkColor || $each.find('a').eq(0).css('color')) || o.color;
				flashvars.hoverColor = o.toHex(options.hoverColor) || flashvars.linkColor;
				if (!(flashvars.underline = (options.underline === true || $alt.css('textDecoration') === 'underline'))) {
					delete flashvars.underline;
				}
			}
			else {
				flashvars = {
					cursor: (options.cursor || $alt.css('cursor')).toString(),
					css: $.extend({
						'.sIFR-root': $.extend({
							color: o.color,
							fontWeight: o.fontWeight,
							lineHeight: o.lineHeight,
							textAlign: o.textAlign
						}, options.style)
					}, options.css),
					delayrun: options.delayRun || false,
					events: options.events || false,
					fitexactly: options.fitExactly || false,
					fixhover: options.fixHover || true,
					flashfilters: options.filter || '',
					forcesingleline: options.forceSingleLine || false,
					gridfittype: options.gridFitType || 'pixel',
					opacity: options.opacity || 100,
					preventwrap: options.preventWrap || false,
					size: o.fontSize,
					tuneheight: options.tuneHeight || 0,
					tunewidth: options.tuneWidth || 0,
					version: options.version
				};
				flashvars.selectable = options.selectable || ((/arrow|pointer/.test(flashvars.cursor)) ? false : true);
			}

			flashvars[o.old ? 'h' : 'height'] = attachOptions.height;
			flashvars[o.old ? 'w' : 'width'] = attachOptions.width;
			flashvars[o.old ? 'txt' : 'content'] = o.content;

			$swf.html($.flash($.extend({
				swf: o.font,
				params: {
					flashvars: flashvars,
					wmode: 'transparent'
				}
			}, attachOptions)));

			(function ($each) {
				var eachX, eachY;

				$(window).resize(function () {
					eachX = eachX || $each[0].childNodes[0].childNodes[0].offsetWidth;
					eachY = eachY || $each[0].childNodes[0].childNodes[0].offsetHeight;

					if (eachX !== $each[0].childNodes[0].childNodes[0].offsetWidth || eachY !== $each[0].childNodes[0].childNodes[0].offsetHeight) {
						eachX = $each[0].childNodes[0].childNodes[0].offsetWidth;
						eachY = $each[0].childNodes[0].childNodes[0].offsetHeight;
						$each.sIFR();
					}
				});
			}($each));
		}
	};


	/* $.fn.unSIFR */
	$.fn.unsIFR = function (options) {
		var $this = this, $each, i = 0;
		while ((($each = $this.eq(i++))[0]) && $each.hasClass('sIFR-replaced')) {
			$each.removeClass('sIFR-replaced')[0].innerHTML = $each[0].childNodes[0].childNodes[0].innerHTML;
		}
	};

	/* $.SIFR */
	$.sIFR = function (options) {
		$(document).sIFR(options);
	};

	/* Pre-execute to build cache */
	$.sIFR();
}(jQuery));