﻿
/* == jQuery Sifr Plugin (with selectors) == */
jQuery.fn.sifr = function(prefs) {

    /* == If false is set, set for unSIFR == */
    if (prefs === false) prefs = { unsifr: true };

    /* == Combine the current preferences with the saved preferences == */
    prefs = jQuery.extend({}, arguments.callee.prefs, prefs);

    /* == If prefs.saved is true, save preferences == */
    if (prefs.save) {
        arguments.callee.prefs = jQuery.extend(
			{
			    /* Absolute Offset X ...... */absoluteOffsetX: null, aoX: null,
			    /* Absolute Offset Y ...... */absoluteOffsetY: null, aoY: null,
			    /* Relative Offset X ...... */relativeOffsetX: null, roX: null,
			    /* Relative Offset Y ...... */relativeOffsetY: null, roY: null,
			    /* Font Path .............. */path: null,
			    /* Font File .............. */font: null,
			    /* Font Size .............. */fontSize: null,
			    /* Text Color ............. */color: null,
			    /* Text Underline ......... */underline: null,
			    /* Text Transform ......... */textTransform: null,
			    /* Text Link Color ........ */link: null,
			    /* Text Hover Color ....... */hover: null,
			    /* Background Color ....... */backgroundColor: null,
			    /* Text Align on X ........ */textAlign: null,
			    /* Content ................ */content: null,
			    /* Width .................. */width: null,
			    /* Height ................. */height: null
			},
			arguments.callee.prefs,
			prefs,
			{ save: false }
		);
    }

    /* == jQuery Sifr Function == */
    return this.each(function() {

        /* == Set the current element as 'o' == */
        var o = jQuery(this);

        /* == If necessary or required, unSIFR text == */
        if (o.is('.sifr') || (prefs.unsifr && o.is('.sifr'))) {

            /* == Restore element with unSIFRed text == */
            o.html(jQuery(this.firstChild).html());
            o.removeClass('sifr');

        }

        /* == SIFR Element == */
        if (!prefs.unsifr) {

            /* == Collect Settings == */
            var s = jQuery.extend({}, arguments.callee.prefs, prefs);

            /* == Converts color to HEX == */
            var hex = function(N) {
                if (N == null) return "00";
                N = parseInt(N);
                if (N == 0 || isNaN(N)) return "00";
                N = Math.max(0, N);
                N = Math.min(N, 255);
                N = Math.round(N);
                return "0123456789ABCDEF".charAt((N - N % 16) / 16) + "0123456789ABCDEF".charAt(N % 16);
            };

            /* == Converts colors to HEX == */
            var hexed = function(color) {
                if (!color) { return false; }
                if (color.search('rgb') > -1) {
                    color = color.substr(4, color.length - 5).split(', ');
                    color = hex(color[0]) + hex(color[1]) + hex(color[2]);
                }
                color = color.replace('#', '');
                if (color.length < 6) {
                    color = color.substr(0, 1) + color.substr(0, 1) + color.substr(1, 1) + color.substr(1, 1) + color.substr(2, 1) + color.substr(2, 1);
                }
                return '#' + color;
            };

            /* == Evaluates Sifr Settings == */
            /* Add Sifr Class ......... */o.addClass('sifr');
            /* Font File .............. */s.font = s.font || (/([^\'\",]+)[,]?/.exec(o.css('fontFamily')) || [, ])[1];
            /* Font Color ............. */s.color = hexed(s.color || o.css('color'));
            /* Link Color ............. */s.link = hexed(s.link || o.children('a').css('color')) || s.color;
            /* Link Hover Color ....... */s.hover = hexed(s.hover) || s.link;
            /* Link Underline ......... */s.underline = (s.underline || (o.css('textDecoration') == 'underline')) ? true : null;
            /* Background Color ....... */o.css('backgroundColor', hexed(s.backgroundColor));
            /* Text Align on X ........ */s.textAlign = s.textAlign || o.css('textAlign') || 'left';
            /* Text Part 1 ............ */o.html('<span style="display:inline;margin:0;padding:0;float:none;width:auto;height:auto;font-weight:inherit;">' + o.html() + '</span>');
            /* Text Part 2 ............ */var oc = jQuery(this.firstChild);
            /* Text Align on Y ........ */s.ieM = (o.height() - oc.height()) / 2;
            s.ieM = (jQuery.browser.msie) ? 'height:' + (o.height() - s.ieM) + 'px;margin:' + s.ieM + 'px 0 0;vertical-align:middle;' : 'vertical-align:middle;';
            /* Text Size .............. */
            if (s.fontSize) oc.css('fontSize', s.fontSize);
            /* Text Transform ......... */s.textTransform = s.textTransform || o.css('textTransform');
            if (s.textTransform == 'uppercase') s.content = oc.html().toUpperCase();
            if (s.textTransform == 'lowercase') s.content = oc.html().toLowerCase();
            if (s.textTransform == 'capitalize') {
                var c = oc.html().replace(/^\s+|\s+$/g, '').replace(/\>/g, '> ').split(' ');
                for (var i = 0; i < c.length; i++) {
                    c[i] = c[i].charAt(0).toUpperCase() + c[i].substring(1);
                }
                s.content = c.join(' ').replace(/\> /g, '>');
            }
            /* Content ................ */s.content = s.content || oc.html();
            /* Width .................. */s.width = s.width || oc.width();
            /* Height ................. */s.height = s.height || oc.height();
            /* Relative Offset X ...... */s.aoX = (s.aoX || 0) + ((s.width / 100) * (s.roX || 0));
            /* Relative Offset Y ...... */s.aoY = (s.aoY || 0) + ((s.height / 100) * (s.roY || 0));

            /* == Hide == */
            oc.hide();

            o.flash(
            /* == Flash Configuration Part 1: Flash Settings & Style == */
				{
				/* == Assign Sifr Font File == */
				src: s.path + s.font + '.swf',

				/* == Assign Sifr Style == */
				flashvars: {
				    txt: s.content.replace(/^\s+|\s+$/g, ''),
				    w: s.width,
				    h: s.height,
				    offsetLeft: s.aoX,
				    offsetTop: s.aoY,
				    textalign: s.textAlign,
				    textcolor: s.color,
				    linkColor: s.link,
				    hoverColor: s.hover,
				    underline: s.underline
				}

},

            /* == Flash Configuration Part 2: Flash Requirements == */
				{
				version: 7,
				update: false
},

            /* == Flash Configuration Part 3: Flash Settings & Execution == */
				function(htmlOptions) {

				    htmlOptions.style = s.ieM;
				    htmlOptions.wmode = 'transparent';
				    htmlOptions.width = s.width;
				    htmlOptions.height = s.height;
				    o.append(jQuery.fn.flash.transform(htmlOptions));

				}

			);

        }

    });

};

/* == jQuery Sifr Plugin (without selectors) == */
jQuery.sifr = jQuery(document).sifr;


/**
* Flash (http://jquery.lukelutman.com/plugins/flash)
* A jQuery plugin for embedding Flash movies.
* 
* Version 1.0
* November 9th, 2006
*
* Copyright (c) 2006 Luke Lutman (http://www.lukelutman.com)
* Dual licensed under the MIT and GPL licenses.
* http://www.opensource.org/licenses/mit-license.php
* http://www.opensource.org/licenses/gpl-license.php
* 
* Inspired by:
* SWFObject (http://blog.deconcept.com/swfobject/)
* UFO (http://www.bobbyvandersluis.com/ufo/)
* sIFR (http://www.mikeindustries.com/sifr/)
* 
* IMPORTANT: 
* The packed version of jQuery breaks ActiveX control
* activation in Internet Explorer. Use JSMin to minifiy
* jQuery (see: http://jquery.lukelutman.com/plugins/flash#activex).
*
**/
; (function() {

    var $$;

    /**
    * 
    * @desc Replace matching elements with a flash movie.
    * @author Luke Lutman
    * @version 1.0.1
    *
    * @name flash
    * @param Hash htmlOptions Options for the embed/object tag.
    * @param Hash pluginOptions Options for detecting/updating the Flash plugin (optional).
    * @param Function replace Custom block called for each matched element if flash is installed (optional).
    * @param Function update Custom block called for each matched if flash isn't installed (optional).
    * @type jQuery
    *
    * @cat plugins/flash
    * 
    * @example $('#hello').flash({ src: 'hello.swf' });
    * @desc Embed a Flash movie.
    *
    * @example $('#hello').flash({ src: 'hello.swf' }, { version: 8 });
    * @desc Embed a Flash 8 movie.
    *
    * @example $('#hello').flash({ src: 'hello.swf' }, { expressInstall: true });
    * @desc Embed a Flash movie using Express Install if flash isn't installed.
    *
    * @example $('#hello').flash({ src: 'hello.swf' }, { update: false });
    * @desc Embed a Flash movie, don't show an update message if Flash isn't installed.
    *
    **/
    $$ = jQuery.fn.flash = function(htmlOptions, pluginOptions, replace, update) {

        // Set the default block.
        var block = replace || $$.replace;

        // Merge the default and passed plugin options.
        pluginOptions = $$.copy($$.pluginOptions, pluginOptions);

        // Detect Flash.
        if (!$$.hasFlash(pluginOptions.version)) {
            // Use Express Install (if specified and Flash plugin 6,0,65 or higher is installed).
            if (pluginOptions.expressInstall && $$.hasFlash(6, 0, 65)) {
                // Add the necessary flashvars (merged later).
                var expressInstallOptions = {
                    flashvars: {
                        MMredirectURL: location,
                        MMplayerType: 'PlugIn',
                        MMdoctitle: jQuery('title').text()
                    }
                };
                // Ask the user to update (if specified).
            } else if (pluginOptions.update) {
                // Change the block to insert the update message instead of the flash movie.
                block = update || $$.update;
                // Fail
            } else {
                // The required version of flash isn't installed.
                // Express Install is turned off, or flash 6,0,65 isn't installed.
                // Update is turned off.
                // Return without doing anything.
                return this;
            }
        }

        // Merge the default, express install and passed html options.
        htmlOptions = $$.copy($$.htmlOptions, expressInstallOptions, htmlOptions);

        // Invoke $block (with a copy of the merged html options) for each element.
        return this.each(function() {
            block.call(this, $$.copy(htmlOptions));
        });

    };
    /**
    *
    * @name flash.copy
    * @desc Copy an arbitrary number of objects into a new object.
    * @type Object
    * 
    * @example $$.copy({ foo: 1 }, { bar: 2 });
    * @result { foo: 1, bar: 2 };
    *
    **/
    $$.copy = function() {
        var options = {}, flashvars = {};
        for (var i = 0; i < arguments.length; i++) {
            var arg = arguments[i];
            if (arg == undefined) continue;
            jQuery.extend(options, arg);
            // don't clobber one flash vars object with another
            // merge them instead
            if (arg.flashvars == undefined) continue;
            jQuery.extend(flashvars, arg.flashvars);
        }
        options.flashvars = flashvars;
        return options;
    };
    /*
    * @name flash.hasFlash
    * @desc Check if a specific version of the Flash plugin is installed
    * @type Boolean
    *
    **/
    $$.hasFlash = function() {
        // look for a flag in the query string to bypass flash detection
        if (/hasFlash\=true/.test(location)) return true;
        if (/hasFlash\=false/.test(location)) return false;
        var pv = $$.hasFlash.playerVersion().match(/\d+/g);
        var rv = String([arguments[0], arguments[1], arguments[2]]).match(/\d+/g) || String($$.pluginOptions.version).match(/\d+/g);
        for (var i = 0; i < 3; i++) {
            pv[i] = parseInt(pv[i] || 0);
            rv[i] = parseInt(rv[i] || 0);
            // player is less than required
            if (pv[i] < rv[i]) return false;
            // player is greater than required
            if (pv[i] > rv[i]) return true;
        }
        // major version, minor version and revision match exactly
        return true;
    };
    /**
    *
    * @name flash.hasFlash.playerVersion
    * @desc Get the version of the installed Flash plugin.
    * @type String
    *
    **/
    $$.hasFlash.playerVersion = function() {
        // ie
        try {
            try {
                // avoid fp6 minor version lookup issues
                // see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
                var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
                try { axo.AllowScriptAccess = 'always'; }
                catch (e) { return '6,0,0'; }
            } catch (e) { }
            return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
            // other browsers
        } catch (e) {
            try {
                if (navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) {
                    return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
                }
            } catch (e) { }
        }
        return '0,0,0';
    };
    /**
    *
    * @name flash.htmlOptions
    * @desc The default set of options for the object or embed tag.
    *
    **/
    $$.htmlOptions = {
        flashvars: {},
        pluginspage: 'http://www.adobe.com/go/getflashplayer',
        src: '#',
        type: 'application/x-shockwave-flash'
    };
    /**
    *
    * @name flash.pluginOptions
    * @desc The default set of options for checking/updating the flash Plugin.
    *
    **/
    $$.pluginOptions = {
        expressInstall: false,
        update: true,
        version: '6.0.65'
    };
    /**
    *
    * @name flash.replace
    * @desc The default method for replacing an element with a Flash movie.
    *
    **/
    $$.replace = function(htmlOptions) {
        this.innerHTML = '<div class="alt">' + this.innerHTML + '</div>';
        jQuery(this)
		.addClass('flash-replaced')
		.prepend($$.transform(htmlOptions));
    };
    /**
    *
    * @name flash.update
    * @desc The default method for replacing an element with an update message.
    *
    **/
    $$.update = function(htmlOptions) {
        var url = String(location).split('?');
        url.splice(1, 0, '?hasFlash=true&');
        url = url.join('');
        var msg = '<p>This content requires the Flash Player. <a href="http://www.adobe.com/go/getflashplayer">Download Flash Player</a>. Already have Flash Player? <a href="' + url + '">Click here.</a></p>';
        this.innerHTML = '<span class="alt">' + this.innerHTML + '</span>';
        jQuery(this)
		.addClass('flash-update')
		.prepend(msg);
    };
    /**
    *
    * @desc Convert a hash of html options to a string of attributes, using Function.apply(). 
    * @example toAttributeString.apply(htmlOptions)
    * @result foo="bar" foo="bar"
    *
    **/
    function toAttributeString() {
        var s = '';
        for (var key in this)
            if (typeof this[key] != 'function')
            s += key + '="' + this[key] + '" ';
        return s;
    };
    /**
    *
    * @desc Convert a hash of flashvars to a url-encoded string, using Function.apply(). 
    * @example toFlashvarsString.apply(flashvarsObject)
    * @result foo=bar&foo=bar
    *
    **/
    function toFlashvarsString() {
        var s = '';
        for (var key in this)
            if (typeof this[key] != 'function')
            s += key + '=' + encodeURIComponent(this[key]) + '&';
        return s.replace(/&$/, '');
    };
    /**
    *
    * @name flash.transform
    * @desc Transform a set of html options into an embed tag.
    * @type String 
    *
    * @example $$.transform(htmlOptions)
    * @result <embed src="foo.swf" ... />
    *
    * Note: The embed tag is NOT standards-compliant, but it 
    * works in all current browsers. flash.transform can be
    * overwritten with a custom function to generate more 
    * standards-compliant markup.
    *
    **/
    $$.transform = function(htmlOptions) {
        htmlOptions.toString = toAttributeString;
        if (htmlOptions.flashvars) htmlOptions.flashvars.toString = toFlashvarsString;
        return '<embed ' + String(htmlOptions) + '/>';
    };

    /**
    *
    * Flash Player 9 Fix (http://blog.deconcept.com/2006/07/28/swfobject-143-released/)
    *
    **/
    if (window.attachEvent) {
        window.attachEvent("onbeforeunload", function() {
            __flash_unloadHandler = function() { };
            __flash_savedUnloadHandler = function() { };
        });
    }

})();




/* ******************************************************************************************* */
/* jQuery Support */
/* ******************************************************************************************* */


$(document).ready(
    function() {
        var after_type_cast = {};
        var before_type_cast = {};
        var cached = false;

        jQuery.query = function(cast) {
            if (!cached) {
                // remove leading ? and trailing &
                var q = location.search.replace(/^\?/, '').replace(/\&$/, '').split('&');
                for (var i = q.length - 1; i >= 0; i--) {
                    var p = q[i].split('='), key = p[0], val = p[1];
                    before_type_cast[key] = val;
                    // convert floats
                    if (/^[0-9.]+$/.test(val))
                        val = parseFloat(val);
                    // convert booleans
                    if (/^(true|false)$/.test(val))
                        val = (val == 'true');
                    // ingnore empty values
                    if (val)
                        after_type_cast[key] = val;
                }
                cached = true;
            }
            return cast === false ? before_type_cast : after_type_cast;
        };
        if ($("input.clsSearchTextBox").html() != null) {
            if ($.query().q != null)
                $("input.clsSearchTextBox").val($.query().q);
            $("input.clsSearchTextBox").bind("onkeydown", function(e) {
                var key = 0;
                e = (window.event) ? event : e;
                key = (e.keyCode) ? e.keyCode : e.charCode;
                var obj = document.getElementById('ctl00_txtSearchBox');
                if (e.keyCode == 13) {
                    obj.focus();
                    var v = $("#ctl00_txtSearchBox");
                    window.location = "/search-results.aspx?q=" + v.val();
                }
                return false;
            });

            $("input.clsSearchButton").bind("click", function(e) {
                var v = $("input#ctl00_txtSearchBox");
                window.location = "/search-results.aspx?q=" + v.val();
                return false;
            });

        }
        $("a.ExpandDescriptions").bind("click", function(e) {
            $("div.EventSummary").toggle();
            return false;
        });


        // IE Headaches for the Main Nav
        var isProductBoxes = $(".clsProductBox");

        if (isProductBoxes.html() != null) {
            $("div.clsProductBox").bind("mouseenter", function() {
                $(this).addClass("clsProductBoxSelected");
            }).bind("mouseleave", function() {
                $(this).removeClass("clsProductBoxSelected");
            });

            $("div.clsProductBox").bind("click", function(e) {
                window.location = $(this).attr("href");
                return false;
            });
        }

        $(".FAQ a.Question").bind("click", function(e) {
            var par = $(this).parent();
            $(par).find("div.Answer").toggle();
            return false;
        });
        $(".DMSSearch a.DMSAdvancedSearchLink").bind("click", function(e) {
            var par = $(this).parent();
            $(par).find("div.DMSAdvancedSearchOptions").toggle();
            return false;
        });

        $("a.photoGallery").bind("click", function(e) {
            var flashvars = {};
            flashvars.paramXMLPath = "http://www.hexasuite.com/App_Themes/HexaSuite/flash/param-slideshow.xml";

            var pageid = document.getElementById("pageinfo1").innerHTML;
            var xmlpath = "/app_common/19/xml/xmlslideshow.aspx?pageid=" + pageid + "~" + $(this).attr("fieldpairs");
            flashvars.xmlFilePath = xmlpath;

            var params = {};

            params.mediaPlayerScale = "1";
            params.contentAreaBackgroundAlpha = "1";
            params.contentAreaBackgroundColor = "0x000000";
            params.galleryBackgroundColor = "0x000000";
            params.allowfullscreen = "true";

            var attributes = {};
            attributes.id = "photogallery";
            swfobject.embedSWF("/app_common/flash/slideshowpro.swf", "photogallery", "808px", "456px", "9.0.0", false, flashvars, params, attributes);
            tb_show('', '#TB_inline?width=808&height=486&inlineId=galleryContent&modal=true');
            return false;
        });


        $("a.icon_flashVideo").bind("click", function(e) {
            var path = $(this).attr("href");
            var filename = path.substring(path.lastIndexOf('/') + 1);
            var ext = filename.substring(filename.lastIndexOf('.') + 1);
            filename = filename.substring(0, filename.lastIndexOf('.'));
            var pageid = document.getElementById("pageinfo1").innerHTML;
            var xmlpath = "/app_common/19/xml/xmlvideo.aspx?pageid=" + filename + "~" + ext + "~" + pageid;
            var flashvars = {};
            flashvars.paramXMLPath = "http://www.hexasuite.com/App_Themes/HexaSuite/flash/param.xml";
//            window.alert(xmlpath);
            flashvars.xmlFilePath = xmlpath;

            var params = {};

            params.mediaPlayerScale = "1";
            params.contentAreaBackgroundAlpha = "1";
            params.contentAreaBackgroundColor = "0x000000";
            params.galleryBackgroundColor = "0x000000";
            params.allowfullscreen = "true";

            var attributes = {};
            attributes.id = "photogallery";
            swfobject.embedSWF("/app_common/flash/slideshowpro.swf", "photogallery", "808px", "456px", "9.0.0", false, flashvars, params, attributes);
            tb_show('', '#TB_inline?width=808&height=486&inlineId=galleryContent&modal=true');
            return false;
        });

        //        $("a.calculator").bind("click", function(e) {
        //            var href = $(this).attr("href");
        //            var title = $(this).attr("title");
        //            tb_show(title, href);
        //            return false;
        //        });
        //        $("input#SearchResultState1").bind("click", function(e) {
        //            $("span.ResultItem").show();
        //        });
        //        $("input#SearchResultState2").bind("click", function(e) {
        //            $("span.ResultItem").hide();
        //        });
        //        $("a.CloseDialog").bind("click", function(e) {
        //            //var htmlData = '<div id="galleryContent" style="background-color: #000;"><div id="TB_caption">Photo Gallery</div><div id="TB_closeWindow"><a href="#" id="TB_closeWindowButton" title="Close" class="CloseDialog">close</a></div><div id="photogallery"></div></div>';
        //            //$("div#galleryContainer").html(htmlData);
        //        });

    }
);
