﻿/**
 * appendDom - Extremely flexible tool for dynamic dom creation.
 *   http://byron-adams.com/projects/jquery/appendDom
 *
 * Copyright (c) 2007 Byron Adams (http://byron-adams.com)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 */
jQuery.fn.appendDom = function(template) {
  return this.each(function() {
    for (element in template) {
      var el = (typeof(template[element].tagName) === 'string') ?
        document.createElement(template[element].tagName): document.createTextNode('');
      delete template[element].tagName;
      for (attrib in template[element]) {
        switch ( typeof(template[element][attrib]) ) {
          case 'string' :
            if ( typeof(el[attrib]) === 'string' ) {          
             el[attrib] = template[element][attrib];
            } else {
              el.setAttribute(attrib, template[element][attrib]);
            }
            break;
          case 'function':
            el[attrib] = template[element][attrib];
            break;
          case 'object' :
            if (attrib === 'childNodes')  {$(el).appendDom(template[element][attrib]);}
            break;
        }
      }
      this.appendChild(el);
    }
  });
};

/**
 * 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 = {
	height: 240,
	flashvars: {},
	pluginspage: 'http://www.adobe.com/go/getflashplayer',
	src: '#',
	type: 'application/x-shockwave-flash',
	width: 320		
};
/**
 *
 * @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() {};
	});
}

})();

/**
* Ajax upload
* Project page - http://valums.com/ajax-upload/
* Copyright (c) 2008 Andris Valums, http://valums.com
* Licensed under the MIT license (http://valums.com/mit-license/)
* Version 3.2 (19.05.2009)
*/

/**
* Changes from the previous version:
* 1. Input is cleared after submit is canceled to allow user to select same file
* 2. Fixed problem with FF3 when used on page with smaller font size
* 
* For the full changelog please visit: 
* http://valums.com/ajax-upload-changelog/
*/

(function() {

    var d = document, w = window;

    /**
    * Get element by id
    */
    function get(element) {
        if (typeof element == "string")
            element = d.getElementById(element);
        return element;
    }

    /**
    * Attaches event to a dom element
    */
    function addEvent(el, type, fn) {
        if (w.addEventListener) {
            el.addEventListener(type, fn, false);
        } else if (w.attachEvent) {
            var f = function() {
                fn.call(el, w.event);
            };
            el.attachEvent('on' + type, f)
        }
    }


    /**
    * Creates and returns element from html chunk
    */
    var toElement = function() {
        var div = d.createElement('div');
        return function(html) {
            div.innerHTML = html;
            var el = div.childNodes[0];
            div.removeChild(el);
            return el;
        }
    } ();

    function hasClass(ele, cls) {
        return ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
    }
    function addClass(ele, cls) {
        if (!hasClass(ele, cls)) ele.className += " " + cls;
    }
    function removeClass(ele, cls) {
        var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
        ele.className = ele.className.replace(reg, ' ');
    }

    // getOffset function copied from jQuery lib (http://jquery.com/)
    if (document.documentElement["getBoundingClientRect"]) {
        // Get Offset using getBoundingClientRect
        // http://ejohn.org/blog/getboundingclientrect-is-awesome/
        var getOffset = function(el) {
            var box = el.getBoundingClientRect(),
		doc = el.ownerDocument,
		body = doc.body,
		docElem = doc.documentElement,

            // for ie 
		clientTop = docElem.clientTop || body.clientTop || 0,
		clientLeft = docElem.clientLeft || body.clientLeft || 0,

            // In Internet Explorer 7 getBoundingClientRect property is treated as physical,
            // while others are logical. Make all logical, like in IE8.


		zoom = 1;
            if (body.getBoundingClientRect) {
                var bound = body.getBoundingClientRect();
                zoom = (bound.right - bound.left) / body.clientWidth;
            }
            if (zoom > 1) {
                clientTop = 0;
                clientLeft = 0;
            }
            var top = box.top / zoom + (window.pageYOffset || docElem && docElem.scrollTop / zoom || body.scrollTop / zoom) - clientTop,
		left = box.left / zoom + (window.pageXOffset || docElem && docElem.scrollLeft / zoom || body.scrollLeft / zoom) - clientLeft;

            return {
                top: top,
                left: left
            };
        }

    } else {
        // Get offset adding all offsets 
        var getOffset = function(el) {
            if (w.jQuery) {
                return jQuery(el).offset();
            }

            var top = 0, left = 0;
            do {
                top += el.offsetTop || 0;
                left += el.offsetLeft || 0;
            }
            while (el = el.offsetParent);

            return {
                left: left,
                top: top
            };
        }
    }

    function getBox(el) {
        var left, right, top, bottom;
        var offset = getOffset(el);
        left = offset.left;
        top = offset.top;

        right = left + el.offsetWidth;
        bottom = top + el.offsetHeight;

        return {
            left: left,
            right: right,
            top: top,
            bottom: bottom
        };
    }

    /**
    * Crossbrowser mouse coordinates
    */
    function getMouseCoords(e) {
        // pageX/Y is not supported in IE
        // http://www.quirksmode.org/dom/w3c_cssom.html			
        if (!e.pageX && e.clientX) {
            // In Internet Explorer 7 some properties (mouse coordinates) are treated as physical,
            // while others are logical (offset).
            var zoom = 1;
            var body = document.body;

            if (body.getBoundingClientRect) {
                var bound = body.getBoundingClientRect();
                zoom = (bound.right - bound.left) / body.clientWidth;
            }

            return {
                x: e.clientX / zoom + d.body.scrollLeft + d.documentElement.scrollLeft,
                y: e.clientY / zoom + d.body.scrollTop + d.documentElement.scrollTop
            };
        }

        return {
            x: e.pageX,
            y: e.pageY
        };

    }
    /**
    * Function generates unique id
    */
    var getUID = function() {
        var id = 0;
        return function() {
            return 'ValumsAjaxUpload' + id++;
        }
    } ();

    function fileFromPath(file) {
        return file.replace(/.*(\/|\\)/, "");
    }

    function getExt(file) {
        return (/[.]/.exec(file)) ? /[^.]+$/.exec(file.toLowerCase()) : '';
    }

    // Please use AjaxUpload , Ajax_upload will be removed in the next version
    Ajax_upload = AjaxUpload = function(button, options) {
        if (button.jquery) {
            // jquery object was passed
            button = button[0];
        } else if (typeof button == "string" && /^#.*/.test(button)) {
            button = button.slice(1);
        }
        button = get(button);

        this._input = null;
        this._button = button;
        this._disabled = false;
        this._submitting = false;
        // Variable changes to true if the button was clicked
        // 3 seconds ago (requred to fix Safari on Mac error)
        this._justClicked = false;
        this._parentDialog = d.body;

        if (window.jQuery && jQuery.ui && jQuery.ui.dialog) {
            var parentDialog = jQuery(self._button).parents('.ui-dialog-content');
            if (parentDialog.length) {
                this._parentDialog = parentDialog[0];
            }
        }

        this._settings = {
            // Location of the server-side upload script
            action: 'upload.php',
            // File upload name
            name: 'userfile',
            // Additional data to send
            data: {},
            // Submit file as soon as it's selected
            autoSubmit: true,
            // The type of data that you're expecting back from the server.
            // Html and xml are detected automatically.
            // Only useful when you are using json data as a response.
            // Set to "json" in that case. 
            responseType: false,
            // When user selects a file, useful with autoSubmit disabled			
            onChange: function(file, extension) { },
            // Callback to fire before file is uploaded
            // You can return false to cancel upload
            onSubmit: function(file, extension) { },
            // Fired when file upload is completed
            // WARNING! DO NOT USE "FALSE" STRING AS A RESPONSE!
            onComplete: function(file, response) { }
        };

        // Merge the users options with our defaults
        for (var i in options) {
            this._settings[i] = options[i];
        }

        this._createInput();
        this._rerouteClicks();
    }

    // assigning methods to our class
    AjaxUpload.prototype = {
        setData: function(data) {
            this._settings.data = data;
        },
        disable: function() {
            this._disabled = true;
        },
        enable: function() {
            this._disabled = false;
        },
        // removes ajaxupload
        destroy: function() {
            if (this._input) {
                if (this._input.parentNode) {
                    this._input.parentNode.removeChild(this._input);
                }
                this._input = null;
            }
        },
        /**
        * Creates invisible file input above the button 
        */
        _createInput: function() {
            var self = this;
            var input = d.createElement("input");
            input.setAttribute('type', 'file');
            input.setAttribute('name', this._settings.name);
            var styles = {
                'position': 'absolute'
			, 'margin': '-5px 0 0 -175px'
			, 'padding': 0
			, 'width': '220px'
			, 'height': '30px'
			, 'fontSize': '14px'
			, 'opacity': 0
			, 'cursor': 'pointer'
			, 'display': 'none'
			, 'zIndex': 2147483583 //Max zIndex supported by Opera 9.0-9.2x 
                // Strange, I expected 2147483647					
            };
            for (var i in styles) {
                input.style[i] = styles[i];
            }

            // Make sure that element opacity exists
            // (IE uses filter instead)
            if (!(input.style.opacity === "0")) {
                input.style.filter = "alpha(opacity=0)";
            }

            this._parentDialog.appendChild(input);

            addEvent(input, 'change', function() {
                // get filename from input
                var file = fileFromPath(this.value);
                if (self._settings.onChange.call(self, file, getExt(file)) == false) {
                    return;
                }
                // Submit form when value is changed
                if (self._settings.autoSubmit) {
                    self.submit();
                }
            });

            // Fixing problem with Safari
            // The problem is that if you leave input before the file select dialog opens
            // it does not upload the file.
            // As dialog opens slowly (it is a sheet dialog which takes some time to open)
            // there is some time while you can leave the button.
            // So we should not change display to none immediately
            addEvent(input, 'click', function() {
                self.justClicked = true;
                setTimeout(function() {
                    // we will wait 3 seconds for dialog to open
                    self.justClicked = false;
                }, 3000);
            });

            this._input = input;
        },
        _rerouteClicks: function() {
            var self = this;

            // IE displays 'access denied' error when using this method
            // other browsers just ignore click()
            // addEvent(this._button, 'click', function(e){
            //   self._input.click();
            // });

            var box, dialogOffset = { top: 0, left: 0 }, over = false;
            addEvent(self._button, 'mouseover', function(e) {
                if (!self._input || over) return;
                over = true;
                box = getBox(self._button);

                if (self._parentDialog != d.body) {
                    dialogOffset = getOffset(self._parentDialog);
                }
            });


            // we can't use mouseout on the button,
            // because invisible input is over it
            addEvent(document, 'mousemove', function(e) {
                var input = self._input;
                if (!input || !over) return;

                if (self._disabled) {
                    removeClass(self._button, 'hover');
                    input.style.display = 'none';
                    return;
                }

                var c = getMouseCoords(e);

                if ((c.x >= box.left) && (c.x <= box.right) &&
			(c.y >= box.top) && (c.y <= box.bottom)) {
                    input.style.top = c.y - dialogOffset.top + 'px';
                    input.style.left = c.x - dialogOffset.left + 'px';
                    input.style.display = 'block';
                    addClass(self._button, 'hover');
                } else {
                    // mouse left the button
                    over = false;
                    if (!self.justClicked) {
                        input.style.display = 'none';
                    }
                    removeClass(self._button, 'hover');
                }
            });

        },
        /**
        * Creates iframe with unique name
        */
        _createIframe: function() {
            // unique name
            // We cannot use getTime, because it sometimes return
            // same value in safari :(
            var id = getUID();

            // Remove ie6 "This page contains both secure and nonsecure items" prompt 
            // http://tinyurl.com/77w9wh
            var iframe = toElement('<iframe src="javascript:false;" name="' + id + '" />');
            iframe.id = id;
            iframe.style.display = 'none';
            d.body.appendChild(iframe);
            return iframe;
        },
        /**
        * Upload file without refreshing the page
        */
        submit: function() {
            var self = this, settings = this._settings;

            if (this._input.value === '') {
                // there is no file
                return;
            }

            // get filename from input
            var file = fileFromPath(this._input.value);

            // execute user event
            if (!(settings.onSubmit.call(this, file, getExt(file)) == false)) {
                // Create new iframe for this submission
                var iframe = this._createIframe();

                // Do not submit if user function returns false										
                var form = this._createForm(iframe);
                form.appendChild(this._input);

                form.submit();

                d.body.removeChild(form);
                form = null;
                this._input = null;

                // create new input
                this._createInput();

                var toDeleteFlag = false;

                addEvent(iframe, 'load', function(e) {
                    if (iframe.src == "about:blank") {
                        // First time around, do not delete.
                        if (toDeleteFlag) {
                            // Fix busy state in FF3
                            setTimeout(function() {
                                d.body.removeChild(iframe);
                            }, 0);
                        }
                        return;
                    }

                    var doc = iframe.contentDocument ? iframe.contentDocument : frames[iframe.id].document;

                    // fixing Opera 9.26
                    if (doc.readyState && doc.readyState != 'complete') {
                        // Opera fires load event multiple times
                        // Even when the DOM is not ready yet
                        // this fix should not affect other browsers
                        return;
                    }

                    // fixing Opera 9.64
                    if (doc.body && doc.body.innerHTML == "false") {
                        // In Opera 9.64 event was fired second time
                        // when body.innerHTML changed from false 
                        // to server response approx. after 1 sec
                        return;
                    }

                    var response;

                    if (doc.XMLDocument) {
                        // response is a xml document IE property
                        response = doc.XMLDocument;
                    } else if (doc.body) {
                        // response is html document or plain text
                        response = doc.body.innerHTML;
                        if (settings.responseType == 'json') {
                            response = window["eval"]("(" + response + ")");
                        }
                    } else {
                        // response is a xml document
                        var response = doc;
                    }

                    settings.onComplete.call(self, file, response);

                    // Reload blank page, so that reloading main page
                    // does not re-submit the post. Also, remember to
                    // delete the frame
                    toDeleteFlag = true;
                    iframe.src = "about:blank"; //load event fired				 								
                });

            } else {
                // clear input to allow user to select same file
                // Doesn't work in IE6
                // this._input.value = '';
                d.body.removeChild(this._input);
                this._input = null;

                // create new input
                this._createInput();
            }
        },
        /**
        * Creates form, that will be submitted to iframe
        */
        _createForm: function(iframe) {
            var settings = this._settings;

            // method, enctype must be specified here
            // because changing this attr on the fly is not allowed in IE 6/7		
            var form = toElement('<form method="post" enctype="multipart/form-data"></form>');
            form.style.display = 'none';
            form.action = settings.action;
            form.target = iframe.name;
            d.body.appendChild(form);

            // Create hidden input element for each data key
            for (var prop in settings.data) {
                var el = d.createElement("input");
                el.type = 'hidden';
                el.name = prop;
                el.value = settings.data[prop];
                form.appendChild(el);
            }
            return form;
        }
    };
})();

/*
* imgAreaSelect jQuery plugin
* version 0.8
*
* Copyright (c) 2008-2009 Michal Wojciechowski (odyniec.net)
*
* Dual licensed under the MIT (MIT-LICENSE.txt) 
* and GPL (GPL-LICENSE.txt) licenses.
*
* http://odyniec.net/projects/imgareaselect/
*
*/

(function($) {

    $.imgAreaSelect = { onKeyPress: null };

    $.imgAreaSelect.init = function(img, options) {
        var $img = $(img), imgLoaded, $box = $('<div />'), $area = $('<div />'),
        $border1 = $('<div />'), $border2 = $('<div />'), $areaOpera,
        $outLeft = $('<div />'), $outTop = $('<div />'),
        $outRight = $('<div />'), $outBottom = $('<div />'),
        $handles = $([]), handleWidth, handles = [], left, top, M = Math,
        imgOfs, imgWidth, imgHeight, $parent, parOfs,
        zIndex = 0, position = 'absolute', $p, startX, startY,
        scaleX = 1, scaleY = 1, resizeMargin = 10, resize = [], V = 0, H = 1,
        d, aspectRatio, x1, x2, y1, y2, x, y, adjusted, shown, i,
        selection = { x1: 0, y1: 0, x2: 0, y2: 0, width: 0, height: 0 };

        var $o = $outLeft.add($outTop).add($outRight).add($outBottom);

        function viewX(x) {
            return x + imgOfs.left - parOfs.left;
        }

        function viewY(y) {
            return y + imgOfs.top - parOfs.top;
        }

        function selX(x) {
            return x - imgOfs.left + parOfs.left;
        }

        function selY(y) {
            return y - imgOfs.top + parOfs.top;
        }

        function evX(event) {
            return event.pageX - parOfs.left;
        }

        function evY(event) {
            return event.pageY - parOfs.top;
        }

        function trueSelection() {
            return { x1: M.round(selection.x1 * scaleX),
                y1: M.round(selection.y1 * scaleY),
                x2: M.round(selection.x2 * scaleX),
                y2: M.round(selection.y2 * scaleY),
                width: M.round(selection.x2 * scaleX) - M.round(selection.x1 * scaleX),
                height: M.round(selection.y2 * scaleY) - M.round(selection.y1 * scaleY)
            };
        }

        function getZIndex() {
            $p = $img;

            while ($p.length && !$p.is('body')) {
                if (!isNaN($p.css('z-index')) && $p.css('z-index') > zIndex)
                    zIndex = $p.css('z-index');
                if ($p.css('position') == 'fixed')
                    position = 'fixed';

                $p = $p.parent();
            }

            if (!isNaN(options.zIndex))
                zIndex = options.zIndex;
        }

        function adjust() {
            imgOfs = { left: M.round($img.offset().left), top: M.round($img.offset().top) };
            imgWidth = $img.width();
            imgHeight = $img.height();

            if ($().jquery == '1.3.2' && $.browser.safari && position == 'fixed') {
                imgOfs.top += M.max(document.documentElement.scrollTop, $('body').scrollTop());
                imgOfs.left += M.max(document.documentElement.scrollLeft, $('body').scrollLeft());
            }

            parOfs = $.inArray($parent.css('position'), ['absolute', 'relative']) != -1 ?
            { left: M.round($parent.offset().left) - $parent.scrollLeft(),
                top: M.round($parent.offset().top) - $parent.scrollTop()} :
            position == 'fixed' ?
                { left: $(document).scrollLeft(), top: $(document).scrollTop()} :
                { left: 0, top: 0 };

                left = viewX(0);
                top = viewY(0);
            }

            function update(resetKeyPress) {
                if (!shown) return;

                $box.css({
                    left: viewX(selection.x1) + 'px', top: viewY(selection.y1) + 'px',
                    width: selection.width + 'px', height: selection.height + 'px'
                });
                $area.add($border1).add($border2).css({
                    left: '0px', top: '0px',
                    width: M.max(selection.width - options.borderWidth * 2, 0) + 'px',
                    height: M.max(selection.height - options.borderWidth * 2, 0) + 'px'
                });
                $border1.css({ borderStyle: 'solid', borderColor: options.borderColor1 });
                $border2.css({ borderStyle: 'dashed', borderColor: options.borderColor2 });
                $border1.add($border2).css({ opacity: options.borderOpacity });
                $outLeft.css({ left: left + 'px', top: top + 'px',
                    width: selection.x1 + 'px', height: imgHeight + 'px'
                });
                $outTop.css({ left: left + selection.x1 + 'px', top: top + 'px',
                    width: selection.width + 'px', height: selection.y1 + 'px'
                });
                $outRight.css({ left: left + selection.x2 + 'px', top: top + 'px',
                    width: imgWidth - selection.x2 + 'px', height: imgHeight + 'px'
                });
                $outBottom.css({ left: left + selection.x1 + 'px', top: top + selection.y2 + 'px',
                    width: selection.width + 'px', height: imgHeight - selection.y2 + 'px'
                });

                if (handles.length) {
                    handles[1].css({ left: selection.width - handleWidth + 'px' });
                    handles[2].css({ left: selection.width - handleWidth + 'px',
                        top: selection.height - handleWidth + 'px'
                    });
                    handles[3].css({ top: selection.height - handleWidth + 'px' });

                    if (handles.length == 8) {
                        handles[4].css({ left: (selection.width - handleWidth) / 2 + 'px' });
                        handles[5].css({ left: selection.width - handleWidth + 'px',
                            top: (selection.height - handleWidth) / 2 + 'px'
                        });
                        handles[6].css({ left: (selection.width - handleWidth) / 2 + 'px',
                            top: selection.height - handleWidth + 'px'
                        });
                        handles[7].css({ top: (selection.height - handleWidth) / 2 + 'px' });
                    }
                }

                if (resetKeyPress !== false) {
                    if ($.imgAreaSelect.keyPress != docKeyPress)
                        $(document).unbind($.imgAreaSelect.keyPress,
                    $.imgAreaSelect.onKeyPress);

                    if (options.keys)
                        $(document).bind($.imgAreaSelect.keyPress,
                    $.imgAreaSelect.onKeyPress = docKeyPress);
                }

                if ($.browser.msie && options.borderWidth == 1 && options.borderOpacity < 1) {
                    $border1.add($border2).css('margin', '0');
                    setTimeout(function() { $border1.add($border2).css('margin', 'auto'); }, 0);
                }
            }

            function areaMouseMove(event) {
                if (!adjusted) {
                    adjust();
                    adjusted = true;

                    $box.one('mouseout', function() { adjusted = false; });
                }

                x = selX(evX(event)) - selection.x1;
                y = selY(evY(event)) - selection.y1;

                resize = [];

                if (options.resizable) {
                    if (y <= resizeMargin)
                        resize[V] = 'n';
                    else if (y >= selection.height - resizeMargin)
                        resize[V] = 's';
                    if (x <= resizeMargin)
                        resize[H] = 'w';
                    else if (x >= selection.width - resizeMargin)
                        resize[H] = 'e';
                }

                $box.css('cursor', resize.length ? resize.join('') + '-resize' :
            options.movable ? 'move' : '');
                if ($areaOpera)
                    $areaOpera.toggle();
            }

            function docMouseUp(event) {
                resize = [];

                $('body').css('cursor', '');

                if (options.autoHide || selection.width * selection.height == 0)
                    $box.add($o).hide();

                options.onSelectEnd(img, trueSelection());

                $(document).unbind('mousemove', selectingMouseMove);
                $box.mousemove(areaMouseMove);
            }

            function areaMouseDown(event) {
                if (event.which != 1) return false;

                adjust();

                if (options.resizable && resize.length > 0) {
                    $('body').css('cursor', resize.join('') + '-resize');

                    x1 = viewX(selection[resize[H] == 'w' ? 'x2' : 'x1']);
                    y1 = viewY(selection[resize[V] == 'n' ? 'y2' : 'y1']);

                    $(document).mousemove(selectingMouseMove)
                .one('mouseup', docMouseUp);
                    $box.unbind('mousemove', areaMouseMove);
                }
                else if (options.movable) {
                    startX = left + selection.x1 - evX(event);
                    startY = top + selection.y1 - evY(event);

                    $box.unbind('mousemove', areaMouseMove);

                    $(document).mousemove(movingMouseMove)
                .one('mouseup', function() {
                    options.onSelectEnd(img, trueSelection());

                    $(document).unbind('mousemove', movingMouseMove);
                    $box.mousemove(areaMouseMove);
                });
                }
                else
                    $img.mousedown(event);

                return false;
            }

            function aspectRatioXY() {
                x2 = M.max(left, M.min(left + imgWidth,
            x1 + M.abs(y2 - y1) * aspectRatio * (x2 < x1 ? -1 : 1)));
                y2 = M.round(M.max(top, M.min(top + imgHeight,
            y1 + M.abs(x2 - x1) / aspectRatio * (y2 < y1 ? -1 : 1))));
                x2 = M.round(x2);
            }

            function aspectRatioYX() {
                y2 = M.max(top, M.min(top + imgHeight,
            y1 + M.abs(x2 - x1) / aspectRatio * (y2 < y1 ? -1 : 1)));
                x2 = M.round(M.max(left, M.min(left + imgWidth,
            x1 + M.abs(y2 - y1) * aspectRatio * (x2 < x1 ? -1 : 1))));
                y2 = M.round(y2);
            }

            function doResize() {
                if (options.minWidth && M.abs(x2 - x1) < options.minWidth) {
                    x2 = x1 - options.minWidth * (x2 < x1 ? 1 : -1);

                    if (x2 < left)
                        x1 = left + options.minWidth;
                    else if (x2 > left + imgWidth)
                        x1 = left + imgWidth - options.minWidth;
                }

                if (options.minHeight && M.abs(y2 - y1) < options.minHeight) {
                    y2 = y1 - options.minHeight * (y2 < y1 ? 1 : -1);

                    if (y2 < top)
                        y1 = top + options.minHeight;
                    else if (y2 > top + imgHeight)
                        y1 = top + imgHeight - options.minHeight;
                }

                x2 = M.max(left, M.min(x2, left + imgWidth));
                y2 = M.max(top, M.min(y2, top + imgHeight));

                if (aspectRatio)
                    if (M.abs(x2 - x1) / aspectRatio > M.abs(y2 - y1))
                    aspectRatioYX();
                else
                    aspectRatioXY();

                if (options.maxWidth && M.abs(x2 - x1) > options.maxWidth) {
                    x2 = x1 - options.maxWidth * (x2 < x1 ? 1 : -1);
                    if (aspectRatio) aspectRatioYX();
                }

                if (options.maxHeight && M.abs(y2 - y1) > options.maxHeight) {
                    y2 = y1 - options.maxHeight * (y2 < y1 ? 1 : -1);
                    if (aspectRatio) aspectRatioXY();
                }

                selection = { x1: selX(M.min(x1, x2)), x2: selX(M.max(x1, x2)),
                    y1: selY(M.min(y1, y2)), y2: selY(M.max(y1, y2)),
                    width: M.abs(x2 - x1), height: M.abs(y2 - y1)
                };

                update();

                options.onSelectChange(img, trueSelection());
            }

            function selectingMouseMove(event) {
                x2 = !resize.length || resize[H] || aspectRatio ? evX(event) : viewX(selection.x2);
                y2 = !resize.length || resize[V] || aspectRatio ? evY(event) : viewY(selection.y2);

                doResize();

                return false;
            }

            function doMove(newX1, newY1) {
                x2 = (x1 = newX1) + selection.width;
                y2 = (y1 = newY1) + selection.height;

                selection = $.extend(selection, { x1: selX(x1), y1: selY(y1),
                    x2: selX(x2), y2: selY(y2)
                });

                update();

                options.onSelectChange(img, trueSelection());
            }

            function movingMouseMove(event) {
                x1 = M.max(left, M.min(startX + evX(event), left + imgWidth - selection.width));
                y1 = M.max(top, M.min(startY + evY(event), top + imgHeight - selection.height));

                doMove(x1, y1);

                event.preventDefault();
                return false;
            }

            function startSelection(event) {
                adjust();

                x2 = x1;
                y2 = y1;
                doResize();

                resize = [];

                $box.add($o.is(':visible') ? null : $o).show();
                shown = true;

                $(document).unbind('mouseup', cancelSelection)
            .mousemove(selectingMouseMove).one('mouseup', docMouseUp);
                $box.unbind('mousemove', areaMouseMove);

                options.onSelectStart(img, trueSelection());
            }

            function cancelSelection() {
                $(document).unbind('mousemove', startSelection);
                $box.add($o).hide();

                selection = { x1: 0, y1: 0, x2: 0, y2: 0, width: 0, height: 0 };

                options.onSelectChange(img, selection);
                options.onSelectEnd(img, selection);
            }

            function imgMouseDown(event) {
                if (event.which != 1) return false;

                adjust();
                startX = x1 = evX(event);
                startY = y1 = evY(event);

                $(document).one('mousemove', startSelection)
            .one('mouseup', cancelSelection);

                return false;
            }

            function parentScroll() {
                adjust();
                update(false);
                x1 = viewX(selection.x1); y1 = viewY(selection.y1);
                x2 = viewX(selection.x2); y2 = viewY(selection.y2);
            }

            function imgLoad() {
                imgLoaded = true;

                if (options.show) {
                    shown = true;
                    adjust();
                    update();
                    $box.add($o).show();
                }

                $box.add($o).css({ visibility: '' });
            }

            var docKeyPress = function(event) {
                var k = options.keys, d, t, key = event.keyCode || event.which;

                d = !isNaN(k.alt) && (event.altKey || event.originalEvent.altKey) ? k.alt :
            !isNaN(k.ctrl) && event.ctrlKey ? k.ctrl :
            !isNaN(k.shift) && event.shiftKey ? k.shift :
            !isNaN(k.arrows) ? k.arrows : 10;

                if (k.arrows == 'resize' || (k.shift == 'resize' && event.shiftKey) ||
            (k.ctrl == 'resize' && event.ctrlKey) ||
            (k.alt == 'resize' && (event.altKey || event.originalEvent.altKey))) {
                    switch (key) {
                        case 37:
                            d = -d;
                        case 39:
                            t = M.max(x1, x2);
                            x1 = M.min(x1, x2);
                            x2 = M.max(t + d, x1);
                            if (aspectRatio) aspectRatioYX();
                            break;
                        case 38:
                            d = -d;
                        case 40:
                            t = M.max(y1, y2);
                            y1 = M.min(y1, y2);
                            y2 = M.max(t + d, y1);
                            if (aspectRatio) aspectRatioXY();
                            break;
                        default:
                            return;
                    }

                    doResize();
                }
                else {
                    x1 = M.min(x1, x2);
                    y1 = M.min(y1, y2);

                    switch (key) {
                        case 37:
                            doMove(M.max(x1 - d, left), y1);
                            break;
                        case 38:
                            doMove(x1, M.max(y1 - d, top));
                            break;
                        case 39:
                            doMove(x1 + M.min(d, imgWidth - selX(x2)), y1);
                            break;
                        case 40:
                            doMove(x1, y1 + M.min(d, imgHeight - selY(y2)));
                            break;
                        default:
                            return;
                    }
                }

                return false;
            };

            this.setOptions = function(newOptions) {
                if (newOptions.parent)
                    ($parent = $(newOptions.parent)).append($box.add($o));

                adjust();
                getZIndex();

                if (newOptions.x1 != null) {
                    selection = { x1: newOptions.x1, y1: newOptions.y1,
                        x2: newOptions.x2, y2: newOptions.y2
                    };
                    newOptions.show = !newOptions.hide;

                    x1 = viewX(selection.x1); y1 = viewY(selection.y1);
                    x2 = viewX(selection.x2); y2 = viewY(selection.y2);
                    selection.width = x2 - x1;
                    selection.height = y2 - y1;
                }

                if (newOptions.handles != null) {
                    $handles.remove();
                    $handles = $(handles = []);

                    i = newOptions.handles ? newOptions.handles == 'corners' ? 4 : 8 : 0;

                    while (i--)
                        $handles = $handles.add(handles[i] = $('<div />'));

                    handleWidth = 4 + options.borderWidth;

                    $handles.css({ position: 'absolute', borderWidth: options.borderWidth + 'px',
                        borderStyle: 'solid', borderColor: options.borderColor1,
                        opacity: options.borderOpacity, backgroundColor: options.borderColor2,
                        width: handleWidth + 'px', height: handleWidth + 'px',
                        fontSize: '0px', zIndex: zIndex > 0 ? zIndex + 1 : '1'
                    })
                .addClass(options.classPrefix + '-handle');

                    handleWidth += options.borderWidth * 2;
                }

                update();

                options = $.extend(options, newOptions);

                if (options.imageWidth || options.imageHeight) {
                    scaleX = (parseInt(options.imageWidth) || imgWidth) / imgWidth;
                    scaleY = (parseInt(options.imageHeight) || imgHeight) / imgHeight;
                }

                if (newOptions.keys)
                    options.keys = $.extend({ shift: 1, ctrl: 'resize' },
                newOptions.keys === true ? {} : newOptions.keys);

                $o.addClass(options.classPrefix + '-outer');
                $area.addClass(options.classPrefix + '-selection');
                $border1.addClass(options.classPrefix + '-border1');
                $border2.addClass(options.classPrefix + '-border2');

                $box.add($area).add($border1).add($border2).css({ borderWidth: options.borderWidth + 'px' });
                $area.css({ backgroundColor: options.selectionColor, opacity: options.selectionOpacity });
                $border1.css({ borderStyle: 'solid', borderColor: options.borderColor1 });
                $border2.css({ borderStyle: 'dashed', borderColor: options.borderColor2 });
                $border1.add($border2).css({ opacity: options.borderOpacity });
                $o.css({ opacity: options.outerOpacity, backgroundColor: options.outerColor });

                $box.append($area.add($border1).add($border2).add($handles).add($areaOpera));

                if (newOptions.hide)
                    $box.add($o).hide();
                else if (newOptions.show && imgLoaded) {
                    shown = true;
                    update();
                    $box.add($o).show();
                }

                aspectRatio = options.aspectRatio && (d = options.aspectRatio.split(/:/)) ?
            d[0] / d[1] : null;

                if (aspectRatio)
                    if (options.minWidth)
                    options.minHeight = parseInt(options.minWidth / aspectRatio);
                else if (options.minHeight)
                    options.minWidth = parseInt(options.minHeight * aspectRatio);

                if (options.disable || options.enable === false) {
                    $box.unbind('mousemove', areaMouseMove).unbind('mousedown', areaMouseDown);
                    $img.add($o).unbind('mousedown', imgMouseDown);
                    $(window).unbind('resize', parentScroll);
                    $img.add($img.parents()).unbind('scroll', parentScroll);
                }
                else if (options.enable || options.disable === false) {
                    if (options.resizable || options.movable)
                        $box.mousemove(areaMouseMove).mousedown(areaMouseDown);

                    if (!options.persistent)
                        $img.add($o).mousedown(imgMouseDown);
                    $(window).resize(parentScroll);
                    $img.add($img.parents()).scroll(parentScroll);
                }

                options.enable = options.disable = undefined;
            };

            if ($.browser.msie)
                $img.attr('unselectable', 'on');

            $.imgAreaSelect.keyPress = $.browser.msie ||
        $.browser.safari ? 'keydown' : 'keypress';

            if ($.browser.opera)
                ($areaOpera = $('<div style="width: 100%; height: 100%; position: absolute;" />'))
            .css({ zIndex: zIndex > 0 ? zIndex + 2 : '2' });

            this.setOptions(options = $.extend({
                borderColor1: '#000',
                borderColor2: '#fff',
                borderWidth: 1,
                borderOpacity: .5,
                classPrefix: 'imgareaselect',
                movable: true,
                resizable: true,
                selectionColor: '#fff',
                selectionOpacity: 0,
                outerColor: '#000',
                outerOpacity: .4,
                parent: 'body',
                onSelectStart: function() { },
                onSelectChange: function() { },
                onSelectEnd: function() { }
            }, options));

            $box.add($o).css({ visibility: 'hidden', position: position,
                overflow: 'hidden', zIndex: zIndex > 0 ? zIndex : '0'
            });
            $area.css({ borderStyle: 'solid' });
            $box.css({ position: position, zIndex: zIndex > 0 ? zIndex + 2 : '2' });
            $area.add($border1).add($border2).css({ position: 'absolute' });

            img.complete || img.readyState == 'complete' || !$img.is('img') ?
        imgLoad() : $img.one('load', imgLoad);
        };

        $.fn.imgAreaSelect = function(options) {
            options = options || {};

            this.each(function() {
                if ($(this).data('imgAreaSelect'))
                    $(this).data('imgAreaSelect').setOptions(options);
                else {
                    if (options.enable === undefined && options.disable === undefined)
                        options.enable = true;

                    $(this).data('imgAreaSelect', new $.imgAreaSelect.init(this, options));
                }
            });

            return this;
        };

    })(jQuery);

    /**
    * jQuery lightBox plugin
    * This jQuery plugin was inspired and based on Lightbox 2 by Lokesh Dhakar (http://www.huddletogether.com/projects/lightbox2/)
    * and adapted to me for use like a plugin from jQuery.
    * @name jquery-lightbox-0.5.js
    * @author Leandro Vieira Pinho - http://leandrovieira.com
    * @version 0.5
    * @date April 11, 2008
    * @category jQuery plugin
    * @copyright (c) 2008 Leandro Vieira Pinho (leandrovieira.com)
    * @license CC Attribution-No Derivative Works 2.5 Brazil - http://creativecommons.org/licenses/by-nd/2.5/br/deed.en_US
    * @example Visit http://leandrovieira.com/projects/jquery/lightbox/ for more informations about this jQuery plugin



    document.getElementById('divRight').clientHeight
    */
    (function($) {
        $.fn.lightBox = function(settings) {
            settings = jQuery.extend({ overlayBgColor: '#000', overlayOpacity: 0.8, fixedNavigation: false, imageLoading: 'images/lightbox-ico-loading.gif', imageBtnPrev: 'images/lightbox-btn-prev.gif', imageBtnNext: 'images/lightbox-btn-next.gif', imageBtnClose: 'images/lightbox-btn-close.gif', imageBlank: 'images/lightbox-blank.gif', containerBorderSize: 10, containerResizeSpeed: 400, txtImage: 'Image', txtOf: 'of', keyToClose: 'c', keyToPrev: 'p', keyToNext: 'n', imageArray: [], activeImage: 0 }, settings); var jQueryMatchedObj = this; function _initialize() { _start(this, jQueryMatchedObj); return false; }
            function _start(objClicked, jQueryMatchedObj) {
                $('embed, object, select').css({ 'visibility': 'hidden' }); _set_interface(); settings.imageArray.length = 0; settings.activeImage = 0; if (jQueryMatchedObj.length == 1) { settings.imageArray.push(new Array(objClicked.getAttribute('href'), objClicked.getAttribute('title'))); } else { for (var i = 0; i < jQueryMatchedObj.length; i++) { settings.imageArray.push(new Array(jQueryMatchedObj[i].getAttribute('href'), jQueryMatchedObj[i].getAttribute('title'))); } }
                while (settings.imageArray[settings.activeImage][0] != objClicked.getAttribute('href')) { settings.activeImage++; }
                _set_image_to_view();
            }
            function _set_interface() {
                $('body').append('<div id="jquery-overlay"></div><div id="jquery-lightbox"><div id="lightbox-container-image-box"><div id="lightbox-container-image"><img id="lightbox-image"><div style="" id="lightbox-nav"><a href="#" id="lightbox-nav-btnPrev"></a><a href="#" id="lightbox-nav-btnNext"></a></div><div id="lightbox-loading"><a href="#" id="lightbox-loading-link"><img src="' + settings.imageLoading + '"></a></div></div></div><div id="lightbox-container-image-data-box"><div id="lightbox-container-image-data"><div id="lightbox-image-details"><span id="lightbox-image-details-caption"></span><span id="lightbox-image-details-currentNumber"></span></div><div id="lightbox-secNav"><a href="#" id="lightbox-secNav-btnClose"><img src="' + settings.imageBtnClose + '"></a></div></div></div></div>'); var arrPageSizes = ___getPageSize(); $('#jquery-overlay').css({ backgroundColor: settings.overlayBgColor, opacity: settings.overlayOpacity, width: arrPageSizes[0], height: arrPageSizes[1] }).fadeIn(); var arrPageScroll = ___getPageScroll(); $('#jquery-lightbox').css({ top: arrPageScroll[1] + (arrPageSizes[3] / 10), left: arrPageScroll[0] }).show(); $('#jquery-overlay,#jquery-lightbox').click(function() { _finish(); }); $('#lightbox-loading-link,#lightbox-secNav-btnClose').click(function() { _finish(); return false; }); $(window).resize(function() {
                    var arrPageSizes = ___getPageSize();
                    //alterado para funcionar totalHeight no IE
                    if (arrPageSizes[1] < document.getElementById('divRight').clientHeight) { arrPageSizes[1] = document.getElementById('divRight').clientHeight }
                    $('#jquery-overlay').css({ width: arrPageSizes[0], height: arrPageSizes[1] }); var arrPageScroll = ___getPageScroll(); $('#jquery-lightbox').css({ top: arrPageScroll[1] + (arrPageSizes[3] / 10), left: arrPageScroll[0] });
                });
            }
            function _set_image_to_view() {
                $('#lightbox-loading').show(); if (settings.fixedNavigation) { $('#lightbox-image,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide(); } else { $('#lightbox-image,#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide(); }
                var objImagePreloader = new Image(); objImagePreloader.onload = function() { $('#lightbox-image').attr('src', settings.imageArray[settings.activeImage][0]); _resize_container_image_box(objImagePreloader.width, objImagePreloader.height); objImagePreloader.onload = function() { }; }; objImagePreloader.src = settings.imageArray[settings.activeImage][0];
            }; function _resize_container_image_box(intImageWidth, intImageHeight) {
                var intCurrentWidth = $('#lightbox-container-image-box').width(); var intCurrentHeight = $('#lightbox-container-image-box').height(); var intWidth = (intImageWidth + (settings.containerBorderSize * 2)); var intHeight = (intImageHeight + (settings.containerBorderSize * 2)); var intDiffW = intCurrentWidth - intWidth; var intDiffH = intCurrentHeight - intHeight; $('#lightbox-container-image-box').animate({ width: intWidth, height: intHeight }, settings.containerResizeSpeed, function() { _show_image(); }); if ((intDiffW == 0) && (intDiffH == 0)) { if ($.browser.msie) { ___pause(250); } else { ___pause(100); } }
                $('#lightbox-container-image-data-box').css({ width: intImageWidth }); $('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({ height: intImageHeight + (settings.containerBorderSize * 2) });
            }; function _show_image() { $('#lightbox-loading').hide(); $('#lightbox-image').fadeIn(function() { _show_image_data(); _set_navigation(); }); _preload_neighbor_images(); }; function _show_image_data() {
                $('#lightbox-container-image-data-box').slideDown('fast'); $('#lightbox-image-details-caption').hide(); if (settings.imageArray[settings.activeImage][1]) { $('#lightbox-image-details-caption').html(settings.imageArray[settings.activeImage][1]).show(); }
                if (settings.imageArray.length > 1) { $('#lightbox-image-details-currentNumber').html(settings.txtImage + ' ' + (settings.activeImage + 1) + ' ' + settings.txtOf + ' ' + settings.imageArray.length).show(); }
            }
            function _set_navigation() {
                $('#lightbox-nav').show(); $('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({ 'background': 'transparent url(' + settings.imageBlank + ') no-repeat' }); if (settings.activeImage != 0) { if (settings.fixedNavigation) { $('#lightbox-nav-btnPrev').css({ 'background': 'url(' + settings.imageBtnPrev + ') left 15% no-repeat' }).unbind().bind('click', function() { settings.activeImage = settings.activeImage - 1; _set_image_to_view(); return false; }); } else { $('#lightbox-nav-btnPrev').unbind().hover(function() { $(this).css({ 'background': 'url(' + settings.imageBtnPrev + ') left 15% no-repeat' }); }, function() { $(this).css({ 'background': 'transparent url(' + settings.imageBlank + ') no-repeat' }); }).show().bind('click', function() { settings.activeImage = settings.activeImage - 1; _set_image_to_view(); return false; }); } }
                if (settings.activeImage != (settings.imageArray.length - 1)) { if (settings.fixedNavigation) { $('#lightbox-nav-btnNext').css({ 'background': 'url(' + settings.imageBtnNext + ') right 15% no-repeat' }).unbind().bind('click', function() { settings.activeImage = settings.activeImage + 1; _set_image_to_view(); return false; }); } else { $('#lightbox-nav-btnNext').unbind().hover(function() { $(this).css({ 'background': 'url(' + settings.imageBtnNext + ') right 15% no-repeat' }); }, function() { $(this).css({ 'background': 'transparent url(' + settings.imageBlank + ') no-repeat' }); }).show().bind('click', function() { settings.activeImage = settings.activeImage + 1; _set_image_to_view(); return false; }); } }
                _enable_keyboard_navigation();
            }
            function _enable_keyboard_navigation() { $(document).keydown(function(objEvent) { _keyboard_action(objEvent); }); }
            function _disable_keyboard_navigation() { $(document).unbind(); }
            function _keyboard_action(objEvent) {
                if (objEvent == null) { keycode = event.keyCode; escapeKey = 27; } else { keycode = objEvent.keyCode; escapeKey = objEvent.DOM_VK_ESCAPE; }
                key = String.fromCharCode(keycode).toLowerCase(); if ((key == settings.keyToClose) || (key == 'x') || (keycode == escapeKey)) { _finish(); }
                if ((key == settings.keyToPrev) || (keycode == 37)) { if (settings.activeImage != 0) { settings.activeImage = settings.activeImage - 1; _set_image_to_view(); _disable_keyboard_navigation(); } }
                if ((key == settings.keyToNext) || (keycode == 39)) { if (settings.activeImage != (settings.imageArray.length - 1)) { settings.activeImage = settings.activeImage + 1; _set_image_to_view(); _disable_keyboard_navigation(); } }
            }
            function _preload_neighbor_images() {
                if ((settings.imageArray.length - 1) > settings.activeImage) { objNext = new Image(); objNext.src = settings.imageArray[settings.activeImage + 1][0]; }
                if (settings.activeImage > 0) { objPrev = new Image(); objPrev.src = settings.imageArray[settings.activeImage - 1][0]; }
            }
            function _finish() { $('#jquery-lightbox').remove(); $('#jquery-overlay').fadeOut(function() { $('#jquery-overlay').remove(); }); $('embed, object, select').css({ 'visibility': 'visible' }); }
            function ___getPageSize() {
                var xScroll, yScroll; if (window.innerHeight && window.scrollMaxY) { xScroll = window.innerWidth + window.scrollMaxX; yScroll = window.innerHeight + window.scrollMaxY; } else if (document.body.scrollHeight > document.body.offsetHeight) { xScroll = document.body.scrollWidth; yScroll = document.body.scrollHeight; } else { xScroll = document.body.offsetWidth; yScroll = document.body.offsetHeight; }
                var windowWidth, windowHeight; if (self.innerHeight) {
                    if (document.documentElement.clientWidth) { windowWidth = document.documentElement.clientWidth; } else { windowWidth = self.innerWidth; }
                    windowHeight = self.innerHeight;
                } else if (document.documentElement && document.documentElement.clientHeight) { windowWidth = document.documentElement.clientWidth; windowHeight = document.documentElement.clientHeight; } else if (document.body) { windowWidth = document.body.clientWidth; windowHeight = document.body.clientHeight; }
                if (yScroll < windowHeight) { pageHeight = windowHeight; } else { pageHeight = yScroll; }
                if (xScroll < windowWidth) { pageWidth = xScroll; } else { pageWidth = windowWidth; }
                arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight); return arrayPageSize;


            }; function ___getPageScroll() {
                var xScroll, yScroll; if (self.pageYOffset) { yScroll = self.pageYOffset; xScroll = self.pageXOffset; } else if (document.documentElement && document.documentElement.scrollTop) { yScroll = document.documentElement.scrollTop; xScroll = document.documentElement.scrollLeft; } else if (document.body) { yScroll = document.body.scrollTop; xScroll = document.body.scrollLeft; }
                arrayPageScroll = new Array(xScroll, yScroll); return arrayPageScroll;
            }; function ___pause(ms) {
                var date = new Date(); curDate = null; do { var curDate = new Date(); }
                while (curDate - date < ms);
            }; return this.unbind('click').click(_initialize);
        };
    })(jQuery);

    /*
    * Thickbox 3.1 - One Box To Rule Them All.
    * By Cody Lindley (http://www.codylindley.com)
    * Copyright (c) 2007 cody lindley
    * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
    */

    var tb_pathToImage = "images/loadingAnimation.gif";

    /*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/

    //on page load call tb_init
    $(document).ready(function() {
        tb_init('a.thickbox, area.thickbox, input.thickbox'); //pass where to apply thickbox
        imgLoader = new Image(); // preload image
        imgLoader.src = tb_pathToImage;
    });

    //add thickbox to href & area elements that have a class of .thickbox
    function tb_init(domChunk) {
        $(domChunk).click(function() {
            var t = this.title || this.name || null;
            var a = this.href || this.alt;
            var g = this.rel || false;
            tb_show(t, a, g);
            this.blur();
            return false;
        });
    }

    function tb_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link

        try {
            if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
                $("body", "html").css({ height: "100%", width: "100%" });
                $("html").css("overflow", "hidden");
                if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
                    $("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
                    $("#TB_overlay").click(tb_remove);
                }
            } else {//all others
                if (document.getElementById("TB_overlay") === null) {
                    $("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
                    $("#TB_overlay").click(tb_remove);
                }
            }

            if (tb_detectMacXFF()) {
                $("#TB_overlay").addClass("TB_overlayMacFFBGHack"); //use png overlay so hide flash
            } else {
                $("#TB_overlay").addClass("TB_overlayBG"); //use background and opacity
            }

            if (caption === null) { caption = ""; }
            $("body").append("<div id='TB_load'><img src='" + imgLoader.src + "' /></div>"); //add loader to the page
            $('#TB_load').show(); //show loader

            var baseURL;
            if (url.indexOf("?") !== -1) { //ff there is a query string involved
                baseURL = url.substr(0, url.indexOf("?"));
            } else {
                baseURL = url;
            }

            var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
            var urlType = baseURL.toLowerCase().match(urlString);

            if (urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp') {//code to show images

                TB_PrevCaption = "";
                TB_PrevURL = "";
                TB_PrevHTML = "";
                TB_NextCaption = "";
                TB_NextURL = "";
                TB_NextHTML = "";
                TB_imageCount = "";
                TB_FoundURL = false;
                if (imageGroup) {
                    TB_TempArray = $("a[@rel=" + imageGroup + "]").get();
                    for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === "")); TB_Counter++) {
                        var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString);
                        if (!(TB_TempArray[TB_Counter].href == url)) {
                            if (TB_FoundURL) {
                                TB_NextCaption = TB_TempArray[TB_Counter].title;
                                TB_NextURL = TB_TempArray[TB_Counter].href;
                                TB_NextHTML = "<span id='TB_next'>&nbsp;&nbsp;<a href='#'>Next &gt;</a></span>";
                            } else {
                                TB_PrevCaption = TB_TempArray[TB_Counter].title;
                                TB_PrevURL = TB_TempArray[TB_Counter].href;
                                TB_PrevHTML = "<span id='TB_prev'>&nbsp;&nbsp;<a href='#'>&lt; Prev</a></span>";
                            }
                        } else {
                            TB_FoundURL = true;
                            TB_imageCount = "Image " + (TB_Counter + 1) + " of " + (TB_TempArray.length);
                        }
                    }
                }

                imgPreloader = new Image();
                imgPreloader.onload = function() {
                    imgPreloader.onload = null;

                    // Resizing large images - orginal by Christian Montoya edited by me.
                    var pagesize = tb_getPageSize();
                    var x = pagesize[0] - 150;
                    var y = pagesize[1] - 150;
                    var imageWidth = imgPreloader.width;
                    var imageHeight = imgPreloader.height;
                    if (imageWidth > x) {
                        imageHeight = imageHeight * (x / imageWidth);
                        imageWidth = x;
                        if (imageHeight > y) {
                            imageWidth = imageWidth * (y / imageHeight);
                            imageHeight = y;
                        }
                    } else if (imageHeight > y) {
                        imageWidth = imageWidth * (y / imageHeight);
                        imageHeight = y;
                        if (imageWidth > x) {
                            imageHeight = imageHeight * (x / imageWidth);
                            imageWidth = x;
                        }
                    }
                    // End Resizing

                    TB_WIDTH = imageWidth + 30;
                    TB_HEIGHT = imageHeight + 60;
                    $("#TB_window").append("<a href='' id='TB_ImageOff' title='Close'><img id='TB_Image' src='" + url + "' width='" + imageWidth + "' height='" + imageHeight + "' alt='" + caption + "'/></a>" + "<div id='TB_caption'>" + caption + "<div id='TB_secondLine'>" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "</div></div><div id='TB_closeWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a> or Esc Key</div>");

                    $("#TB_closeWindowButton").click(tb_remove);

                    if (!(TB_PrevHTML === "")) {
                        function goPrev() {
                            if ($(document).unbind("click", goPrev)) { $(document).unbind("click", goPrev); }
                            $("#TB_window").remove();
                            $("body").append("<div id='TB_window'></div>");
                            tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
                            return false;
                        }
                        $("#TB_prev").click(goPrev);
                    }

                    if (!(TB_NextHTML === "")) {
                        function goNext() {
                            $("#TB_window").remove();
                            $("body").append("<div id='TB_window'></div>");
                            tb_show(TB_NextCaption, TB_NextURL, imageGroup);
                            return false;
                        }
                        $("#TB_next").click(goNext);

                    }

                    document.onkeydown = function(e) {
                        if (e == null) { // ie
                            keycode = event.keyCode;
                        } else { // mozilla
                            keycode = e.which;
                        }
                        if (keycode == 27) { // close
                            tb_remove();
                        } else if (keycode == 190) { // display previous image
                            if (!(TB_NextHTML == "")) {
                                document.onkeydown = "";
                                goNext();
                            }
                        } else if (keycode == 188) { // display next image
                            if (!(TB_PrevHTML == "")) {
                                document.onkeydown = "";
                                goPrev();
                            }
                        }
                    };

                    tb_position();
                    $("#TB_load").remove();
                    $("#TB_ImageOff").click(tb_remove);
                    $("#TB_window").css({ display: "block" }); //for safari using css instead of show
                };

                imgPreloader.src = url;
            } else {//code to show html

                var queryString = url.replace(/^[^\?]+\??/, '');
                var params = tb_parseQuery(queryString);

                TB_WIDTH = (params['width'] * 1) + 30 || 630; //defaults to 630 if no paramaters were added to URL
                TB_HEIGHT = (params['height'] * 1) + 40 || 440; //defaults to 440 if no paramaters were added to URL
                ajaxContentW = TB_WIDTH - 30;
                ajaxContentH = TB_HEIGHT - 45;

                if (url.indexOf('TB_iframe') != -1) {// either iframe or ajax window		
                    urlNoQuery = url.split('TB_');
                    $("#TB_iframeContent").remove();
                    if (params['modal'] != "true") {//iframe no modal
                        $("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>" + caption + "</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a> or Esc Key</div></div><iframe frameborder='0' hspace='0' src='" + urlNoQuery[0] + "' id='TB_iframeContent' name='TB_iframeContent" + Math.round(Math.random() * 1000) + "' onload='tb_showIframe()' style='width:" + (ajaxContentW + 29) + "px;height:" + (ajaxContentH + 17) + "px;' > </iframe>");
                    } else {//iframe modal
                        $("#TB_overlay").unbind();
                        $("#TB_window").append("<iframe frameborder='0' hspace='0' src='" + urlNoQuery[0] + "' id='TB_iframeContent' name='TB_iframeContent" + Math.round(Math.random() * 1000) + "' onload='tb_showIframe()' style='width:" + (ajaxContentW + 29) + "px;height:" + (ajaxContentH + 17) + "px;'> </iframe>");
                    }
                } else {// not an iframe, ajax
                    if ($("#TB_window").css("display") != "block") {
                        if (params['modal'] != "true") {//ajax no modal
                            $("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>" + caption + "</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'>close</a> or Esc Key</div></div><div id='TB_ajaxContent' style='width:" + ajaxContentW + "px;height:" + ajaxContentH + "px'></div>");
                        } else {//ajax modal
                            $("#TB_overlay").unbind();
                            $("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:" + ajaxContentW + "px;height:" + ajaxContentH + "px;'></div>");
                        }
                    } else {//this means the window is already up, we are just loading new content via ajax
                        $("#TB_ajaxContent")[0].style.width = ajaxContentW + "px";
                        $("#TB_ajaxContent")[0].style.height = ajaxContentH + "px";
                        $("#TB_ajaxContent")[0].scrollTop = 0;
                        $("#TB_ajaxWindowTitle").html(caption);
                    }
                }

                $("#TB_closeWindowButton").click(tb_remove);

                if (url.indexOf('TB_inline') != -1) {
                    $("#TB_ajaxContent").append($('#' + params['inlineId']).children());
                    $("#TB_window").unload(function() {
                        $('#' + params['inlineId']).append($("#TB_ajaxContent").children()); // move elements back when you're finished
                    });
                    tb_position();
                    $("#TB_load").remove();
                    $("#TB_window").css({ display: "block" });
                } else if (url.indexOf('TB_iframe') != -1) {
                    tb_position();
                    if ($.browser.safari) {//safari needs help because it will not fire iframe onload
                        $("#TB_load").remove();
                        $("#TB_window").css({ display: "block" });
                    }
                } else {
                    $("#TB_ajaxContent").load(url += "&random=" + (new Date().getTime()), function() {//to do a post change this load method
                        tb_position();
                        $("#TB_load").remove();
                        tb_init("#TB_ajaxContent a.thickbox");
                        $("#TB_window").css({ display: "block" });
                    });
                }

            }

            if (!params['modal']) {
                document.onkeyup = function(e) {
                    if (e == null) { // ie
                        keycode = event.keyCode;
                    } else { // mozilla
                        keycode = e.which;
                    }
                    if (keycode == 27) { // close
                        tb_remove();
                    }
                };
            }

        } catch (e) {
            //nothing here
        }
    }

    //helper functions below
    function tb_showIframe() {
        $("#TB_load").remove();
        $("#TB_window").css({ display: "block" });
    }

    function tb_remove() {
        $("#TB_imageOff").unbind("click");
        $("#TB_closeWindowButton").unbind("click");
        $("#TB_window").fadeOut("fast", function() { $('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove(); });
        $("#TB_load").remove();
        if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
            $("body", "html").css({ height: "auto", width: "auto" });
            $("html").css("overflow", "");
        }
        document.onkeydown = "";
        document.onkeyup = "";
        return false;
    }

    function tb_position() {
        $("#TB_window").css({ marginLeft: '-' + parseInt((TB_WIDTH / 2), 10) + 'px', width: TB_WIDTH + 'px' });
        if (!(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
            $("#TB_window").css({ marginTop: '-' + parseInt((TB_HEIGHT / 2), 10) + 'px' });
        }
    }

    function tb_parseQuery(query) {
        var Params = {};
        if (!query) { return Params; } // return empty object
        var Pairs = query.split(/[;&]/);
        for (var i = 0; i < Pairs.length; i++) {
            var KeyVal = Pairs[i].split('=');
            if (!KeyVal || KeyVal.length != 2) { continue; }
            var key = unescape(KeyVal[0]);
            var val = unescape(KeyVal[1]);
            val = val.replace(/\+/g, ' ');
            Params[key] = val;
        }
        return Params;
    }

    function tb_getPageSize() {
        var de = document.documentElement;
        var w = window.innerWidth || self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
        var h = window.innerHeight || self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;
        arrayPageSize = [w, h];
        return arrayPageSize;
    }

    function tb_detectMacXFF() {
        var userAgent = navigator.userAgent.toLowerCase();
        if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox') != -1) {
            return true;
        }
    }


