﻿/// <reference name="MicrosoftAjax.js"/>
/// <reference path="jQ/jquery-latest-vsdoc.js" />

(function ($) {
    $.extend({
        metadata: {
            defaults: {
                type: 'attr',
                name: 'data',
                cre: /({.*})/,
                single: 'metadata'
            },
            setType: function (type, name) {
                this.defaults.type = type;
                this.defaults.name = name;
            },
            get: function (elem, opts) {
                var df = this.defaults;
                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;
            }
        }
    });
    $.fn.metadata = function (opts) { return $.metadata.get(this[0], opts); };

})(jQuery);

(function ($) {
    $.Net_Sync = function (arg) {
        var _rtn = null; var _op = $.extend(true, $.Net_Sync.prototype, arg);
        if (_op.success === undefined) { _op.success = function (rtn) { _rtn = rtn.d; }; }
        if (_op.error === undefined) { _op.error = function (jqXHR, sgs, err) { _rtn = err; } }
        if (_op.url !== "") { $.ajax(_op); }
        return _rtn;
    };
    $.Net_Sync.prototype = { type: "POST", url: "", async: false, contentType: "application/json; charset=utf-8", dataType: "json" };
})(jQuery);

/// image loader start old
jQuery.fn.onImagesLoaded = function (_cb) {
    return this.each(function () {

        var $imgs = (this.tagName.toLowerCase() === 'img') ? $(this) : $('img', this),
                _cont = this,
                i = 0,
                _done = function () {
                    if (typeof _cb === 'function') _cb(_cont);
                };

        if ($imgs.length) {
            $imgs.each(function () {
                var _img = this,
                    _checki = function (e) {
                        if ((_img.complete) || (_img.readyState == 'complete' && e.type == 'readystatechange')) {
                            if (++i === $imgs.length) _done();
                        }
                        else if (_img.readyState === undefined) // dont for IE
                        {
                            $(_img).attr('src', $(_img).attr('src')); // re-fire load event
                        }
                    }; // _checki \\

                $(_img).bind('load readystatechange', function (e) { _checki(e); });
                _checki({ type: 'readystatechange' }); // bind to 'load' event...
            });
        } else _done();
    });
};
/// image loader end old

/// image loader start new
(function ($) {
    $.fn.onImagesLoad = function (options) {
        var self = this;
        self.opts = $.extend({}, $.fn.onImagesLoad.defaults, options);

        self.bindEvents = function ($imgs, container, callback) {
            if ($imgs.length === 0) { //no images were in selection. callback based on options
                if (self.opts.callbackIfNoImagesExist && callback) { callback(container); }
            }
            else {
                var loadedImages = [];
                if (!$imgs.jquery) { $imgs = $($imgs); }
                $imgs.each(function (i) {
                    //webkit fix inspiration thanks to bmsterling: http://plugins.jquery.com/node/10312
                    var orgSrc = this.src;
                    if (!$.browser.msie) {
                        this.src = ""; //ie will do funky things if this is here (show the image as an X, only show half of the image, etc)
                    }
                    $(this).bind('load', function () {
                        if (jQuery.inArray(i, loadedImages) < 0) { //don't double count images
                            loadedImages.push(i); //keep a record of images we've seen
                            if (loadedImages.length == $imgs.length) {
                                if (callback) { callback.call(container, container); }
                            }
                        }
                    });
                    if (!$.browser.msie) {
                        this.src = orgSrc; //needed for potential cached images
                    }
                    else if (this.complete || this.complete === undefined) { this.src = orgSrc; }
                });
            }
        };

        var imgAry = []; //only used if self.opts.selectorCallback exists
        self.each(function () {
            if (self.opts.itemCallback) {
                var $imgs;
                if (this.tagName == "IMG") { $imgs = this; } //is an image
                else { $imgs = $('img', this); } //contains image(s)
                self.bindEvents($imgs, this, self.opts.itemCallback);
            }
            if (self.opts.selectorCallback) {
                if (this.tagName == "IMG") { imgAry.push(this); } //is an image
                else { //contains image(s)
                    $('img', this).each(function () { imgAry.push(this); });
                }
            }
        });
        if (self.opts.selectorCallback) { self.bindEvents(imgAry, this, self.opts.selectorCallback); }
        return self.each(function () { }); //dont break the chain
    };

    //DEFAULT OPTOINS
    $.fn.onImagesLoad.defaults = {
        selectorCallback: null,        //the function to invoke when all images that $(yourSelector) encapsultaes have loaded (invoked only once per selector. see documentation)
        itemCallback: null,            //the function to invoke when each item that $(yourSelector) encapsultaes has loaded (invoked one or more times depending on selector. see documentation)
        callbackIfNoImagesExist: false //if true, the callbacks will be invoked even if no images exist within $(yourSelector).
        //if false, the callbacks will not be invoked if no images exist within $(yourSelector).
    };
})(jQuery);
/// image loader end new

// photo gallery show start

var fadeSlideShow_descpanel = {
    controls: [['x.png', 7, 7], ['restore.png', 10, 11], ['loading.gif', 54, 55]], //full URL and dimensions of close, restore, and loading images
    fontStyle: 'normal 11px Verdana', //font style for text descriptions
    slidespeed: 200 //speed of description panel animation (in millisec)
};

function fadeSlideShow(settingarg) {
    this.setting = settingarg
    settingarg = null
    var setting = this.setting
    setting.fadeduration = setting.fadeduration ? parseInt(setting.fadeduration) : 500
    setting.curimage = (setting.persist) ? fadeSlideShow.routines.getCookie("gallery-" + setting.wrapperid) : 0
    setting.curimage = setting.curimage || 0 //account for curimage being null if cookie is empty
    setting.currentstep = 0 //keep track of # of slides slideshow has gone through (applicable in displaymode='auto' only)
    setting.totalsteps = setting.imagearray.length * (setting.displaymode.cycles > 0 ? setting.displaymode.cycles : Infinity) //Total steps limit (applicable in displaymode='auto' only w/ cycles>0)
    setting.fglayer = 0, setting.bglayer = 1 //index of active and background layer (switches after each change of slide)
    setting.oninit = setting.oninit || function () { }
    setting.onslide = setting.onslide || function () { }
    if (setting.displaymode.randomize) //randomly shuffle order of images?
        setting.imagearray.sort(function () { return 0.5 - Math.random() })
    var preloadimages = [] //preload images
    setting.longestdesc = "" //get longest description of all slides. If no desciptions defined, variable contains ""
    for (var i = 0; i < setting.imagearray.length; i++) { //preload images
        preloadimages[i] = new Image()
        preloadimages[i].src = setting.imagearray[i][0]
        if (setting.imagearray[i][3] && setting.imagearray[i][3].length > setting.longestdesc.length)
            setting.longestdesc = setting.imagearray[i][3]
    }
    var closebutt = fadeSlideShow_descpanel.controls[0] //add close button to "desc" panel if descreveal="always"
    setting.closebutton = (setting.descreveal == "always") ? '<img class="close" src="' + closebutt[0] + '" style="float:right;cursor:hand;cursor:pointer;width:' + closebutt[1] + 'px;height:' + closebutt[2] + 'px;margin-left:2px" title="Hide Description" />' : ''
    var slideshow = this
    jQuery(document).ready(function ($) { //fire on DOM ready
        var setting = slideshow.setting
        var fullhtml = fadeSlideShow.routines.getFullHTML(setting.imagearray) //get full HTML of entire slideshow
        setting.$wrapperdiv = $('#' + setting.wrapperid).css({ position: 'relative', visibility: 'visible', background: 'black', overflow: 'hidden', width: setting.dimensions[0], height: setting.dimensions[1] }).empty() //main slideshow DIV
        if (setting.$wrapperdiv.length == 0) { //if no wrapper DIV found
            alert("Error: DIV with ID \"" + setting.wrapperid + "\" not found on page.")
            return
        }
        setting.$gallerylayers = $('<div class="gallerylayer"></div><div class="gallerylayer"></div>') //two stacked DIVs to display the actual slide 
			.css({ position: 'absolute', left: 0, top: 0, width: '100%', height: '100%', background: 'black' })
			.appendTo(setting.$wrapperdiv)
        var $loadingimg = $('<img src="' + fadeSlideShow_descpanel.controls[2][0] + '" style="position:absolute;width:' + fadeSlideShow_descpanel.controls[2][1] + ';height:' + fadeSlideShow_descpanel.controls[2][2] + '" />')
			.css({ left: setting.dimensions[0] / 2 - fadeSlideShow_descpanel.controls[2][1] / 2, top: setting.dimensions[1] / 2 - fadeSlideShow_descpanel.controls[2][2] }) //center loading gif
			.appendTo(setting.$wrapperdiv)
        var $curimage = setting.$gallerylayers.html(fullhtml).find('img').hide().eq(setting.curimage) //prefill both layers with entire slideshow content, hide all images, and return current image
        if (setting.longestdesc != "" && setting.descreveal != "none") { //if at least one slide contains a description (versus feature is enabled but no descriptions defined) and descreveal not explicitly disabled
            fadeSlideShow.routines.adddescpanel($, setting)
            if (setting.descreveal == "always") { //position desc panel so it's visible to begin with
                setting.$descpanel.css({ top: setting.dimensions[1] - setting.panelheight })
                setting.$descinner.click(function (e) { //asign click behavior to "close" icon
                    if (e.target.className == "close") {
                        slideshow.showhidedescpanel('hide')
                    }
                })
                setting.$restorebutton.click(function (e) { //asign click behavior to "restore" icon
                    slideshow.showhidedescpanel('show')
                    $(this).css({ visibility: 'hidden' })
                })
            }
            else if (setting.descreveal == "ondemand") { //display desc panel on demand (mouseover)
                setting.$wrapperdiv.bind('mouseenter', function () { slideshow.showhidedescpanel('show') })
                setting.$wrapperdiv.bind('mouseleave', function () { slideshow.showhidedescpanel('hide') })
            }
        }
        setting.$wrapperdiv.bind('mouseenter', function () { setting.ismouseover = true }) //pause slideshow mouseover
        setting.$wrapperdiv.bind('mouseleave', function () { setting.ismouseover = false })
        if ($curimage.get(0).complete) { //accounf for IE not firing image.onload
            $loadingimg.hide()
            slideshow.paginateinit($)
            slideshow.showslide(setting.curimage)
        }
        else { //initialize slideshow when first image has fully loaded
            $loadingimg.hide()
            slideshow.paginateinit($)
            $curimage.bind('load', function () { slideshow.showslide(setting.curimage) })
        }
        setting.oninit.call(slideshow) //trigger oninit() event
        $(window).bind('unload', function () { //clean up and persist
            if (slideshow.setting.persist) //remember last shown image's index
                fadeSlideShow.routines.setCookie("gallery-" + setting.wrapperid, setting.curimage)
            jQuery.each(slideshow.setting, function (k) {
                if (slideshow.setting[k] instanceof Array) {
                    for (var i = 0; i < slideshow.setting[k].length; i++) {
                        if (slideshow.setting[k][i].tagName == "DIV") //catches 2 gallerylayer divs, gallerystatus div
                            slideshow.setting[k][i].innerHTML = null
                        slideshow.setting[k][i] = null
                    }
                }
            })
            slideshow = slideshow.setting = null
        })
    })
};

fadeSlideShow.prototype = {
    navigate: function (keyword) {
        var setting = this.setting
        clearTimeout(setting.playtimer)
        if (setting.displaymode.type == "auto") { //in auto mode
            setting.displaymode.type = "manual" //switch to "manual" mode when nav buttons are clicked on
            setting.displaymode.wraparound = true //set wraparound option to true
        }
        if (!isNaN(parseInt(keyword))) { //go to specific slide?
            this.showslide(parseInt(keyword))
        }
        else if (/(prev)|(next)/i.test(keyword)) { //go back or forth inside slide?
            this.showslide(keyword.toLowerCase())
        }
    },
    showslide: function (keyword) {
        var slideshow = this
        var setting = slideshow.setting
        if (setting.displaymode.type == "auto" && setting.ismouseover && setting.currentstep <= setting.totalsteps) { //if slideshow in autoplay mode and mouse is over it, pause it
            setting.playtimer = setTimeout(function () { slideshow.showslide('next') }, setting.displaymode.pause)
            return
        }
        var totalimages = setting.imagearray.length
        var imgindex = (keyword == "next") ? (setting.curimage < totalimages - 1 ? setting.curimage + 1 : 0)
			: (keyword == "prev") ? (setting.curimage > 0 ? setting.curimage - 1 : totalimages - 1)
			: Math.min(keyword, totalimages - 1)
        var $slideimage = setting.$gallerylayers.eq(setting.bglayer).find('img').hide().eq(imgindex).show() //hide all images except current one
        var imgdimensions = [$slideimage.width(), $slideimage.height()] //center align image
        $slideimage.css({ marginLeft: (imgdimensions[0] > 0 && imgdimensions[0] < setting.dimensions[0]) ? setting.dimensions[0] / 2 - imgdimensions[0] / 2 : 0 })
        $slideimage.css({ marginTop: (imgdimensions[1] > 0 && imgdimensions[1] < setting.dimensions[1]) ? setting.dimensions[1] / 2 - imgdimensions[1] / 2 : 0 })
        if (setting.descreveal == "peekaboo" && setting.longestdesc != "") { //if descreveal is set to "peekaboo", make sure description panel is hidden before next slide is shown
            clearTimeout(setting.hidedesctimer) //clear hide desc panel timer
            slideshow.showhidedescpanel('hide', 0) //and hide it immediately
        }
        setting.$gallerylayers.eq(setting.bglayer).css({ zIndex: 1000, opacity: 0 }) //background layer becomes foreground
			.stop().css({ opacity: 0 }).animate({ opacity: 1 }, setting.fadeduration, function () { //Callback function after fade animation is complete:
			    clearTimeout(setting.playtimer)
			    try {
			        setting.onslide.call(slideshow, setting.$gallerylayers.eq(setting.fglayer).get(0), setting.curimage)
			    } catch (e) {
			        alert("Fade In Slideshow error: An error has occured somwhere in your code attached to the \"onslide\" event: " + e)
			    }
			    if (setting.descreveal == "peekaboo" && setting.longestdesc != "") {
			        slideshow.showhidedescpanel('show')
			        setting.hidedesctimer = setTimeout(function () { slideshow.showhidedescpanel('hide') }, setting.displaymode.pause - fadeSlideShow_descpanel.slidespeed)
			    }
			    setting.currentstep += 1
			    if (setting.displaymode.type == "auto") {
			        if (setting.currentstep <= setting.totalsteps || setting.displaymode.cycles == 0)
			            setting.playtimer = setTimeout(function () { slideshow.showslide('next') }, setting.displaymode.pause)
			    }
			}) //end callback function
        setting.$gallerylayers.eq(setting.fglayer).css({ zIndex: 999 }) //foreground layer becomes background
        setting.fglayer = setting.bglayer
        setting.bglayer = (setting.bglayer == 0) ? 1 : 0
        setting.curimage = imgindex
        if (setting.$descpanel) {
            setting.$descpanel.css({ visibility: (setting.imagearray[imgindex][3]) ? 'visible' : 'hidden' })
            if (setting.imagearray[imgindex][3]) //if this slide contains a description
                setting.$descinner.empty().html(setting.closebutton + setting.imagearray[imgindex][3])
        }
        if (setting.displaymode.type == "manual" && !setting.displaymode.wraparound) {
            this.paginatecontrol()
        }
        if (setting.$status) //if status container defined
            setting.$status.html(setting.curimage + 1 + "/" + totalimages)
    },

    showhidedescpanel: function (state, animateduration) {
        var setting = this.setting
        var endpoint = (state == "show") ? setting.dimensions[1] - setting.panelheight : this.setting.dimensions[1]
        setting.$descpanel.stop().animate({ top: endpoint }, (typeof animateduration != "undefined" ? animateduration : fadeSlideShow_descpanel.slidespeed), function () {
            if (setting.descreveal == "always" && state == "hide")
                setting.$restorebutton.css({ visibility: 'visible' }) //show restore button
        })
    },

    paginateinit: function ($) {
        var slideshow = this
        var setting = this.setting
        if (setting.togglerid) { //if toggler div defined
            setting.$togglerdiv = $("#" + setting.togglerid)
            setting.$prev = setting.$togglerdiv.find('.prev').data('action', 'prev')
            setting.$next = setting.$togglerdiv.find('.next').data('action', 'next')
            setting.$prev.add(setting.$next).click(function (e) { //assign click behavior to prev and next controls
                var $target = $(this)
                slideshow.navigate($target.data('action'))
                e.preventDefault()
            })
            setting.$status = setting.$togglerdiv.find('.status')
        }
    },

    paginatecontrol: function () {
        var setting = this.setting
        setting.$prev.css({ opacity: (setting.curimage == 0) ? 0.4 : 1 }).data('action', (setting.curimage == 0) ? 'none' : 'prev')
        setting.$next.css({ opacity: (setting.curimage == setting.imagearray.length - 1) ? 0.4 : 1 }).data('action', (setting.curimage == setting.imagearray.length - 1) ? 'none' : 'next')
        if (document.documentMode == 8) { //in IE8 standards mode, apply opacity to inner image of link
            setting.$prev.find('img:eq(0)').css({ opacity: (setting.curimage == 0) ? 0.4 : 1 })
            setting.$next.find('img:eq(0)').css({ opacity: (setting.curimage == setting.imagearray.length - 1) ? 0.4 : 1 })
        }
    }


};

fadeSlideShow.routines = {
    getSlideHTML: function (imgelement) {
        var layerHTML = (imgelement[1]) ? '<a href="' + imgelement[1] + '" target="' + imgelement[2] + '">\n' : '' //hyperlink slide?
        layerHTML += '<img src="' + imgelement[0] + '" style="border-width:0;" />\n'
        layerHTML += (imgelement[1]) ? '</a>\n' : ''
        return layerHTML //return HTML for this layer
    },

    getFullHTML: function (imagearray) {
        var preloadhtml = ''
        for (var i = 0; i < imagearray.length; i++)
            preloadhtml += this.getSlideHTML(imagearray[i])
        return preloadhtml
    },

    adddescpanel: function ($, setting) {
        setting.$descpanel = $('<div class="fadeslidedescdiv"></div>')
			.css({ position: 'absolute', visibility: 'hidden', width: '100%', left: 0, top: setting.dimensions[1], font: fadeSlideShow_descpanel.fontStyle, zIndex: '1001' })
			.appendTo(setting.$wrapperdiv)
        $('<div class="descpanelbg"></div><div class="descpanelfg"></div>') //create inner nav panel DIVs
			.css({ position: 'absolute', left: 0, top: 0, width: setting.$descpanel.width() - 8, padding: '4px' })
			.eq(0).css({ background: 'black', opacity: 0.7 }).end() //"descpanelbg" div
			.eq(1).css({ color: 'white' }).html(setting.closebutton + setting.longestdesc).end() //"descpanelfg" div
			.appendTo(setting.$descpanel)
        setting.$descinner = setting.$descpanel.find('div.descpanelfg')
        setting.panelheight = setting.$descinner.outerHeight()
        setting.$descpanel.css({ height: setting.panelheight }).find('div').css({ height: '100%' })
        if (setting.descreveal == "always") { //create restore button
            setting.$restorebutton = $('<img class="restore" title="Restore Description" src="' + fadeSlideShow_descpanel.controls[1][0] + '" style="position:absolute;visibility:hidden;right:0;bottom:0;z-index:1002;width:' + fadeSlideShow_descpanel.controls[1][1] + 'px;height:' + fadeSlideShow_descpanel.controls[1][2] + 'px;cursor:pointer;cursor:hand" />')
				.appendTo(setting.$wrapperdiv)


        }
    },
    getCookie: function (Name) {
        var re = new RegExp(Name + "=[^;]+", "i"); //construct RE to search for target name/value pair
        if (document.cookie.match(re)) //if cookie found
            return document.cookie.match(re)[0].split("=")[1] //return its value
        return null
    },
    setCookie: function (name, value) {
        document.cookie = name + "=" + value + ";path=/"
    }
};
// photo gallery show end

// color picker 1.0.3 start
(function ($) {
    var ColorPicker = function () {
        var 
			ids = {},
			inAction,
			charMin = 65,
			visible,
			tpl = '<div class="colorpicker"><div class="colorpicker_color"><div><div></div></div></div><div class="colorpicker_hue"><div></div></div><div class="colorpicker_new_color"></div><div class="colorpicker_current_color"></div><div class="colorpicker_hex"><input type="text" maxlength="6" size="6" /></div><div class="colorpicker_rgb_r colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_rgb_g colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_rgb_b colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_h colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_s colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_b colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_submit"></div></div>',
			defaults = {
			    eventName: 'click',
			    onShow: function () { },
			    onBeforeShow: function () { },
			    onHide: function () { },
			    onChange: function () { },
			    onSubmit: function () { },
			    color: 'ff0000',
			    livePreview: true,
			    flat: false
			},
			fillRGBFields = function (hsb, cal) {
			    var rgb = HSBToRGB(hsb);
			    $(cal).data('colorpicker').fields
					.eq(1).val(rgb.r).end()
					.eq(2).val(rgb.g).end()
					.eq(3).val(rgb.b).end();
			},
			fillHSBFields = function (hsb, cal) {
			    $(cal).data('colorpicker').fields
					.eq(4).val(hsb.h).end()
					.eq(5).val(hsb.s).end()
					.eq(6).val(hsb.b).end();
			},
			fillHexFields = function (hsb, cal) {
			    $(cal).data('colorpicker').fields
					.eq(0).val(HSBToHex(hsb)).end();
			},
			setSelector = function (hsb, cal) {
			    $(cal).data('colorpicker').selector.css('backgroundColor', '#' + HSBToHex({ h: hsb.h, s: 100, b: 100 }));
			    $(cal).data('colorpicker').selectorIndic.css({
			        left: parseInt(150 * hsb.s / 100, 10),
			        top: parseInt(150 * (100 - hsb.b) / 100, 10)
			    });
			},
			setHue = function (hsb, cal) {
			    $(cal).data('colorpicker').hue.css('top', parseInt(150 - 150 * hsb.h / 360, 10));
			},
			setCurrentColor = function (hsb, cal) {
			    $(cal).data('colorpicker').currentColor.css('backgroundColor', '#' + HSBToHex(hsb));
			},
			setNewColor = function (hsb, cal) {
			    $(cal).data('colorpicker').newColor.css('backgroundColor', '#' + HSBToHex(hsb));
			},
			keyDown = function (ev) {
			    var pressedKey = ev.charCode || ev.keyCode || -1;
			    if ((pressedKey > charMin && pressedKey <= 90) || pressedKey == 32) {
			        return false;
			    }
			    var cal = $(this).parent().parent();
			    if (cal.data('colorpicker').livePreview === true) {
			        change.apply(this);
			    }
			},
			change = function (ev) {
			    var cal = $(this).parent().parent(), col;
			    if (this.parentNode.className.indexOf('_hex') > 0) {
			        cal.data('colorpicker').color = col = HexToHSB(fixHex(this.value));
			    } else if (this.parentNode.className.indexOf('_hsb') > 0) {
			        cal.data('colorpicker').color = col = fixHSB({
			            h: parseInt(cal.data('colorpicker').fields.eq(4).val(), 10),
			            s: parseInt(cal.data('colorpicker').fields.eq(5).val(), 10),
			            b: parseInt(cal.data('colorpicker').fields.eq(6).val(), 10)
			        });
			    } else {
			        cal.data('colorpicker').color = col = RGBToHSB(fixRGB({
			            r: parseInt(cal.data('colorpicker').fields.eq(1).val(), 10),
			            g: parseInt(cal.data('colorpicker').fields.eq(2).val(), 10),
			            b: parseInt(cal.data('colorpicker').fields.eq(3).val(), 10)
			        }));
			    }
			    if (ev) {
			        fillRGBFields(col, cal.get(0));
			        fillHexFields(col, cal.get(0));
			        fillHSBFields(col, cal.get(0));
			    }
			    setSelector(col, cal.get(0));
			    setHue(col, cal.get(0));
			    setNewColor(col, cal.get(0));
			    cal.data('colorpicker').onChange.apply(cal, [col, HSBToHex(col), HSBToRGB(col)]);
			},
			blur = function (ev) {
			    var cal = $(this).parent().parent();
			    cal.data('colorpicker').fields.parent().removeClass('colorpicker_focus');
			},
			focus = function () {
			    charMin = this.parentNode.className.indexOf('_hex') > 0 ? 70 : 65;
			    $(this).parent().parent().data('colorpicker').fields.parent().removeClass('colorpicker_focus');
			    $(this).parent().addClass('colorpicker_focus');
			},
			downIncrement = function (ev) {
			    var field = $(this).parent().find('input').focus();
			    var current = {
			        el: $(this).parent().addClass('colorpicker_slider'),
			        max: this.parentNode.className.indexOf('_hsb_h') > 0 ? 360 : (this.parentNode.className.indexOf('_hsb') > 0 ? 100 : 255),
			        y: ev.pageY,
			        field: field,
			        val: parseInt(field.val(), 10),
			        preview: $(this).parent().parent().data('colorpicker').livePreview
			    };
			    $(document).bind('mouseup', current, upIncrement);
			    $(document).bind('mousemove', current, moveIncrement);
			},
			moveIncrement = function (ev) {
			    ev.data.field.val(Math.max(0, Math.min(ev.data.max, parseInt(ev.data.val + ev.pageY - ev.data.y, 10))));
			    if (ev.data.preview) {
			        change.apply(ev.data.field.get(0), [true]);
			    }
			    return false;
			},
			upIncrement = function (ev) {
			    change.apply(ev.data.field.get(0), [true]);
			    ev.data.el.removeClass('colorpicker_slider').find('input').focus();
			    $(document).unbind('mouseup', upIncrement);
			    $(document).unbind('mousemove', moveIncrement);
			    return false;
			},
			downHue = function (ev) {
			    var current = {
			        cal: $(this).parent(),
			        y: $(this).offset().top
			    };
			    current.preview = current.cal.data('colorpicker').livePreview;
			    $(document).bind('mouseup', current, upHue);
			    $(document).bind('mousemove', current, moveHue);
			},
			moveHue = function (ev) {
			    change.apply(
					ev.data.cal.data('colorpicker')
						.fields
						.eq(4)
						.val(parseInt(360 * (150 - Math.max(0, Math.min(150, (ev.pageY - ev.data.y)))) / 150, 10))
						.get(0),
					[ev.data.preview]
				);
			    return false;
			},
			upHue = function (ev) {
			    fillRGBFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
			    fillHexFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
			    $(document).unbind('mouseup', upHue);
			    $(document).unbind('mousemove', moveHue);
			    return false;
			},
			downSelector = function (ev) {
			    var current = {
			        cal: $(this).parent(),
			        pos: $(this).offset()
			    };
			    current.preview = current.cal.data('colorpicker').livePreview;
			    $(document).bind('mouseup', current, upSelector);
			    $(document).bind('mousemove', current, moveSelector);
			},
			moveSelector = function (ev) {
			    change.apply(
					ev.data.cal.data('colorpicker')
						.fields
						.eq(6)
						.val(parseInt(100 * (150 - Math.max(0, Math.min(150, (ev.pageY - ev.data.pos.top)))) / 150, 10))
						.end()
						.eq(5)
						.val(parseInt(100 * (Math.max(0, Math.min(150, (ev.pageX - ev.data.pos.left)))) / 150, 10))
						.get(0),
					[ev.data.preview]
				);
			    return false;
			},
			upSelector = function (ev) {
			    fillRGBFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
			    fillHexFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
			    $(document).unbind('mouseup', upSelector);
			    $(document).unbind('mousemove', moveSelector);
			    return false;
			},
			enterSubmit = function (ev) {
			    $(this).addClass('colorpicker_focus');
			},
			leaveSubmit = function (ev) {
			    $(this).removeClass('colorpicker_focus');
			},
			clickSubmit = function (ev) {
			    var cal = $(this).parent();
			    var col = cal.data('colorpicker').color;
			    cal.data('colorpicker').origColor = col;
			    setCurrentColor(col, cal.get(0));
			    cal.data('colorpicker').onSubmit(col, HSBToHex(col), HSBToRGB(col), cal.data('colorpicker').el);
			},
			show = function (ev) {
			    var cal = $('#' + $(this).data('colorpickerId'));
			    cal.data('colorpicker').onBeforeShow.apply(this, [cal.get(0)]);
			    var pos = $(this).offset();
			    var viewPort = getViewport();
			    var top = pos.top + this.offsetHeight;
			    var left = pos.left;
			    if (top + 176 > viewPort.t + viewPort.h) {
			        top -= this.offsetHeight + 176;
			    }
			    if (left + 356 > viewPort.l + viewPort.w) {
			        left -= 356;
			    }
			    cal.css({ left: left + 'px', top: top + 'px' });
			    if (cal.data('colorpicker').onShow.apply(this, [cal.get(0)]) != false) {
			        cal.show();
			    }
			    $(document).bind('mousedown', { cal: cal }, hide);
			    return false;
			},
			hide = function (ev) {
			    if (!isChildOf(ev.data.cal.get(0), ev.target, ev.data.cal.get(0))) {
			        if (ev.data.cal.data('colorpicker').onHide.apply(this, [ev.data.cal.get(0)]) != false) {
			            ev.data.cal.hide();
			        }
			        $(document).unbind('mousedown', hide);
			    }
			},
			isChildOf = function (parentEl, el, container) {
			    if (parentEl == el) {
			        return true;
			    }
			    if (parentEl.contains) {
			        return parentEl.contains(el);
			    }
			    if (parentEl.compareDocumentPosition) {
			        return !!(parentEl.compareDocumentPosition(el) & 16);
			    }
			    var prEl = el.parentNode;
			    while (prEl && prEl != container) {
			        if (prEl == parentEl)
			            return true;
			        prEl = prEl.parentNode;
			    }
			    return false;
			},
			getViewport = function () {
			    var m = document.compatMode == 'CSS1Compat';
			    return {
			        l: window.pageXOffset || (m ? document.documentElement.scrollLeft : document.body.scrollLeft),
			        t: window.pageYOffset || (m ? document.documentElement.scrollTop : document.body.scrollTop),
			        w: window.innerWidth || (m ? document.documentElement.clientWidth : document.body.clientWidth),
			        h: window.innerHeight || (m ? document.documentElement.clientHeight : document.body.clientHeight)
			    };
			},
			fixHSB = function (hsb) {
			    return {
			        h: Math.min(360, Math.max(0, hsb.h)),
			        s: Math.min(100, Math.max(0, hsb.s)),
			        b: Math.min(100, Math.max(0, hsb.b))
			    };
			},
			fixRGB = function (rgb) {
			    return {
			        r: Math.min(255, Math.max(0, rgb.r)),
			        g: Math.min(255, Math.max(0, rgb.g)),
			        b: Math.min(255, Math.max(0, rgb.b))
			    };
			},
			fixHex = function (hex) {
			    var len = 6 - hex.length;
			    if (len > 0) {
			        var o = [];
			        for (var i = 0; i < len; i++) {
			            o.push('0');
			        }
			        o.push(hex);
			        hex = o.join('');
			    }
			    return hex;
			},
			HexToRGB = function (hex) {
			    var hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16);
			    return { r: hex >> 16, g: (hex & 0x00FF00) >> 8, b: (hex & 0x0000FF) };
			},
			HexToHSB = function (hex) {
			    return RGBToHSB(HexToRGB(hex));
			},
			RGBToHSB = function (rgb) {
			    var hsb = {
			        h: 0,
			        s: 0,
			        b: 0
			    };
			    var min = Math.min(rgb.r, rgb.g, rgb.b);
			    var max = Math.max(rgb.r, rgb.g, rgb.b);
			    var delta = max - min;
			    hsb.b = max;
			    if (max != 0) {

			    }
			    hsb.s = max != 0 ? 255 * delta / max : 0;
			    if (hsb.s != 0) {
			        if (rgb.r == max) {
			            hsb.h = (rgb.g - rgb.b) / delta;
			        } else if (rgb.g == max) {
			            hsb.h = 2 + (rgb.b - rgb.r) / delta;
			        } else {
			            hsb.h = 4 + (rgb.r - rgb.g) / delta;
			        }
			    } else {
			        hsb.h = -1;
			    }
			    hsb.h *= 60;
			    if (hsb.h < 0) {
			        hsb.h += 360;
			    }
			    hsb.s *= 100 / 255;
			    hsb.b *= 100 / 255;
			    return hsb;
			},
			HSBToRGB = function (hsb) {
			    var rgb = {};
			    var h = Math.round(hsb.h);
			    var s = Math.round(hsb.s * 255 / 100);
			    var v = Math.round(hsb.b * 255 / 100);
			    if (s == 0) {
			        rgb.r = rgb.g = rgb.b = v;
			    } else {
			        var t1 = v;
			        var t2 = (255 - s) * v / 255;
			        var t3 = (t1 - t2) * (h % 60) / 60;
			        if (h == 360) h = 0;
			        if (h < 60) { rgb.r = t1; rgb.b = t2; rgb.g = t2 + t3 }
			        else if (h < 120) { rgb.g = t1; rgb.b = t2; rgb.r = t1 - t3 }
			        else if (h < 180) { rgb.g = t1; rgb.r = t2; rgb.b = t2 + t3 }
			        else if (h < 240) { rgb.b = t1; rgb.r = t2; rgb.g = t1 - t3 }
			        else if (h < 300) { rgb.b = t1; rgb.g = t2; rgb.r = t2 + t3 }
			        else if (h < 360) { rgb.r = t1; rgb.g = t2; rgb.b = t1 - t3 }
			        else { rgb.r = 0; rgb.g = 0; rgb.b = 0 }
			    }
			    return { r: Math.round(rgb.r), g: Math.round(rgb.g), b: Math.round(rgb.b) };
			},
			RGBToHex = function (rgb) {
			    var hex = [
					rgb.r.toString(16),
					rgb.g.toString(16),
					rgb.b.toString(16)
				];
			    $.each(hex, function (nr, val) {
			        if (val.length == 1) {
			            hex[nr] = '0' + val;
			        }
			    });
			    return hex.join('');
			},
			HSBToHex = function (hsb) {
			    return RGBToHex(HSBToRGB(hsb));
			},
			restoreOriginal = function () {
			    var cal = $(this).parent();
			    var col = cal.data('colorpicker').origColor;
			    cal.data('colorpicker').color = col;
			    fillRGBFields(col, cal.get(0));
			    fillHexFields(col, cal.get(0));
			    fillHSBFields(col, cal.get(0));
			    setSelector(col, cal.get(0));
			    setHue(col, cal.get(0));
			    setNewColor(col, cal.get(0));
			};
        return {
            init: function (opt) {
                opt = $.extend({}, defaults, opt || {});
                if (typeof opt.color == 'string') {
                    opt.color = HexToHSB(opt.color);
                } else if (opt.color.r != undefined && opt.color.g != undefined && opt.color.b != undefined) {
                    opt.color = RGBToHSB(opt.color);
                } else if (opt.color.h != undefined && opt.color.s != undefined && opt.color.b != undefined) {
                    opt.color = fixHSB(opt.color);
                } else {
                    return this;
                }
                return this.each(function () {
                    if (!$(this).data('colorpickerId')) {
                        var options = $.extend({}, opt);
                        options.origColor = opt.color;
                        var id = 'collorpicker_' + parseInt(Math.random() * 1000);
                        $(this).data('colorpickerId', id);
                        var cal = $(tpl).attr('id', id);
                        if (options.flat) {
                            cal.appendTo(this).show();
                        } else {
                            cal.appendTo(document.body);
                        }
                        options.fields = cal
											.find('input')
												.bind('keyup', keyDown)
												.bind('change', change)
												.bind('blur', blur)
												.bind('focus', focus);
                        cal
							.find('span').bind('mousedown', downIncrement).end()
							.find('>div.colorpicker_current_color').bind('click', restoreOriginal);
                        options.selector = cal.find('div.colorpicker_color').bind('mousedown', downSelector);
                        options.selectorIndic = options.selector.find('div div');
                        options.el = this;
                        options.hue = cal.find('div.colorpicker_hue div');
                        cal.find('div.colorpicker_hue').bind('mousedown', downHue);
                        options.newColor = cal.find('div.colorpicker_new_color');
                        options.currentColor = cal.find('div.colorpicker_current_color');
                        cal.data('colorpicker', options);
                        cal.find('div.colorpicker_submit')
							.bind('mouseenter', enterSubmit)
							.bind('mouseleave', leaveSubmit)
							.bind('click', clickSubmit);
                        fillRGBFields(options.color, cal.get(0));
                        fillHSBFields(options.color, cal.get(0));
                        fillHexFields(options.color, cal.get(0));
                        setHue(options.color, cal.get(0));
                        setSelector(options.color, cal.get(0));
                        setCurrentColor(options.color, cal.get(0));
                        setNewColor(options.color, cal.get(0));
                        if (options.flat) {
                            cal.css({
                                position: 'relative',
                                display: 'block'
                            });
                        } else {
                            $(this).bind(options.eventName, show);
                        }
                    }
                });
            },
            showPicker: function () {
                return this.each(function () {
                    if ($(this).data('colorpickerId')) {
                        show.apply(this);
                    }
                });
            },
            hidePicker: function () {
                return this.each(function () {
                    if ($(this).data('colorpickerId')) {
                        $('#' + $(this).data('colorpickerId')).hide();
                    }
                });
            },
            setColor: function (col) {
                if (typeof col == 'string') {
                    col = HexToHSB(col);
                } else if (col.r != undefined && col.g != undefined && col.b != undefined) {
                    col = RGBToHSB(col);
                } else if (col.h != undefined && col.s != undefined && col.b != undefined) {
                    col = fixHSB(col);
                } else {
                    return this;
                }
                return this.each(function () {
                    if ($(this).data('colorpickerId')) {
                        var cal = $('#' + $(this).data('colorpickerId'));
                        cal.data('colorpicker').color = col;
                        cal.data('colorpicker').origColor = col;
                        fillRGBFields(col, cal.get(0));
                        fillHSBFields(col, cal.get(0));
                        fillHexFields(col, cal.get(0));
                        setHue(col, cal.get(0));
                        setSelector(col, cal.get(0));
                        setCurrentColor(col, cal.get(0));
                        setNewColor(col, cal.get(0));
                    }
                });
            }
        };
    } ();
    $.fn.extend({
        ColorPicker: ColorPicker.init,
        ColorPickerHide: ColorPicker.hidePicker,
        ColorPickerShow: ColorPicker.showPicker,
        ColorPickerSetColor: ColorPicker.setColor
    });
})(jQuery)


// color picker 1.0.3 end

// this overwrites the html in the target
function Ajax_Process(path, params, id, tp, cache) {
    var _cache = true;
    if (cache !== undefined) {
        _cache = cache;
    }
    $.ajax({
        type: tp,
        url: path,
        data: params,
        cache: _cache,
        success: function (msg) {
            $(id).html(msg);
        }
    });
}

// this appends the returned html to the html already in the target
function Ajax_AppendToTarget(path, params, id, tp, cache) {
    var _cache = true;
    if (cache !== undefined) {
        _cache = cache;
    }
    $.ajax({
        type: tp,
        url: path,
        data: params,
        cache: _cache,
        success: function (msg) {
            $(id).html($(id).html() + msg);
        }
    });
}

// this gets a javascript file and executes the function passed in... pass null to not fire a function
function Ajax_GetJSFile(path, fnc, arg, opt) {
    if (fnc === undefined || fnc === null) { fnc = '{}'; }
    var _op = { url: path, dataType: 'script', success: function () { if (typeof fnc === 'function') { if (arg === undefined) { fnc(); } else { fnc(arg); } } else { eval(fnc); } } };
    if(opt !== undefined) { _op = $.extend(true, _op, opt);  }
    $.ajax(_op);
}

// this executes the javascript returned
function Ajax_ExecuteScript(path, params) {
    $.ajax({
        type: "POST",
        dataType: "script",
        url: path,
        data: params
    });
}
//* Ajax Related Operations end //


/* Process Like | Dislike */
function Process_Advice(path, params, id, actionid, actiontype) {
    toggle_panel(1, '#shw_lgn');
    // start posting ajax
    Ajax_Process(path, params, id, "GET");
    // disable like or dislike button
    if (actiontype == 0) {
        $(actionid).removeClass("ui-adv-icon-good");
        $(actionid).removeClass("ui-adv-icon-gd_hover");
        $(actionid).addClass("ui-fixed ui-adv-icon-good");

    } else {
        $(actionid).removeClass("ui-adv-icon-bad");
        $(actionid).removeClass("ui-adv-icon-bd_hover");
        $(actionid).addClass("ui-fixed ui-adv-icon-bad");
    }
    // disable action
}

/* Process Abuse Report */
function Process_Req(path, params, id, type) {
    toggle_panel(1, '#shw_lgn');
    // start posting ajax
    Ajax_Process(path, params, id, type);
}
/* Process Abuse Report */
function Process_Req(path, params, id, type, loadingid) {
    ShowHide(1, '#' + loadingid);
    // start posting ajax
    Ajax_Process(path, params, id, type);
    ShowHide(2, '#' + loadingid);
}
/* Submit Abuse Report */
function Post_Abuse(path, params, id, elementid, msgid) {
    var value = $(elementid).val();
    if (value == '') {
        Display_Message(msgid, "Please select reason", 1, 200);
        return;
    }
    Display_Processing(msgid);
    Ajax_Process(path, params + "&val=" + value, id, "POST");
    toggle_panel(1, '#shw_lgn');
}
/* Submit Playlist */
function Post_Playlist(path, params, id, elementid, msgid) {
    var value = $(elementid).val();
    if (value == '') {
        Display_Message(msgid, "Please select playlist", 1, 200);
        return;
    }
    Display_Processing(msgid);
    Ajax_Process(path, params + "&val=" + value, id, "POST");
    toggle_panel(1, '#shw_lgn');
}
/* Validate and Post data */
function Post_Data(path, params, id, elementid, msgid, valmsg) {
    var value = $('#' + elementid).val();
    if (value == '') {
        Display_Message('#' + msgid, valmsg, 1, 200);
        return;
    }
    Display_Processing(msgid);
    Ajax_Process(path, params + "&val=" + value, id, "POST");
    $('#' + elementid).val('');
}
/* Display processing message */
function Display_Processing(id) {
    $(id).html("<div style='padding:4px 0px;'>Processing....</div>");
}
/* Display Message */
function Display_Message(id, msg, tp, width) {
    if (tp == 0)
        $(id).html("<div class='ui-state-highlight ui-corner-all' style='width:" + width + "px;margin:4px auto 4px auto;'>" + msg + "</div>");
    else
        $(id).html("<div class='ui-state-error ui-corner-all' style='width:" + width + "px;margin:4px auto 4px auto;'>" + msg + "</div>");
}

/* view loading */
/* view loading */
function Expand_View(path, params, msg) {
    // collapse info view if open
    Collapse_Info();
    $('#bx_expander').addClass('box-expander-body');
    $('#bx_exp_arrow2').removeClass('ui-icon-triangle-1-s');
    $('#bx_exp_arrow2').addClass('ui-icon-triangle-1-n');
    $('#bx_exp_hd2').removeClass('box-expander-head');
    $('#bx_exp_hd2').addClass('box-expander-head-active');
    $('#bx_exp_bd2').show('slow');
    $('#bx_hd_exp2').hide('slow');
    $('#bx_exp_hd2').unbind("click");
    $('#bx_exp_hd2').bind('click', function () {
        Collapse_View(path, params, msg);
    });
    // ajax processing
    Ajax_Process(path, params, msg, "POST");
}

function Collapse_View(path, params, msg) {
    $('#bx_expander').removeClass('box-expander-body');
    $('#bx_exp_arrow2').addClass('ui-icon-triangle-1-s');
    $('#bx_exp_arrow2').removeClass('ui-icon-triangle-1-n');
    $('#bx_exp_hd2').addClass('box-expander-head');
    $('#bx_exp_hd2').removeClass('box-expander-head-active');
    $('#bx_exp_bd2').hide('slow');
    $('#bx_hd_exp2').show('slow');
    $('#bx_exp_hd2').unbind("click");
    $('#bx_exp_hd2').bind('click', function () {
        Expand_View(path, params, msg);
    });
}
/* Box behaviour design */
function Expand_Info(path, params, msg) {
    // collapse view if open
    Collapse_View(path, params, msg);
    $('#bx_expander').addClass('box-expander-body');
    $('#bx_exp_arrow').removeClass('ui-icon-triangle-1-s');
    $('#bx_exp_arrow').addClass('ui-icon-triangle-1-n');
    $('#bx_exp_hd').removeClass('box-expander-head');
    $('#bx_exp_hd').addClass('box-expander-head-active');
    $('#bx_exp_bd').show('slow');
    $('#bx_hd_exp').hide('slow');
    $('#bx_exp_hd').unbind("click");
    $('#bx_exp_hd').bind('click', function () {
        Collapse_Info();
    });
}

function Collapse_Info() {
    $('#bx_expander').removeClass('box-expander-body');
    $('#bx_exp_arrow').addClass('ui-icon-triangle-1-s');
    $('#bx_exp_arrow').removeClass('ui-icon-triangle-1-n');
    $('#bx_exp_hd').addClass('box-expander-head');
    $('#bx_exp_hd').removeClass('box-expander-head-active');
    $('#bx_exp_bd').hide('slow');
    $('#bx_hd_exp').show('slow');
    $('#bx_exp_hd').unbind("click");
    $('#bx_exp_hd').bind('click', function () {
        Expand_Info();
    });
}

/* Box behaviour design */
function Expand_Usr_Bx(path, params, output, loadingid) {
    $(output).show('slow');
    $('#bx_tp_usr_arrow').removeClass('ui-icon-triangle-1-s');
    $('#bx_tp_usr_arrow').addClass('ui-icon-triangle-1-n');
    $('#bx_tp_usr_hd').unbind("click");
    $('#bx_tp_usr_hd').bind('click', function () { Collapse_Usr_Bx(path, params, output, loadingid); });
    // ajax request
    Process_Req(path, params, output, 'GET', loadingid)
}

function Collapse_Usr_Bx(path, params, output, loadingid) {
    $('#bx_tp_usr_arrow').addClass('ui-icon-triangle-1-s');
    $('#bx_tp_usr_arrow').removeClass('ui-icon-triangle-1-n');
    $('#bx_tp_usr_hd').unbind("click");
    $('#bx_tp_usr_hd').bind('click', function () { Expand_Usr_Bx(path, params, output, loadingid); });
    $(output).hide('slow');
}
// video stuff start
var pics = new Array();
var stat = new Array();
var pic = new Array();

function changepic(i, code) {
    var loop = 0;
    if (stat[code]) {
        while ((pics[code][i] == 0 || i >= 16) && loop < 100) {
            if (i >= 16) { i = 0; }
            else { i++; }
            loop++;
        }
        if (pic[code][i].complete) { document.getElementById(code).src = pic[code][i].src; setTimeout("changepic(" + (i + 1) + ",'" + code + "')", 500); }
        else {setTimeout("changepic(" + i + ",'" + code + "')", 20); }
    }
}
function loadpic(url, code, j) { if (stat[code]) { pic[code][j].src = url; }}
function startm(code, ta, te) {
    stat[code] = 1;
    var jj, jjj;
    var first = 1;

    for (var j = 0; j < 16; j++) {
        if (pics[code][j] == 1) {
            pic[code][j] = new Image();
            jj = j + 1;
            if (jj >= 100) { jjj = "" + jj; }
            if (jj < 100 && jj >= 10) { jjj = "0" + jj; }
            if (jj < 10) { jjj = "00" + jj; }
            if (first) { first = 0; loadpic(ta + jjj + te, code, j); }
            else { setTimeout("loadpic('" + ta + jjj + te + "','" + code + "'," + j + ")", j * 50); }
        }
    }
    changepic(0, code);
}

function endm(code) { stat[code] = 0; }

// Show / Hide Panels
function toggle_panel(index, pnl) {
    switch (index) {
        case 1:
            $(pnl).slideDown(1000);
            break;
        case 2:
            $(pnl).hide("highlight", 1000);
            break;
    }
}
function ShowHide(index, pnl) {
    switch (index) {
        case 1:
            $(pnl).show();
            break;
        case 2:
            $(pnl).hide();
            break;
    }
}

function toggle_tw_panel(index, pnl1, pnl2) {
    switch (index) {
        case 1:
            $(pnl1).show(); $(pnl2).hide(); break;
        case 2:
         $(pnl2).show(); $(pnl1).hide(); break; }}

// SWFObject v1.5:
if (typeof deconcept == "undefined") { var deconcept = new Object(); } if (typeof deconcept.util == "undefined") { deconcept.util = new Object(); } if (typeof deconcept.SWFObjectUtil == "undefined") { deconcept.SWFObjectUtil = new Object(); } deconcept.SWFObject = function (_1, id, w, h, _5, c, _7, _8, _9, _a) { if (!document.getElementById) { return; } this.DETECT_KEY = _a ? _a : "detectflash"; this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY); this.params = new Object(); this.variables = new Object(); this.attributes = new Array(); if (_1) { this.setAttribute("swf", _1); } if (id) { this.setAttribute("id", id); } if (w) { this.setAttribute("width", w); } if (h) { this.setAttribute("height", h); } if (_5) { this.setAttribute("version", new deconcept.PlayerVersion(_5.toString().split("."))); } this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion(); if (!window.opera && document.all && this.installedVer.major > 7) { deconcept.SWFObject.doPrepUnload = true; } if (c) { this.addParam("bgcolor", c); } var q = _7 ? _7 : "high"; this.addParam("quality", q); this.setAttribute("useExpressInstall", false); this.setAttribute("doExpressInstall", false); var _c = (_8) ? _8 : window.location; this.setAttribute("xiRedirectUrl", _c); this.setAttribute("redirectUrl", ""); if (_9) { this.setAttribute("redirectUrl", _9); } }; deconcept.SWFObject.prototype = { useExpressInstall: function (_d) { this.xiSWFPath = !_d ? "expressinstall.swf" : _d; this.setAttribute("useExpressInstall", true); }, setAttribute: function (_e, _f) { this.attributes[_e] = _f; }, getAttribute: function (_10) { return this.attributes[_10]; }, addParam: function (_11, _12) { this.params[_11] = _12; }, getParams: function () { return this.params; }, addVariable: function (_13, _14) { this.variables[_13] = _14; }, getVariable: function (_15) { return this.variables[_15]; }, getVariables: function () { return this.variables; }, getVariablePairs: function () { var _16 = new Array(); var key; var _18 = this.getVariables(); for (key in _18) { _16[_16.length] = key + "=" + _18[key]; } return _16; }, getSWFHTML: function () { var _19 = ""; if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { if (this.getAttribute("doExpressInstall")) { this.addVariable("MMplayerType", "PlugIn"); this.setAttribute("swf", this.xiSWFPath); } _19 = "<embed type=\"application/x-shockwave-flash\" src=\"" + this.getAttribute("swf") + "\" width=\"" + this.getAttribute("width") + "\" height=\"" + this.getAttribute("height") + "\" style=\"" + this.getAttribute("style") + "\""; _19 += " id=\"" + this.getAttribute("id") + "\" name=\"" + this.getAttribute("id") + "\" "; var _1a = this.getParams(); for (var key in _1a) { _19 += [key] + "=\"" + _1a[key] + "\" "; } var _1c = this.getVariablePairs().join("&"); if (_1c.length > 0) { _19 += "flashvars=\"" + _1c + "\""; } _19 += "/>"; } else { if (this.getAttribute("doExpressInstall")) { this.addVariable("MMplayerType", "ActiveX"); this.setAttribute("swf", this.xiSWFPath); } _19 = "<object id=\"" + this.getAttribute("id") + "\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"" + this.getAttribute("width") + "\" height=\"" + this.getAttribute("height") + "\" style=\"" + this.getAttribute("style") + "\">"; _19 += "<param name=\"movie\" value=\"" + this.getAttribute("swf") + "\" />"; var _1d = this.getParams(); for (var key in _1d) { _19 += "<param name=\"" + key + "\" value=\"" + _1d[key] + "\" />"; } var _1f = this.getVariablePairs().join("&"); if (_1f.length > 0) { _19 += "<param name=\"flashvars\" value=\"" + _1f + "\" />"; } _19 += "</object>"; } return _19; }, write: function (_20) { if (this.getAttribute("useExpressInstall")) { var _21 = new deconcept.PlayerVersion([6, 0, 65]); if (this.installedVer.versionIsValid(_21) && !this.installedVer.versionIsValid(this.getAttribute("version"))) { this.setAttribute("doExpressInstall", true); this.addVariable("MMredirectURL", escape(this.getAttribute("xiRedirectUrl"))); document.title = document.title.slice(0, 47) + " - Flash Player Installation"; this.addVariable("MMdoctitle", document.title); } } if (this.skipDetect || this.getAttribute("doExpressInstall") || this.installedVer.versionIsValid(this.getAttribute("version"))) { var n = (typeof _20 == "string") ? document.getElementById(_20) : _20; n.innerHTML = this.getSWFHTML(); return true; } else { if (this.getAttribute("redirectUrl") != "") { document.location.replace(this.getAttribute("redirectUrl")); } } return false; } }; deconcept.SWFObjectUtil.getPlayerVersion = function () { var _23 = new deconcept.PlayerVersion([0, 0, 0]); if (navigator.plugins && navigator.mimeTypes.length) { var x = navigator.plugins["Shockwave Flash"]; if (x && x.description) { _23 = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split(".")); } } else { if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0) { var axo = 1; var _26 = 3; while (axo) { try { _26++; axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + _26); _23 = new deconcept.PlayerVersion([_26, 0, 0]); } catch (e) { axo = null; } } } else { try { var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7"); } catch (e) { try { var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6"); _23 = new deconcept.PlayerVersion([6, 0, 21]); axo.AllowScriptAccess = "always"; } catch (e) { if (_23.major == 6) { return _23; } } try { axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); } catch (e) { } } if (axo != null) { _23 = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(",")); } } } return _23; }; deconcept.PlayerVersion = function (_29) { this.major = _29[0] != null ? parseInt(_29[0]) : 0; this.minor = _29[1] != null ? parseInt(_29[1]) : 0; this.rev = _29[2] != null ? parseInt(_29[2]) : 0; }; deconcept.PlayerVersion.prototype.versionIsValid = function (fv) { if (this.major < fv.major) { return false; } if (this.major > fv.major) { return true; } if (this.minor < fv.minor) { return false; } if (this.minor > fv.minor) { return true; } if (this.rev < fv.rev) { return false; } return true; }; deconcept.util = { getRequestParameter: function (_2b) { var q = document.location.search || document.location.hash; if (_2b == null) { return q; } if (q) { var _2d = q.substring(1).split("&"); for (var i = 0; i < _2d.length; i++) { if (_2d[i].substring(0, _2d[i].indexOf("=")) == _2b) { return _2d[i].substring((_2d[i].indexOf("=") + 1)); } } } return ""; } }; deconcept.SWFObjectUtil.cleanupSWFs = function () { var _2f = document.getElementsByTagName("OBJECT"); for (var i = _2f.length - 1; i >= 0; i--) { _2f[i].style.display = "none"; for (var x in _2f[i]) { if (typeof _2f[i][x] == "function") { _2f[i][x] = function () { }; } } } }; if (deconcept.SWFObject.doPrepUnload) { if (!deconcept.unloadSet) { deconcept.SWFObjectUtil.prepUnload = function () { __flash_unloadHandler = function () { }; __flash_savedUnloadHandler = function () { }; window.attachEvent("onunload", deconcept.SWFObjectUtil.cleanupSWFs); }; window.attachEvent("onbeforeunload", deconcept.SWFObjectUtil.prepUnload); deconcept.unloadSet = true; } } if (!document.getElementById && document.all) { document.getElementById = function (id) { return document.all[id]; }; } var getQueryParamValue = deconcept.util.getRequestParameter; var FlashObject = deconcept.SWFObject; var SWFObject = deconcept.SWFObject; // video suff end
// SWFObject v2.2:
// var swfobject = function () { var D = "undefined", r = "object", S = "Shockwave Flash", W = "ShockwaveFlash.ShockwaveFlash", q = "application/x-shockwave-flash", R = "SWFObjectExprInst", x = "onreadystatechange", O = window, j = document, t = navigator, T = false, U = [h], o = [], N = [], I = [], l, Q, E, B, J = false, a = false, n, G, m = true, M = function () { var aa = typeof j.getElementById != D && typeof j.getElementsByTagName != D && typeof j.createElement != D, ah = t.userAgent.toLowerCase(), Y = t.platform.toLowerCase(), ae = Y ? /win/.test(Y) : /win/.test(ah), ac = Y ? /mac/.test(Y) : /mac/.test(ah), af = /webkit/.test(ah) ? parseFloat(ah.replace(/^.*webkit\/(\d+(\.\d+)?).*$/, "$1")) : false, X = ! +"\v1", ag = [0, 0, 0], ab = null; if (typeof t.plugins != D && typeof t.plugins[S] == r) { ab = t.plugins[S].description; if (ab && !(typeof t.mimeTypes != D && t.mimeTypes[q] && !t.mimeTypes[q].enabledPlugin)) { T = true; X = false; ab = ab.replace(/^.*\s+(\S+\s+\S+$)/, "$1"); ag[0] = parseInt(ab.replace(/^(.*)\..*$/, "$1"), 10); ag[1] = parseInt(ab.replace(/^.*\.(.*)\s.*$/, "$1"), 10); ag[2] = /[a-zA-Z]/.test(ab) ? parseInt(ab.replace(/^.*[a-zA-Z]+(.*)$/, "$1"), 10) : 0 } } else { if (typeof O.ActiveXObject != D) { try { var ad = new ActiveXObject(W); if (ad) { ab = ad.GetVariable("$version"); if (ab) { X = true; ab = ab.split(" ")[1].split(","); ag = [parseInt(ab[0], 10), parseInt(ab[1], 10), parseInt(ab[2], 10)] } } } catch (Z) { } } } return { w3: aa, pv: ag, wk: af, ie: X, win: ae, mac: ac} } (), k = function () { if (!M.w3) { return } if ((typeof j.readyState != D && j.readyState == "complete") || (typeof j.readyState == D && (j.getElementsByTagName("body")[0] || j.body))) { f() } if (!J) { if (typeof j.addEventListener != D) { j.addEventListener("DOMContentLoaded", f, false) } if (M.ie && M.win) { j.attachEvent(x, function () { if (j.readyState == "complete") { j.detachEvent(x, arguments.callee); f() } }); if (O == top) { (function () { if (J) { return } try { j.documentElement.doScroll("left") } catch (X) { setTimeout(arguments.callee, 0); return } f() })() } } if (M.wk) { (function () { if (J) { return } if (!/loaded|complete/.test(j.readyState)) { setTimeout(arguments.callee, 0); return } f() })() } s(f) } } (); function f() { if (J) { return } try { var Z = j.getElementsByTagName("body")[0].appendChild(C("span")); Z.parentNode.removeChild(Z) } catch (aa) { return } J = true; var X = U.length; for (var Y = 0; Y < X; Y++) { U[Y]() } } function K(X) { if (J) { X() } else { U[U.length] = X } } function s(Y) { if (typeof O.addEventListener != D) { O.addEventListener("load", Y, false) } else { if (typeof j.addEventListener != D) { j.addEventListener("load", Y, false) } else { if (typeof O.attachEvent != D) { i(O, "onload", Y) } else { if (typeof O.onload == "function") { var X = O.onload; O.onload = function () { X(); Y() } } else { O.onload = Y } } } } } function h() { if (T) { V() } else { H() } } function V() { var X = j.getElementsByTagName("body")[0]; var aa = C(r); aa.setAttribute("type", q); var Z = X.appendChild(aa); if (Z) { var Y = 0; (function () { if (typeof Z.GetVariable != D) { var ab = Z.GetVariable("$version"); if (ab) { ab = ab.split(" ")[1].split(","); M.pv = [parseInt(ab[0], 10), parseInt(ab[1], 10), parseInt(ab[2], 10)] } } else { if (Y < 10) { Y++; setTimeout(arguments.callee, 10); return } } X.removeChild(aa); Z = null; H() })() } else { H() } } function H() { var ag = o.length; if (ag > 0) { for (var af = 0; af < ag; af++) { var Y = o[af].id; var ab = o[af].callbackFn; var aa = { success: false, id: Y }; if (M.pv[0] > 0) { var ae = c(Y); if (ae) { if (F(o[af].swfVersion) && !(M.wk && M.wk < 312)) { w(Y, true); if (ab) { aa.success = true; aa.ref = z(Y); ab(aa) } } else { if (o[af].expressInstall && A()) { var ai = {}; ai.data = o[af].expressInstall; ai.width = ae.getAttribute("width") || "0"; ai.height = ae.getAttribute("height") || "0"; if (ae.getAttribute("class")) { ai.styleclass = ae.getAttribute("class") } if (ae.getAttribute("align")) { ai.align = ae.getAttribute("align") } var ah = {}; var X = ae.getElementsByTagName("param"); var ac = X.length; for (var ad = 0; ad < ac; ad++) { if (X[ad].getAttribute("name").toLowerCase() != "movie") { ah[X[ad].getAttribute("name")] = X[ad].getAttribute("value") } } P(ai, ah, Y, ab) } else { p(ae); if (ab) { ab(aa) } } } } } else { w(Y, true); if (ab) { var Z = z(Y); if (Z && typeof Z.SetVariable != D) { aa.success = true; aa.ref = Z } ab(aa) } } } } } function z(aa) { var X = null; var Y = c(aa); if (Y && Y.nodeName == "OBJECT") { if (typeof Y.SetVariable != D) { X = Y } else { var Z = Y.getElementsByTagName(r)[0]; if (Z) { X = Z } } } return X } function A() { return !a && F("6.0.65") && (M.win || M.mac) && !(M.wk && M.wk < 312) } function P(aa, ab, X, Z) { a = true; E = Z || null; B = { success: false, id: X }; var ae = c(X); if (ae) { if (ae.nodeName == "OBJECT") { l = g(ae); Q = null } else { l = ae; Q = X } aa.id = R; if (typeof aa.width == D || (!/%$/.test(aa.width) && parseInt(aa.width, 10) < 310)) { aa.width = "310" } if (typeof aa.height == D || (!/%$/.test(aa.height) && parseInt(aa.height, 10) < 137)) { aa.height = "137" } j.title = j.title.slice(0, 47) + " - Flash Player Installation"; var ad = M.ie && M.win ? "ActiveX" : "PlugIn", ac = "MMredirectURL=" + O.location.toString().replace(/&/g, "%26") + "&MMplayerType=" + ad + "&MMdoctitle=" + j.title; if (typeof ab.flashvars != D) { ab.flashvars += "&" + ac } else { ab.flashvars = ac } if (M.ie && M.win && ae.readyState != 4) { var Y = C("div"); X += "SWFObjectNew"; Y.setAttribute("id", X); ae.parentNode.insertBefore(Y, ae); ae.style.display = "none"; (function () { if (ae.readyState == 4) { ae.parentNode.removeChild(ae) } else { setTimeout(arguments.callee, 10) } })() } u(aa, ab, X) } } function p(Y) { if (M.ie && M.win && Y.readyState != 4) { var X = C("div"); Y.parentNode.insertBefore(X, Y); X.parentNode.replaceChild(g(Y), X); Y.style.display = "none"; (function () { if (Y.readyState == 4) { Y.parentNode.removeChild(Y) } else { setTimeout(arguments.callee, 10) } })() } else { Y.parentNode.replaceChild(g(Y), Y) } } function g(ab) { var aa = C("div"); if (M.win && M.ie) { aa.innerHTML = ab.innerHTML } else { var Y = ab.getElementsByTagName(r)[0]; if (Y) { var ad = Y.childNodes; if (ad) { var X = ad.length; for (var Z = 0; Z < X; Z++) { if (!(ad[Z].nodeType == 1 && ad[Z].nodeName == "PARAM") && !(ad[Z].nodeType == 8)) { aa.appendChild(ad[Z].cloneNode(true)) } } } } } return aa } function u(ai, ag, Y) { var X, aa = c(Y); if (M.wk && M.wk < 312) { return X } if (aa) { if (typeof ai.id == D) { ai.id = Y } if (M.ie && M.win) { var ah = ""; for (var ae in ai) { if (ai[ae] != Object.prototype[ae]) { if (ae.toLowerCase() == "data") { ag.movie = ai[ae] } else { if (ae.toLowerCase() == "styleclass") { ah += ' class="' + ai[ae] + '"' } else { if (ae.toLowerCase() != "classid") { ah += " " + ae + '="' + ai[ae] + '"' } } } } } var af = ""; for (var ad in ag) { if (ag[ad] != Object.prototype[ad]) { af += '<param name="' + ad + '" value="' + ag[ad] + '" />' } } aa.outerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' + ah + ">" + af + "</object>"; N[N.length] = ai.id; X = c(ai.id) } else { var Z = C(r); Z.setAttribute("type", q); for (var ac in ai) { if (ai[ac] != Object.prototype[ac]) { if (ac.toLowerCase() == "styleclass") { Z.setAttribute("class", ai[ac]) } else { if (ac.toLowerCase() != "classid") { Z.setAttribute(ac, ai[ac]) } } } } for (var ab in ag) { if (ag[ab] != Object.prototype[ab] && ab.toLowerCase() != "movie") { e(Z, ab, ag[ab]) } } aa.parentNode.replaceChild(Z, aa); X = Z } } return X } function e(Z, X, Y) { var aa = C("param"); aa.setAttribute("name", X); aa.setAttribute("value", Y); Z.appendChild(aa) } function y(Y) { var X = c(Y); if (X && X.nodeName == "OBJECT") { if (M.ie && M.win) { X.style.display = "none"; (function () { if (X.readyState == 4) { b(Y) } else { setTimeout(arguments.callee, 10) } })() } else { X.parentNode.removeChild(X) } } } function b(Z) { var Y = c(Z); if (Y) { for (var X in Y) { if (typeof Y[X] == "function") { Y[X] = null } } Y.parentNode.removeChild(Y) } } function c(Z) { var X = null; try { X = j.getElementById(Z) } catch (Y) { } return X } function C(X) { return j.createElement(X) } function i(Z, X, Y) { Z.attachEvent(X, Y); I[I.length] = [Z, X, Y] } function F(Z) { var Y = M.pv, X = Z.split("."); X[0] = parseInt(X[0], 10); X[1] = parseInt(X[1], 10) || 0; X[2] = parseInt(X[2], 10) || 0; return (Y[0] > X[0] || (Y[0] == X[0] && Y[1] > X[1]) || (Y[0] == X[0] && Y[1] == X[1] && Y[2] >= X[2])) ? true : false } function v(ac, Y, ad, ab) { if (M.ie && M.mac) { return } var aa = j.getElementsByTagName("head")[0]; if (!aa) { return } var X = (ad && typeof ad == "string") ? ad : "screen"; if (ab) { n = null; G = null } if (!n || G != X) { var Z = C("style"); Z.setAttribute("type", "text/css"); Z.setAttribute("media", X); n = aa.appendChild(Z); if (M.ie && M.win && typeof j.styleSheets != D && j.styleSheets.length > 0) { n = j.styleSheets[j.styleSheets.length - 1] } G = X } if (M.ie && M.win) { if (n && typeof n.addRule == r) { n.addRule(ac, Y) } } else { if (n && typeof j.createTextNode != D) { n.appendChild(j.createTextNode(ac + " {" + Y + "}")) } } } function w(Z, X) { if (!m) { return } var Y = X ? "visible" : "hidden"; if (J && c(Z)) { c(Z).style.visibility = Y } else { v("#" + Z, "visibility:" + Y) } } function L(Y) { var Z = /[\\\"<>\.;]/; var X = Z.exec(Y) != null; return X && typeof encodeURIComponent != D ? encodeURIComponent(Y) : Y } var d = function () { if (M.ie && M.win) { window.attachEvent("onunload", function () { var ac = I.length; for (var ab = 0; ab < ac; ab++) { I[ab][0].detachEvent(I[ab][1], I[ab][2]) } var Z = N.length; for (var aa = 0; aa < Z; aa++) { y(N[aa]) } for (var Y in M) { M[Y] = null } M = null; for (var X in swfobject) { swfobject[X] = null } swfobject = null }) } } (); return { registerObject: function (ab, X, aa, Z) { if (M.w3 && ab && X) { var Y = {}; Y.id = ab; Y.swfVersion = X; Y.expressInstall = aa; Y.callbackFn = Z; o[o.length] = Y; w(ab, false) } else { if (Z) { Z({ success: false, id: ab }) } } }, getObjectById: function (X) { if (M.w3) { return z(X) } }, embedSWF: function (ab, ah, ae, ag, Y, aa, Z, ad, af, ac) { var X = { success: false, id: ah }; if (M.w3 && !(M.wk && M.wk < 312) && ab && ah && ae && ag && Y) { w(ah, false); K(function () { ae += ""; ag += ""; var aj = {}; if (af && typeof af === r) { for (var al in af) { aj[al] = af[al] } } aj.data = ab; aj.width = ae; aj.height = ag; var am = {}; if (ad && typeof ad === r) { for (var ak in ad) { am[ak] = ad[ak] } } if (Z && typeof Z === r) { for (var ai in Z) { if (typeof am.flashvars != D) { am.flashvars += "&" + ai + "=" + Z[ai] } else { am.flashvars = ai + "=" + Z[ai] } } } if (F(Y)) { var an = u(aj, am, ah); if (aj.id == ah) { w(ah, true) } X.success = true; X.ref = an } else { if (aa && A()) { aj.data = aa; P(aj, am, ah, ac); return } else { w(ah, true) } } if (ac) { ac(X) } }) } else { if (ac) { ac(X) } } }, switchOffAutoHideShow: function () { m = false }, ua: M, getFlashPlayerVersion: function () { return { major: M.pv[0], minor: M.pv[1], release: M.pv[2]} }, hasFlashPlayerVersion: F, createSWF: function (Z, Y, X) { if (M.w3) { return u(Z, Y, X) } else { return undefined } }, showExpressInstall: function (Z, aa, X, Y) { if (M.w3 && A()) { P(Z, aa, X, Y) } }, removeSWF: function (X) { if (M.w3) { y(X) } }, createCSS: function (aa, Z, Y, X) { if (M.w3) { v(aa, Z, Y, X) } }, addDomLoadEvent: K, addLoadEvent: s, getQueryParamValue: function (aa) { var Z = j.location.search || j.location.hash; if (Z) { if (/\?/.test(Z)) { Z = Z.split("?")[1] } if (aa == null) { return L(Z) } var Y = Z.split("&"); for (var X = 0; X < Y.length; X++) { if (Y[X].substring(0, Y[X].indexOf("=")) == aa) { return L(Y[X].substring((Y[X].indexOf("=") + 1))) } } } return "" }, expressInstallCallback: function () { if (a) { var X = c(R); if (X && l) { X.parentNode.replaceChild(l, X); if (Q) { w(Q, true); if (M.ie && M.win) { l.style.display = "block" } } if (E) { E(B) } } a = false } } } } ();

// simple tooltip // will tie this into the main AMS class at some point..
(function ($) { $.fn.tipTip = function (options) { var defaults = { activation: "hover", keepAlive: false, maxWidth: "200px", edgeOffset: 3, defaultPosition: "bottom", delay: 400, fadeIn: 200, fadeOut: 200, attribute: "title", content: false, enter: function () { }, exit: function () { } }; var opts = $.extend(defaults, options); if ($("#tiptip_holder").length <= 0) { var tiptip_holder = $('<div id="tiptip_holder" style="max-width:' + opts.maxWidth + ';"></div>'); var tiptip_content = $('<div id="tiptip_content"></div>'); var tiptip_arrow = $('<div id="tiptip_arrow"></div>'); $("body").append(tiptip_holder.html(tiptip_content).prepend(tiptip_arrow.html('<div id="tiptip_arrow_inner"></div>'))) } else { var tiptip_holder = $("#tiptip_holder"); var tiptip_content = $("#tiptip_content"); var tiptip_arrow = $("#tiptip_arrow") } return this.each(function () { var org_elem = $(this); if (opts.content) { var org_title = opts.content } else { var org_title = org_elem.attr(opts.attribute) } if (org_title != "") { if (!opts.content) { org_elem.removeAttr(opts.attribute) } var timeout = false; if (opts.activation == "hover") { org_elem.hover(function () { active_tiptip() }, function () { if (!opts.keepAlive) { deactive_tiptip() } }); if (opts.keepAlive) { tiptip_holder.hover(function () { }, function () { deactive_tiptip() }) } } else if (opts.activation == "focus") { org_elem.focus(function () { active_tiptip() }).blur(function () { deactive_tiptip() }) } else if (opts.activation == "click") { org_elem.click(function () { active_tiptip(); return false }).hover(function () { }, function () { if (!opts.keepAlive) { deactive_tiptip() } }); if (opts.keepAlive) { tiptip_holder.hover(function () { }, function () { deactive_tiptip() }) } } function active_tiptip() { opts.enter.call(this); tiptip_content.html(org_title); tiptip_holder.hide().removeAttr("class").css("margin", "0"); tiptip_arrow.removeAttr("style"); var top = parseInt(org_elem.offset()['top']); var left = parseInt(org_elem.offset()['left']); var org_width = parseInt(org_elem.outerWidth()); var org_height = parseInt(org_elem.outerHeight()); var tip_w = tiptip_holder.outerWidth(); var tip_h = tiptip_holder.outerHeight(); var w_compare = Math.round((org_width - tip_w) / 2); var h_compare = Math.round((org_height - tip_h) / 2); var marg_left = Math.round(left + w_compare); var marg_top = Math.round(top + org_height + opts.edgeOffset); var t_class = ""; var arrow_top = ""; var arrow_left = Math.round(tip_w - 12) / 2; if (opts.defaultPosition == "bottom") { t_class = "_bottom" } else if (opts.defaultPosition == "top") { t_class = "_top" } else if (opts.defaultPosition == "left") { t_class = "_left" } else if (opts.defaultPosition == "right") { t_class = "_right" } var right_compare = (w_compare + left) < parseInt($(window).scrollLeft()); var left_compare = (tip_w + left) > parseInt($(window).width()); if ((right_compare && w_compare < 0) || (t_class == "_right" && !left_compare) || (t_class == "_left" && left < (tip_w + opts.edgeOffset + 5))) { t_class = "_right"; arrow_top = Math.round(tip_h - 13) / 2; arrow_left = -12; marg_left = Math.round(left + org_width + opts.edgeOffset); marg_top = Math.round(top + h_compare) } else if ((left_compare && w_compare < 0) || (t_class == "_left" && !right_compare)) { t_class = "_left"; arrow_top = Math.round(tip_h - 13) / 2; arrow_left = Math.round(tip_w); marg_left = Math.round(left - (tip_w + opts.edgeOffset + 5)); marg_top = Math.round(top + h_compare) } var top_compare = (top + org_height + opts.edgeOffset + tip_h + 8) > parseInt($(window).height() + $(window).scrollTop()); var bottom_compare = ((top + org_height) - (opts.edgeOffset + tip_h + 8)) < 0; if (top_compare || (t_class == "_bottom" && top_compare) || (t_class == "_top" && !bottom_compare)) { if (t_class == "_top" || t_class == "_bottom") { t_class = "_top" } else { t_class = t_class + "_top" } arrow_top = tip_h; marg_top = Math.round(top - (tip_h + 5 + opts.edgeOffset)) } else if (bottom_compare | (t_class == "_top" && bottom_compare) || (t_class == "_bottom" && !top_compare)) { if (t_class == "_top" || t_class == "_bottom") { t_class = "_bottom" } else { t_class = t_class + "_bottom" } arrow_top = -12; marg_top = Math.round(top + org_height + opts.edgeOffset) } if (t_class == "_right_top" || t_class == "_left_top") { marg_top = marg_top + 5 } else if (t_class == "_right_bottom" || t_class == "_left_bottom") { marg_top = marg_top - 5 } if (t_class == "_left_top" || t_class == "_left_bottom") { marg_left = marg_left + 5 } tiptip_arrow.css({ "margin-left": arrow_left + "px", "margin-top": arrow_top + "px" }); tiptip_holder.css({ "margin-left": marg_left + "px", "margin-top": marg_top + "px" }).attr("class", "tip" + t_class); if (timeout) { clearTimeout(timeout) } timeout = setTimeout(function () { tiptip_holder.stop(true, true).fadeIn(opts.fadeIn) }, opts.delay) } function deactive_tiptip() { opts.exit.call(this); if (timeout) { clearTimeout(timeout) } tiptip_holder.fadeOut(opts.fadeOut) } } }) } })(jQuery);
