﻿/// <reference path="jquery-1.3.2-vsdoc2.js" />

// Simple JavaScript Templating
// John Resig - http://ejohn.org/ - MIT Licensed
(function(){
  var cache = {};
 
  this.tmpl = function tmpl(str, data){
    // Figure out if we're getting a template, or if we need to
    // load the template - and be sure to cache the result.
    var fn = !/\W/.test(str) ?
      cache[str] = cache[str] ||
        tmpl(document.getElementById(str).innerHTML) :
     
      // Generate a reusable function that will serve as a template
      // generator (and which will be cached).
      new Function("obj",
        "var p=[],print=function(){p.push.apply(p,arguments);};" +
       
        // Introduce the data as local variables using with(){}
        "with(obj){p.push('" +
       
        // Convert the template into pure JavaScript
        str
          .replace(/[\r\t\n]/g, " ")
          .split("<~").join("\t")
          .replace(/((^|~>)[^\t]*)'/g, "$1\r")
          .replace(/\t=(.*?)~>/g, "',$1,'")
          .split("\t").join("');")
          .split("~>").join("p.push('")
          .split("\r").join("\\'")
      + "');}return p.join('');");
   
    // Provide some basic currying to the user
    return data ? fn( data ) : fn;
  };
})();

/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);

/*
* Metadata - jQuery plugin for parsing metadata from elements
*
* Copyright (c) 2006 John Resig, Yehuda Katz, J�örn Zaefferer, Paul McLanahan
*
* Dual licensed under the MIT and GPL licenses:
*   http://www.opensource.org/licenses/mit-license.php
*   http://www.gnu.org/licenses/gpl.html
*
* Revision: $Id: jquery.metadata.js 3640 2007-10-11 18:34:38Z pmclanahan $
*
*/

/**
* Sets the type of metadata to use. Metadata is encoded in JSON, and each property
* in the JSON will become a property of the element itself.
*
* There are four supported types of metadata storage:
*
*   attr:  Inside an attribute. The name parameter indicates *which* attribute.
*          
*   class: Inside the class attribute, wrapped in curly braces: { }
*   
*   elem:  Inside a child element (e.g. a script tag). The
*          name parameter indicates *which* element.
*   html5: Values are stored in data-* attributes.
*          
* The metadata for an element is loaded the first time the element is accessed via jQuery.
*
* As a result, you can define the metadata type, use $(expr) to load the metadata into the elements
* matched by expr, then redefine the metadata type and run another $(expr) for other elements.
* 
* @name $.metadata.setType
*
* @example <p id="one" class="some_class {item_id: 1, item_label: 'Label'}">This is a p</p>
* @before $.metadata.setType("class")
* @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
* @desc Reads metadata from the class attribute
* 
* @example <p id="one" class="some_class" data="{item_id: 1, item_label: 'Label'}">This is a p</p>
* @before $.metadata.setType("attr", "data")
* @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
* @desc Reads metadata from a "data" attribute
* 
* @example <p id="one" class="some_class"><script>{item_id: 1, item_label: 'Label'}</script>This is a p</p>
* @before $.metadata.setType("elem", "script")
* @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
* @desc Reads metadata from a nested script element
* 
* @example <p id="one" class="some_class" data-item_id="1" data-item_label="Label">This is a p</p>
* @before $.metadata.setType("html5")
* @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
* @desc Reads metadata from a series of data-* attributes
*
* @param String type The encoding type
* @param String name The name of the attribute to be used to get metadata (optional)
* @cat Plugins/Metadata
* @descr Sets the type of encoding to be used when loading metadata for the first time
* @type undefined
* @see metadata()
*/

(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 = "{}";

                var getData = function(data) {
                    if (typeof data != "string") return data;

                    if (data.indexOf('{') < 0) {
                        data = eval("(" + data + ")");
                    }
                }

                var getObject = function(data) {
                    if (typeof data != "string") return data;

                    data = eval("(" + data + ")");
                    return data;
                }

                if (settings.type == "html5") {
                    var object = {};
                    $(elem.attributes).each(function() {
                        var name = this.nodeName;
                        if (name.match(/^data-/)) name = name.replace(/^data-/, '');
                        else return true;
                        object[name] = getObject(this.nodeValue);
                    });
                } else {
                    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;
                        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;
                    }
                    object = getObject(data.indexOf("{") < 0 ? "{" + data + "}" : data);
                }

                $.data(elem, settings.single, object);
                return object;
            }
        }
    });

    /**
    * 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);


/*
* jQuery Media Plugin for converting elements into rich media content.
*
* Examples and documentation at: http://malsup.com/jquery/media/
* Copyright (c) 2007-2008 M. Alsup
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* @author: M. Alsup
* @version: 0.92 (24-SEP-2009)
* @requires jQuery v1.1.2 or later
* $Id: jquery.media.js 2460 2007-07-23 02:53:15Z malsup $
*
* Supported Media Players:
*	- Flash
*	- Quicktime
*	- Real Player
*	- Silverlight
*	- Windows Media Player
*	- iframe
*
* Supported Media Formats:
*	 Any types supported by the above players, such as:
*	 Video: asf, avi, flv, mov, mpg, mpeg, mp4, qt, smil, swf, wmv, 3g2, 3gp
*	 Audio: aif, aac, au, gsm, mid, midi, mov, mp3, m4a, snd, rm, wav, wma
*	 Other: bmp, html, pdf, psd, qif, qtif, qti, tif, tiff, xaml
*
* Thanks to Mark Hicken and Brent Pedersen for helping me debug this on the Mac!
* Thanks to Dan Rossi for numerous bug reports and code bits!
* Thanks to Skye Giordano for several great suggestions!
* Thanks to Richard Connamacher for excellent improvements to the non-IE behavior!
*/
; (function($) {

    /**
    * Chainable method for converting elements into rich media.
    *
    * @param options
    * @param callback fn invoked for each matched element before conversion
    * @param callback fn invoked for each matched element after conversion
    */
    $.fn.media = function(options, f1, f2) {
        if (options == 'undo') {
            return this.each(function() {
                var $this = $(this);
                var html = $this.data('media.origHTML');
                if (html)
                    $this.replaceWith(html);
            });
        }

        return this.each(function() {
            if (typeof options == 'function') {
                f2 = f1;
                f1 = options;
                options = {};
            }
            var o = getSettings(this, options);
            // pre-conversion callback, passes original element and fully populated options
            if (typeof f1 == 'function') f1(this, o);

            var r = getTypesRegExp();
            var m = r.exec(o.src.toLowerCase()) || [''];

            o.type ? m[0] = o.type : m.shift();
            for (var i = 0; i < m.length; i++) {
                fn = m[i].toLowerCase();
                if (isDigit(fn[0])) fn = 'fn' + fn; // fns can't begin with numbers
                if (!$.fn.media[fn])
                    continue;  // unrecognized media type
                // normalize autoplay settings
                var player = $.fn.media[fn + '_player'];
                if (!o.params) o.params = {};
                if (player) {
                    var num = player.autoplayAttr == 'autostart';
                    o.params[player.autoplayAttr || 'autoplay'] = num ? (o.autoplay ? 1 : 0) : o.autoplay ? true : false;
                }
                var $div = $.fn.media[fn](this, o);

                $div.css('backgroundColor', o.bgColor).width(o.width);

                if (o.canUndo) {
                    var $temp = $('<div></div>').append(this);
                    $div.data('media.origHTML', $temp.html()); // store original markup
                }

                // post-conversion callback, passes original element, new div element and fully populated options
                if (typeof f2 == 'function') f2(this, $div[0], o, player.name);
                break;
            }
        });
    };

    /**
    * Non-chainable method for adding or changing file format / player mapping
    * @name mapFormat
    * @param String format File format extension (ie: mov, wav, mp3)
    * @param String player Player name to use for the format (one of: flash, quicktime, realplayer, winmedia, silverlight or iframe
    */
    $.fn.media.mapFormat = function(format, player) {
        if (!format || !player || !$.fn.media.defaults.players[player]) return; // invalid
        format = format.toLowerCase();
        if (isDigit(format[0])) format = 'fn' + format;
        $.fn.media[format] = $.fn.media[player];
        $.fn.media[format + '_player'] = $.fn.media.defaults.players[player];
    };

    // global defautls; override as needed
    $.fn.media.defaults = {
        standards: false,      // use object tags only (no embeds for non-IE browsers)
        canUndo: true,       // tells plugin to store the original markup so it can be reverted via: $(sel).mediaUndo()
        width: 400,
        height: 400,
        autoplay: 0, 	   	// normalized cross-player setting
        bgColor: '#ffffff', 	// background color
        params: { wmode: 'transparent' }, // added to object element as param elements; added to embed element as attrs
        attrs: {}, 		// added to object and embed elements as attrs
        flvKeyName: 'file', 	// key used for object src param (thanks to Andrea Ercolino)
        flashvars: {}, 		// added to flash content as flashvars param/attr
        flashVersion: '7', // required flash version
        expressInstaller: null, // src for express installer

        // default flash video and mp3 player (@see: http://jeroenwijering.com/?item=Flash_Media_Player)
        flvPlayer: '/media/player.swf',
        mp3Player: '/media/player.swf',

        // @see http://msdn2.microsoft.com/en-us/library/bb412401.aspx
        silverlight: {
            inplaceInstallPrompt: 'true', // display in-place install prompt?
            isWindowless: 'true', // windowless mode (false for wrapping markup)
            framerate: '24',   // maximum framerate
            version: '0.9',  // Silverlight version
            onError: null,   // onError callback
            onLoad: null,   // onLoad callback
            initParams: null,   // object init params
            userContext: null	  // callback arg passed to the load callback
        }
    };

    // Media Players; think twice before overriding
    $.fn.media.defaults.players = {
        flash: {
            name: 'flash',
            title: 'Flash',
            types: 'flv,mp3,swf',
            mimetype: 'application/x-shockwave-flash',
            pluginspage: 'http://www.adobe.com/go/getflashplayer',
            ieAttrs: {
                classid: 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000',
                type: 'application/x-oleobject',
                codebase: 'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + $.fn.media.defaults.flashVersion
            }
        },
        quicktime: {
            name: 'quicktime',
            title: 'QuickTime',
            mimetype: 'video/quicktime',
            pluginspage: 'http://www.apple.com/quicktime/download/',
            types: 'aif,aiff,aac,au,bmp,gsm,mov,mid,midi,mpg,mpeg,mp4,m4a,psd,qt,qtif,qif,qti,snd,tif,tiff,wav,3g2,3gp',
            ieAttrs: {
                classid: 'clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B',
                codebase: 'http://www.apple.com/qtactivex/qtplugin.cab'
            }
        },
        realplayer: {
            name: 'real',
            title: 'RealPlayer',
            types: 'ra,ram,rm,rpm,rv,smi,smil',
            mimetype: 'audio/x-pn-realaudio-plugin',
            pluginspage: 'http://www.real.com/player/',
            autoplayAttr: 'autostart',
            ieAttrs: {
                classid: 'clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA'
            }
        },
        winmedia: {
            name: 'winmedia',
            title: 'Windows Media',
            types: 'asx,asf,avi,wma,wmv',
            mimetype: $.browser.mozilla && isFirefoxWMPPluginInstalled() ? 'application/x-ms-wmp' : 'application/x-mplayer2',
            pluginspage: 'http://www.microsoft.com/Windows/MediaPlayer/',
            autoplayAttr: 'autostart',
            oUrl: 'url',
            ieAttrs: {
                classid: 'clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6',
                type: 'application/x-oleobject'
            }
        },
        // special cases
        iframe: {
            name: 'iframe',
            types: 'html,pdf'
        },
        silverlight: {
            name: 'silverlight',
            types: 'xaml'
        }
    };

    //
    //	everything below here is private
    //


    // detection script for FF WMP plugin (http://www.therossman.org/experiments/wmp_play.html)
    // (hat tip to Mark Ross for this script)
    function isFirefoxWMPPluginInstalled() {
        var plugs = navigator.plugins;
        for (var i = 0; i < plugs.length; i++) {
            var plugin = plugs[i];
            if (plugin['filename'] == 'np-mswmp.dll')
                return true;
        }
        return false;
    }

    var counter = 1;

    for (var player in $.fn.media.defaults.players) {
        var types = $.fn.media.defaults.players[player].types;
        $.each(types.split(','), function(i, o) {
            if (isDigit(o[0])) o = 'fn' + o;
            $.fn.media[o] = $.fn.media[player] = getGenerator(player);
            $.fn.media[o + '_player'] = $.fn.media.defaults.players[player];
        });
    };

    function getTypesRegExp() {
        var types = '';
        for (var player in $.fn.media.defaults.players) {
            if (types.length) types += ',';
            types += $.fn.media.defaults.players[player].types;
        };
        return new RegExp('\\.(' + types.replace(/,/ig, '|') + ')\\b');
    };

    function getGenerator(player) {
        return function(el, options) {
            return generate(el, options, player);
        };
    };

    function isDigit(c) {
        return '0123456789'.indexOf(c) > -1;
    };

    // flatten all possible options: global defaults, meta, option obj
    function getSettings(el, options) {
        options = options || {};
        var $el = $(el);
        var cls = el.className || '';
        // support metadata plugin (v1.0 and v2.0)
        var meta = $.metadata ? $el.metadata() : $.meta ? $el.data() : {};
        meta = meta || {};
        var w = meta.width || parseInt(((cls.match(/w:(\d+)/) || [])[1] || 0));
        var h = meta.height || parseInt(((cls.match(/h:(\d+)/) || [])[1] || 0));

        if (w) meta.width = w;
        if (h) meta.height = h;
        if (cls) meta.cls = cls;

        var a = $.fn.media.defaults;
        var b = options;
        var c = meta;

        var p = { params: { bgColor: options.bgColor || $.fn.media.defaults.bgColor} };
        var opts = $.extend({}, a, b, c);
        $.each(['attrs', 'params', 'flashvars', 'silverlight'], function(i, o) {
            opts[o] = $.extend({}, p[o] || {}, a[o] || {}, b[o] || {}, c[o] || {});
        });

        if (typeof opts.caption == 'undefined') opts.caption = $el.text();

        // make sure we have a source!
        opts.src = opts.src || $el.attr('href') || $el.attr('src') || 'unknown';
        return opts;
    };

    //
    //	Flash Player
    //

    // generate flash using SWFObject library if possible
    $.fn.media.swf = function(el, opts) {
        if (!window.SWFObject && !window.swfobject) {
            // roll our own
            if (opts.flashvars) {
                var a = [];
                for (var f in opts.flashvars)
                    a.push(f + '=' + opts.flashvars[f]);
                if (!opts.params) opts.params = {};
                opts.params.flashvars = a.join('&');
            }
            return generate(el, opts, 'flash');
        }

        var id = el.id ? (' id="' + el.id + '"') : '';
        var cls = opts.cls ? (' class="' + opts.cls + '"') : '';
        var $div = $('<div' + id + cls + '>');

        // swfobject v2+
        if (window.swfobject) {
            $(el).after($div).appendTo($div);
            if (!el.id) el.id = 'movie_player_' + counter++;

            // replace el with swfobject content
            swfobject.embedSWF(opts.src, el.id, opts.width, opts.height, opts.flashVersion,
			opts.expressInstaller, opts.flashvars, opts.params, opts.attrs);
        }
        // swfobject < v2
        else {
            $(el).after($div).remove();
            var so = new SWFObject(opts.src, 'movie_player_' + counter++, opts.width, opts.height, opts.flashVersion, opts.bgColor);
            if (opts.expressInstaller) so.useExpressInstall(opts.expressInstaller);

            for (var p in opts.params)
                if (p != 'bgColor') so.addParam(p, opts.params[p]);
            for (var f in opts.flashvars)
                so.addVariable(f, opts.flashvars[f]);
            so.write($div[0]);
        }

        if (opts.caption) $('<div>').appendTo($div).html(opts.caption);
        return $div;
    };

    // map flv and mp3 files to the swf player by default
    $.fn.media.flv = $.fn.media.mp3 = function(el, opts) {
        var src = opts.src;
        var player = /\.mp3\b/i.test(src) ? $.fn.media.defaults.mp3Player : $.fn.media.defaults.flvPlayer;
        var key = opts.flvKeyName;
        src = encodeURIComponent(src);
        opts.src = player;
        opts.src = opts.src + '?' + key + '=' + (src);
        var srcObj = {};
        srcObj[key] = src;
        opts.flashvars = $.extend({}, srcObj, opts.flashvars);
        return $.fn.media.swf(el, opts);
    };

    //
    //	Silverlight
    //
    $.fn.media.xaml = function(el, opts) {
        if (!window.Sys || !window.Sys.Silverlight) {
            if ($.fn.media.xaml.warning) return;
            $.fn.media.xaml.warning = 1;
            alert('You must include the Silverlight.js script.');
            return;
        }

        var props = {
            width: opts.width,
            height: opts.height,
            background: opts.bgColor,
            inplaceInstallPrompt: opts.silverlight.inplaceInstallPrompt,
            isWindowless: opts.silverlight.isWindowless,
            framerate: opts.silverlight.framerate,
            version: opts.silverlight.version
        };
        var events = {
            onError: opts.silverlight.onError,
            onLoad: opts.silverlight.onLoad
        };

        var id1 = el.id ? (' id="' + el.id + '"') : '';
        var id2 = opts.id || 'AG' + counter++;
        // convert element to div
        var cls = opts.cls ? (' class="' + opts.cls + '"') : '';
        var $div = $('<div' + id1 + cls + '>');
        $(el).after($div).remove();

        Sys.Silverlight.createObjectEx({
            source: opts.src,
            initParams: opts.silverlight.initParams,
            userContext: opts.silverlight.userContext,
            id: id2,
            parentElement: $div[0],
            properties: props,
            events: events
        });

        if (opts.caption) $('<div>').appendTo($div).html(opts.caption);
        return $div;
    };

    //
    // generate object/embed markup
    //
    function generate(el, opts, player) {
        var $el = $(el);
        var o = $.fn.media.defaults.players[player];

        if (player == 'iframe') {
            var o = $('<iframe' + ' width="' + opts.width + '" height="' + opts.height + '" >');
            o.attr('src', opts.src);
            o.css('backgroundColor', o.bgColor);
        }
        else if ($.browser.msie) {
            var a = ['<object width="' + opts.width + '" height="' + opts.height + '" '];
            for (var key in opts.attrs)
                a.push(key + '="' + opts.attrs[key] + '" ');
            for (var key in o.ieAttrs || {}) {
                var v = o.ieAttrs[key];
                if (key == 'codebase' && window.location.protocol == 'https:')
                    v = v.replace('http', 'https');
                a.push(key + '="' + v + '" ');
            }
            a.push('></ob' + 'ject' + '>');
            var p = ['<param name="' + (o.oUrl || 'src') + '" value="' + opts.src + '">'];
            for (var key in opts.params)
                p.push('<param name="' + key + '" value="' + opts.params[key] + '">');
            var o = document.createElement(a.join(''));
            for (var i = 0; i < p.length; i++)
                o.appendChild(document.createElement(p[i]));
        }
        else if (o.standards) {
            // Rewritten to be standards compliant by Richard Connamacher
            var a = ['<object type="' + o.mimetype + '" width="' + opts.width + '" height="' + opts.height + '"'];
            if (opts.src) a.push(' data="' + opts.src + '" ');
            a.push('>');
            a.push('<param name="' + (o.oUrl || 'src') + '" value="' + opts.src + '">');
            for (var key in opts.params) {
                if (key == 'wmode' && player != 'flash') // FF3/Quicktime borks on wmode
                    continue;
                a.push('<param name="' + key + '" value="' + opts.params[key] + '">');
            }
            // Alternate HTML
            a.push('<div><p><strong>' + o.title + ' Required</strong></p><p>' + o.title + ' is required to view this media. <a href="' + o.pluginspage + '">Download Here</a>.</p></div>');
            a.push('</ob' + 'ject' + '>');
        }
        else {
            var a = ['<embed width="' + opts.width + '" height="' + opts.height + '" style="display:block"'];
            if (opts.src) a.push(' src="' + opts.src + '" ');
            for (var key in opts.attrs)
                a.push(key + '="' + opts.attrs[key] + '" ');
            for (var key in o.eAttrs || {})
                a.push(key + '="' + o.eAttrs[key] + '" ');
            for (var key in opts.params) {
                if (key == 'wmode' && player != 'flash') // FF3/Quicktime borks on wmode
                    continue;
                a.push(key + '="' + opts.params[key] + '" ');
            }
            a.push('></em' + 'bed' + '>');
        }
        // convert element to div
        var id = el.id ? (' id="' + el.id + '"') : '';
        var cls = opts.cls ? (' class="' + opts.cls + '"') : '';
        var $div = $('<div' + id + cls + '>');
        $el.after($div).remove();
        ($.browser.msie || player == 'iframe') ? $div.append(o) : $div.html(a.join(''));
        if (opts.caption) $('<div>').appendTo($div).html(opts.caption);
        return $div;
    };


})(jQuery);

$( function() { $(".embed-media").media(); });


(function($){

var waitingFor = 0,
    waitInterval,
    $waitElement,
    dot = "&#9646;",
    nodot = "&#9647;",
    dots = 3;
    
    var i = 0;
    var animate = function(){
        if (waitingFor <= 0) 
        {
            $waitElement.fadeOut();
        } else {
            $waitElement.fadeIn();
            var string = "";
            for (var j = 0; j < dots; j++){
                if (i == j) string += dot;
                else string += nodot;
            }
            $waitElement.html(string);
            i = (i + 1) % (dots * 2);
        }
    };

$.loadingWait = function(){
    waitingFor++;
    
    if (!$waitElement) $waitElement = $("<div id='wait' />").appendTo("#subhead h1.logo");
    if (!waitInterval) { waitInterval = window.setInterval(animate, 250); }
    
    return function(){
        waitingFor--;
    } 
}
})(jQuery)

$( function(){
    
    var pageDone = $.loadingWait()
    $(window).load(pageDone);

    $("#messages .message .remove").click(function(){
        var $self = $(this).parent();
        var loadingDone = $.loadingWait();
        $.ajax({
                url:"/SiteMessagesService.asmx/RemoveMessage",
                data:$.jsonSerialize({Id:$self.attr("id")}),
                success: function(r){
                    $self.slideUp();
                    loadingDone();
                }
            });
    });
   

    $("#sideNav.dynamic")
        .accordion({
            active:$("#sideNav li.current :first-child"),
            header:"> li:not(.parent):has(ul) > :first-child",
            event:"click",
            autoHeight:false,
            collapsible:true})
        .find("> li:not(.parent):not(:has(ul))")
            .addClass("empty")
            .end()
        .find("> li:not(.parent):not(.empty) > :first-child a")
            .bind("click", function(){ window.location = this.href; })
            .end();
    
    var baseline = 15;
    $.fn.baseline = function(baseline){
        return $(this).each( function(){ 
            var $this = $(this);
            $this.css("marginBottom", baseline - ($this.height() % baseline));
        });
    }
    
    
//    $("#content img").bind("load", function(e){
//        $(this).baseline(baseline);
//    });
//    $(window).bind("load", function(){
//        $("#content img").baseline(baseline);
//    });
    $("table tbody tr").each(function(i, row){
        if (i % 2) $(row).addClass("alt");
    });
});

(function($) {
    $.fn.starRating = function(starCount) {
        var _self = this;

        if (typeof starCount == "undefined") {
            return {
                get: function() {
                    if (_self.length < 1) return 0;

                    var total = 0;
                    _self.each(function() { total += this.rating });
                    return total / _self.length;
                }, set: function(starRating) {
                    _self.each(function() { this.setStars(starRating) });
                }
            }
        }

        return _self.each(function() {
            var self = this,
            $self = $(self),
            $stars;
            self.rating = 0;

            var makeStars = function() {
                for (var i = 0; i < starCount; i++) {
                    $self.append("<span class='star'>&nbsp;</span>");
                }

                $stars = $self.find(".star");
            }
            self.setStars = function(starRating) {
                self.rating = starRating;
                showStars(self.rating);
            }
            var showStars = function(starRating) {
                $stars.removeClass("starred");
                for (var i = 0; i < starRating; i++) {
                    $stars.eq(i).addClass("starred");
                }
            }

            makeStars();
            showStars(self.rating);

            $stars
            .bind("mousedown", function() { return false; })
            .bind("mouseover", function() {
                showStars($stars.index(this) + 1);
            })
            .bind("mouseout", function() {
                showStars(self.rating);
            })
            .bind("click", function() {
                self.setStars($stars.index(this) + 1);
            });
        });
    }
    $.ajaxSetup({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        data: "{}",
        dataFilter: function(data) {
            var msg;

            if (typeof (JSON) !== 'undefined' &&
        typeof (JSON.parse) === 'function')
                msg = JSON.parse(data);
            else
                msg = eval('(' + data + ')');

            return msg;
        }
    });
    $.fn.ajaxLoadControl = function(virtualPath, refreshDelay, suppressError) {

        var $self = this,
        doLoad = function() {
            var loadingDone = $.loadingWait();
            $.ajax({
                url: "/LoadControl.asmx/Load",
                data: $.jsonSerialize({ virtualPath: virtualPath }),
                success: function(r) {
                    $self.empty().append(r.d);
                    loadingDone();
                },
                error: function(r) {
                    if (suppressError) return;
                    $self.empty().append("<strong>Error!</strong>");
                    loadingDone();
                }
            });
        }


        doLoad();

        if (refreshDelay && refreshDelay > 0) setInterval(doLoad, refreshDelay);
    }
    $.formatString = function(string, object) {
        var tokens = object;
        if (tokens.constructor != Object) {
            var temp = [];
            for (var i = 1; i < length; i++) {
                temp[i - 1] = arguments[i];
            }
            tokens = temp;
        }

        $.each(tokens, function(key, value) {
            string = string.replace(new RegExp("\{" + key + "\}", "g"), value);
        });

        return string;
    }
    $.hash = function(object) {
        var pairs = [];
        $.each(object, function(k, v) {
            switch (v.constructor) {
                case Number:
                case Boolean:
                    pairs.push(k + "=" + v.toString());
                    break;
                case String:
                    pairs.push(k + "='" + v.replace(/(?!\\)\'/gi, "\\'") + "'");
                    break;
            }
        })
        return pairs.join("&");
    };
    $.jsonSerialize = function(object) {
        var ser = $.jsonSerialize;
        switch (object.constructor) {
            case Object:
                var pairs = [];
                $.each(object, function(k, v) {
                    pairs[pairs.length] = ["'" + k + "'", ser(v)].join(":");
                });
                return "{" + pairs.join(",") + "}";
                break;
            case Array:
                var strings = [];
                $.each(object, function(i, v) {
                    strings[strings.length] = ser(v);
                });
                return "[" + strings.join(",") + "]";
                break;
            case Number:
            case Boolean:
                return object.toString();
                break;
            case String:
                return "'" + object.replace(/(?!\\)\'/gi, "\\'") + "'";
                break;
        }
    };

    $.jsonDeserialize = function(hashString) {
        return eval("(" + hashString + ")");
    };


})(jQuery)
