/**
 * AJAX Upload ( http://valums.com/ajax-upload/ ) 
 * Copyright (c) Andris Valums
 * Licensed under the MIT license ( http://valums.com/mit-license/ )
 * Thanks to Gary Haran, David Mark, Corey Burns and others for contributions. 
 */
(function () {
    /* global window */
    /* jslint browser: true, devel: true, undef: true, nomen: true, bitwise: true, regexp: true, newcap: true, immed: true */
    
    /**
     * Wrapper for FireBug's console.log
     */
    function log(){
        if (typeof(console) != 'undefined' && typeof(console.log) == 'function'){            
            Array.prototype.unshift.call(arguments, '[Ajax Upload]');
            console.log( Array.prototype.join.call(arguments, ' '));
        }
    } 

    /**
     * Attaches event to a dom element.
     * @param {Element} el
     * @param type event name
     * @param fn callback This refers to the passed element
     */
    function addEvent(el, type, fn){
        if (el.addEventListener) {
            el.addEventListener(type, fn, false);
        } else if (el.attachEvent) {
            el.attachEvent('on' + type, function(){
                fn.call(el);
	        });
	    } else {
            throw new Error('not supported or DOM not loaded');
        }
    }   
    
    /**
     * Attaches resize event to a window, limiting
     * number of event fired. Fires only when encounteres
     * delay of 100 after series of events.
     * 
     * Some browsers fire event multiple times when resizing
     * http://www.quirksmode.org/dom/events/resize.html
     * 
     * @param fn callback This refers to the passed element
     */
    function addResizeEvent(fn){
        var timeout;
               
	    addEvent(window, 'resize', function(){
            if (timeout){
                clearTimeout(timeout);
            }
            timeout = setTimeout(fn, 100);                        
        });
    }    
    
    // Needs more testing, will be rewriten for next version        
    // 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();
            var doc = el.ownerDocument;
            var body = doc.body;
            var docElem = doc.documentElement; // for ie 
            var clientTop = docElem.clientTop || body.clientTop || 0;
            var 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.	
            var 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){
            var top = 0, left = 0;
            do {
                top += el.offsetTop || 0;
                left += el.offsetLeft || 0;
                el = el.offsetParent;
            } while (el);
            
            return {
                left: left,
                top: top
            };
        };
    }
    
    /**
     * Returns left, top, right and bottom properties describing the border-box,
     * in pixels, with the top-left relative to the body
     * @param {Element} el
     * @return {Object} Contains left, top, right,bottom
     */
    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
        };
    }
    
    /**
     * Helper that takes object literal
     * and add all properties to element.style
     * @param {Element} el
     * @param {Object} styles
     */
    function addStyles(el, styles){
        for (var name in styles) {
            if (styles.hasOwnProperty(name)) {
                el.style[name] = styles[name];
            }
        }
    }
        
    /**
     * Function places an absolutely positioned
     * element on top of the specified element
     * copying position and dimentions.
     * @param {Element} from
     * @param {Element} to
     */    
    function copyLayout(from, to){
	    var box = getBox(from);
        
        addStyles(to, {
	        position: 'absolute',                    
	        left : box.left + 'px',
	        top : box.top + 'px',
	        width : from.offsetWidth + 'px',
	        height : from.offsetHeight + 'px'
	    });        
    }

    /**
    * Creates and returns element from html chunk
    * Uses innerHTML to create an element
    */
    var toElement = (function(){
        var div = document.createElement('div');
        return function(html){
            div.innerHTML = html;
            var el = div.firstChild;
            return div.removeChild(el);
        };
    })();
            
    /**
     * Function generates unique id
     * @return unique id 
     */
    var getUID = (function(){
        var id = 0;
        return function(){
            return 'ValumsAjaxUpload' + id++;
        };
    })();        
 
    /**
     * Get file name from path
     * @param {String} file path to file
     * @return filename
     */  
    function fileFromPath(file){
        return file.replace(/.*(\/|\\)/, "");
    }
    
    /**
     * Get file extension lowercase
     * @param {String} file name
     * @return file extenstion
     */    
    function getExt(file){
        return (-1 !== file.indexOf('.')) ? file.replace(/.*[.]/, '') : '';
    }

    function hasClass(el, name){        
        var re = new RegExp('\\b' + name + '\\b');        
        return re.test(el.className);
    }    
    function addClass(el, name){
        if ( ! hasClass(el, name)){   
            el.className += ' ' + name;
        }
    }    
    function removeClass(el, name){
        var re = new RegExp('\\b' + name + '\\b');                
        el.className = el.className.replace(re, '');        
    }
    
    function removeNode(el){
        el.parentNode.removeChild(el);
    }

    /**
     * Easy styling and uploading
     * @constructor
     * @param button An element you want convert to 
     * upload button. Tested dimentions up to 500x500px
     * @param {Object} options See defaults below.
     */
    window.AjaxUpload = function(button, options){
        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,
            // Class applied to button when mouse is hovered
            hoverClass: 'hover',
            // Class applied to button when button is focused
            focusClass: 'focus',
            // Class applied to button when AU is disabled
            disabledClass: 'disabled',            
            // When user selects a file, useful with autoSubmit disabled
            // You can return false to cancel upload			
            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) {
            if (options.hasOwnProperty(i)){
                this._settings[i] = options[i];
            }
        }
                
        // button isn't necessary a dom element
        if (button.jquery){
            // jQuery object was passed
            button = button[0];
        } else if (typeof button == "string") {
            if (/^#.*/.test(button)){
                // If jQuery user passes #elementId don't break it					
                button = button.slice(1);                
            }
            
            button = document.getElementById(button);
        }
        
        if ( ! button || button.nodeType !== 1){
            throw new Error("Please make sure that you're passing a valid element"); 
        }
                
        if ( button.nodeName.toUpperCase() == 'A'){
            // disable link                       
            addEvent(button, 'click', function(e){
                if (e && e.preventDefault){
                    e.preventDefault();
                } else if (window.event){
                    window.event.returnValue = false;
                }
            });
        }
                    
        // DOM element
        this._button = button;        
        // DOM element                 
        this._input = null;
        // If disabled clicking on button won't do anything
        this._disabled = false;
        
        // if the button was disabled before refresh if will remain
        // disabled in FireFox, let's fix it
        this.enable();        
        
        this._rerouteClicks();
    };
    
    // assigning methods to our class
    AjaxUpload.prototype = {
        setData: function(data){
            this._settings.data = data;
        },
        disable: function(){            
            addClass(this._button, this._settings.disabledClass);
            this._disabled = true;
            
            var nodeName = this._button.nodeName.toUpperCase();            
            if (nodeName == 'INPUT' || nodeName == 'BUTTON'){
                this._button.setAttribute('disabled', 'disabled');
            }            
            
            // hide input
            if (this._input){
                // We use visibility instead of display to fix problem with Safari 4
                // The problem is that the value of input doesn't change if it 
                // has display none when user selects a file           
                this._input.parentNode.style.visibility = 'hidden';
            }
        },
        enable: function(){
            removeClass(this._button, this._settings.disabledClass);
            this._button.removeAttribute('disabled');
            this._disabled = false;
            
        },
        /**
         * Creates invisible file input 
         * that will hover above the button
         * <div><input type='file' /></div>
         */
        _createInput: function(){ 
            var self = this;
                        
            var input = document.createElement("input");
            input.setAttribute('type', 'file');
            input.setAttribute('name', this._settings.name);
            
            addStyles(input, {
                'position' : 'absolute',
                // in Opera only 'browse' button
                // is clickable and it is located at
                // the right side of the input
                'right' : 0,
                'margin' : 0,
                'padding' : 0,
                'fontSize' : '480px',
                // in Firefox if font-family is set to
                // 'inherit' the input doesn't work
                'fontFamily' : 'sans-serif',
                'cursor' : 'pointer'
            });            

            var div = document.createElement("div");                        
            addStyles(div, {
                'display' : 'block',
                'position' : 'absolute',
                'overflow' : 'hidden',
                'margin' : 0,
                'padding' : 0,                
                'opacity' : 0,
                // Make sure browse button is in the right side
                // in Internet Explorer
                'direction' : 'ltr',
                //Max zIndex supported by Opera 9.0-9.2
                'zIndex': 2147483583
            });
            
            // Make sure that element opacity exists.
            // Otherwise use IE filter            
            if ( div.style.opacity !== "0") {
                if (typeof(div.filters) == 'undefined'){
                    throw new Error('Opacity not supported by the browser');
                }
                div.style.filter = "alpha(opacity=0)";
            }            
            
            addEvent(input, 'change', function(){
                 
                if ( ! input || input.value === ''){                
                    return;                
                }
                            
                // Get filename from input, required                
                // as some browsers have path instead of it          
                var file = fileFromPath(input.value);
                                
                if (false === self._settings.onChange.call(self, file, getExt(file))){
                    self._clearInput();                
                    return;
                }
                
                // Submit form when value is changed
                if (self._settings.autoSubmit) {
                    self.submit();
                }
            });            

            addEvent(input, 'mouseover', function(){
                addClass(self._button, self._settings.hoverClass);
            });
            
            addEvent(input, 'mouseout', function(){
                removeClass(self._button, self._settings.hoverClass);
                removeClass(self._button, self._settings.focusClass);
                
                // We use visibility instead of display to fix problem with Safari 4
                // The problem is that the value of input doesn't change if it 
                // has display none when user selects a file           
                input.parentNode.style.visibility = 'hidden';

            });   
                        
            addEvent(input, 'focus', function(){
                addClass(self._button, self._settings.focusClass);
            });
            
            addEvent(input, 'blur', function(){
                removeClass(self._button, self._settings.focusClass);
            });
            
	        div.appendChild(input);
            document.body.appendChild(div);
              
            this._input = input;
        },
        _clearInput : function(){
            if (!this._input){
                return;
            }            
                             
            // this._input.value = ''; Doesn't work in IE6                               
            removeNode(this._input.parentNode);
            this._input = null;                                                                   
            this._createInput();
            
            removeClass(this._button, this._settings.hoverClass);
            removeClass(this._button, this._settings.focusClass);
        },
        /**
         * Function makes sure that when user clicks upload button,
         * the this._input is clicked instead
         */
        _rerouteClicks: function(){
            var self = this;
            
            // IE will later display 'access denied' error
            // if you use using self._input.click()
            // other browsers just ignore click()

            addEvent(self._button, 'mouseover', function(){
                if (self._disabled){
                    return;
                }
                                
                if ( ! self._input){
	                self._createInput();
                }
                
                var div = self._input.parentNode;                            
                copyLayout(self._button, div);
                div.style.visibility = 'visible';
                                
            });
            
            
            // commented because we now hide input on mouseleave
            /**
             * When the window is resized the elements 
             * can be misaligned if button position depends
             * on window size
             */
            //addResizeEvent(function(){
            //    if (self._input){
            //        copyLayout(self._button, self._input.parentNode);
            //    }
            //});            
                                         
        },
        /**
         * Creates iframe with unique name
         * @return {Element} iframe
         */
        _createIframe: function(){
            // We can't use getTime, because it sometimes return
            // same value in safari :(
            var id = getUID();            
             
            // We can't use following code as the name attribute
            // won't be properly registered in IE6, and new window
            // on form submit will open
            // var iframe = document.createElement('iframe');
            // iframe.setAttribute('name', id);                        
 
            var iframe = toElement('<iframe src="javascript:false;" name="' + id + '" />');
            // src="javascript:false; was added
            // because it possibly removes ie6 prompt 
            // "This page contains both secure and nonsecure items"
            // Anyway, it doesn't do any harm.            
            iframe.setAttribute('id', id);
            
            iframe.style.display = 'none';
            document.body.appendChild(iframe);
            
            return iframe;
        },
        /**
         * Creates form, that will be submitted to iframe
         * @param {Element} iframe Where to submit
         * @return {Element} form
         */
        _createForm: function(iframe){
            var settings = this._settings;
                        
            // We can't use the following code in IE6
            // var form = document.createElement('form');
            // form.setAttribute('method', 'post');
            // form.setAttribute('enctype', 'multipart/form-data');
            // Because in this case file won't be attached to request                    
            var form = toElement('<form method="post" enctype="multipart/form-data"></form>');
                        
            form.setAttribute('action', settings.action);
            form.setAttribute('target', iframe.name);                                   
            form.style.display = 'none';
            document.body.appendChild(form);
            
            // Create hidden input element for each data key
            for (var prop in settings.data) {
                if (settings.data.hasOwnProperty(prop)){
                    var el = document.createElement("input");
                    el.setAttribute('type', 'hidden');
                    el.setAttribute('name', prop);
                    el.setAttribute('value', settings.data[prop]);
                    form.appendChild(el);
                }
            }
            return form;
        },
        /**
         * Gets response from iframe and fires onComplete event when ready
         * @param iframe
         * @param file Filename to use in onComplete callback 
         */
        _getResponse : function(iframe, file){            
            // getting response
            var toDeleteFlag = false, self = this, settings = this._settings;   
               
            addEvent(iframe, 'load', function(){                
                
                if (// For Safari 
                    iframe.src == "javascript:'%3Chtml%3E%3C/html%3E';" ||
                    // For FF, IE
                    iframe.src == "javascript:'<html></html>';"){                                                                        
                        // First time around, do not delete.
                        // We reload to blank page, so that reloading main page
                        // does not re-submit the post.
                        
                        if (toDeleteFlag) {
                            // Fix busy state in FF3
                            setTimeout(function(){
                                removeNode(iframe);
                            }, 0);
                        }
                                                
                        return;
                }
                
                var doc = iframe.contentDocument ? iframe.contentDocument : window.frames[iframe.id].document;
                
                // fixing Opera 9.26,10.00
                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 Internet Explorer property
                    response = doc.XMLDocument;
                } else if (doc.body){
                    // response is html document or plain text
                    response = doc.body.innerHTML;
                    
                    if (settings.responseType && settings.responseType.toLowerCase() == 'json') {
                        // If the document was sent as 'application/javascript' or
                        // 'text/javascript', then the browser wraps the text in a <pre>
                        // tag and performs html encoding on the contents.  In this case,
                        // we need to pull the original text content from the text node's
                        // nodeValue property to retrieve the unmangled content.
                        // Note that IE6 only understands text/html
                        if (doc.body.firstChild && doc.body.firstChild.nodeName.toUpperCase() == 'PRE') {
                            doc.normalize();
                            response = doc.body.firstChild.firstChild.nodeValue;
                        }
                        
                        if (response) {
                            response = eval("(" + response + ")");
                        } else {
                            response = {};
                        }
                    }
                } else {
                    // response is a xml document
                    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;
                
                // Fix IE mixed content issue
                iframe.src = "javascript:'<html></html>';";
            });            
        },        
        /**
         * Upload file contained in this._input
         */
        submit: function(){                        
            var self = this, settings = this._settings;
            
            if ( ! this._input || this._input.value === ''){                
                return;                
            }
                                    
            var file = fileFromPath(this._input.value);
            
            // user returned false to cancel upload
            if (false === settings.onSubmit.call(this, file, getExt(file))){
                this._clearInput();                
                return;
            }
            
            // sending request    
            var iframe = this._createIframe();
            var form = this._createForm(iframe);
            
            // assuming following structure
            // div -> input type='file'
            removeNode(this._input.parentNode);            
            removeClass(self._button, self._settings.hoverClass);
            removeClass(self._button, self._settings.focusClass);
                        
            form.appendChild(this._input);
                        
            form.submit();

            // request set, clean up                
            removeNode(form); form = null;                          
            removeNode(this._input); this._input = null;            
            
            // Get response from iframe and fire onComplete event when ready
            this._getResponse(iframe, file);            

            // get ready for next request            
            this._createInput();
        }
    };
})(); 


$(document).ready(function() {
  
  var root_url = 'http://'+location.hostname;
  
  var config = {
    toolbar:
     [ 
       ['Cut','Copy','Paste','PasteText','PasteFromWord'],
       ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat','-','Source','Preview'],
       ['Link','Unlink','Anchor'],
       '/',
       ['Bold', 'Italic', 'Underline','NumberedList','BulletedList'],
       ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
       ['Outdent','Indent','Blockquote'],
       ['TextColor','BGColor','HorizontalRule','SpecialChar']
     ]
  };
  
  $("textarea").ckeditor(config);
  
  $('.upload_linked_image').each( function() {
    var add    = this;
    var del    = $(this).parent().find('.delete_button');
    var url    = root_url+'/helpers/new_upload.php';
    var result = $(this).parent().find('.content_holder');
    var my_id  = '#'+$(this).attr('id').replace("_upload","");
    var prompt = 'Enter a caption for';
    var type   = 'image';
    var valid  = 'jpg|png|jpeg|gif';
    linked_file_upload(add, del, my_id, url, prompt, type, valid, result);
  });

  $('.upload_linked_document').each( function() {
    var add    = this;
    var del    = $(this).parent().find('.delete_button');
    var url    = root_url+'/helpers/new_upload.php';
    var result = $(this).parent().find('.content_holder');
    var my_id  = '#'+$(this).attr('id').replace("_upload","");
    var prompt = 'Enter a document description for';
    var type   = 'document';
    var valid  = 'doc|pdf|xls|zip|gz|ppt';
    linked_file_upload(add, del, my_id, url, prompt, type, valid, result);
  });

  $('.upload_file').each(function() {
    var add    = this;
    var type   = $(this).hasClass('image')?'image':'document';
    var valid  = type=='image'?'jpg|png|jpeg|gif':'doc|pdf|xls|zip|gz|ppt';
    var prompt = type=='image'?'Enter a caption for':'Enter a document description for';
    var del    = $(this).parent().find('.delete_button');
    var url    = root_url+'/helpers/upload_only.php';
    var result = $(this).parent().find('.content_holder');
    file_upload(add, del, url, prompt, type, valid, result);
  });
  
  function linked_file_upload(upload_button, delete_button, link_field, url, prompt, file_type, valid_types, container) {
    $(upload_button).show();
    $(delete_button).hide();
    new AjaxUpload(upload_button, {
      action: url,
      responseType: 'json',
      name: 'uploadfile',
      onChange: function(file, extension){
        caption=window.prompt(prompt+' '+file);
        this.setData({'caption': caption, 'upload_type': file_type});
      },
      onSubmit: function(file, ext){
        var valid_exp = new RegExp('^('+valid_types+')$');
        if (! (ext && valid_exp.test(ext))){ 
          // extension is not allowed                              
          alert(ext+' is not a valid file extension for a '+file_type);
          return false;
        }
      },
      onComplete: function(file, response){
        if(response.error === 0 ){
          if(file_type == 'image') {
            $('<img src="'+response.path+'">').appendTo(container);
          } else {
            $('<p>'+response.external+'</p>').appendTo(container);
          }

          $(link_field).val(response.my_id);

          // remove button
          $(upload_button).hide();
          $(delete_button).show();
        }
      },
      onError: function(file, response) {
        alert(response);
      }
    });
  }

  function file_upload(upload_button, delete_button, url, prompt, file_type, valid_types, container) {
    $(upload_button).show();
    $(delete_button).hide();
    var my_id  = '#'+$(upload_button).attr('id').replace("_span","");
    var internal = $(upload_button).parent().find('#'+my_id+'_internal');
    var external = $(upload_button).parent().find('#'+my_id+'_external');
    var container = $(upload_button).parent().find('#'+my_id+'_container');
    new AjaxUpload(upload_button, {
      action: url,
      responseType: 'json',
      name: 'uploadfile',
      onChange: function(file, extension){
        this.setData({'upload_type': file_type});
      },
      onSubmit: function(file, ext){
        var valid_exp = new RegExp('^('+valid_types+')$');
        if (! (ext && valid_exp.test(ext))){ 
          // extension is not allowed                              
          alert(ext+' is not a valid file extension for a '+file_type);
          return false;
        }
      },
      onComplete: function(file, response){
        if(response.error === 0 ){
          if(file_type == 'image') {
            $(container).html('<img src="'+response.path+'">');
          } else {
            $(container).html(response.external);
          }

          $(internal).val(response.internal);
          $(external).val(response.external);
          
          // remove button
          $(upload_button).hide();
          $(delete_button).show();
        }
      },
      onError: function(file, response) {
        alert(response);
      }
    });
  }
  
  $("img")
    .hover(
      function(e){
        $('body').css('cursor', 'url(/app/css/images/magnify.cur), -moz-zoom-in'); 
      },
      function(e){
        $('body').css('cursor', 'default'); 
      })
    .click(function(e){
      var c = (this.alt != "") ? "<br/>" + this.alt : "";
      var mysrc = (this.src).replace('t_','') ;
      $("body").append("<p id='preview'><img src='"+ mysrc +"' alt='Image preview' />"+ c +"</p>");
      $("#preview")
        .center()
        .fadeIn("fast");
      $("#preview img").one('click', function() {
          $("#preview").fadeOut("fast", function() { $(this).remove(); });
      });
    });
  
  // create separate tooltip for each field...
  $('input.has_help').bind('keyup focus',
    function(e){
      var my_input = this;
      if($(my_input).title!=''){
        this.t = this.title;
        var tip_id = $(this).attr('id')+"_tip";
        var position = $(this).position();
        var width = $(this).outerWidth();
        this.top = (position.top + 10); this.left = (position.left + 10 + width);
        $('body').append( '<p id="'+tip_id+'" class="vtip corners"><img class="vtipArrow" src="app/css/images/ltip_arrow.png"/>' + this.t + '</p>' );
        $('#'+tip_id).css("top", this.top+"px").css("left", this.left+"px").fadeIn("slow");
      }
      $('.corners').corner("8px");
    }
  ).blur(
      function(e){
        var tip_id = $(this).attr('id')+"_tip";
        $('#'+tip_id).fadeOut("slow", function(){$('#'+tip_id).remove()});
      });
  
  $('input.has_help:checkbox, input.has_help:radio').hover(
    function(e){
      var my_input = this;
      if($(my_input).title!=''){
        this.t = this.title;
        var tip_id = $(this).attr('id')+"_tip";
        var position = $(this).position();
        var width = $(this).outerWidth();
        this.top = (position.top + 10); this.left = (position.left + 10 + width);
        $('body').append( '<p id="'+tip_id+'" class="vtip corners"><img class="vtipArrow" src="app/css/images/ltip_arrow.png"/>' + this.t + '</p>' );
        $('#'+tip_id).css("top", this.top+"px").css("left", this.left+"px").fadeIn("slow");
        $('.corners').corner("8px");
      }
    },
    function(e){
      var tip_id = $(this).attr('id')+"_tip";
      $('#'+tip_id).fadeOut("slow", function(){$('#'+tip_id).remove()});
    });
  
});

function help() {
  $('#textile_help')
  .load('/textile_examples.html')
  .dialog({'title':'Textile Help','width': '660px', 'autoOpen': false})
  .dialog('open');
}

  

/*!
 * jQuery corner plugin: simple corner rounding
 * Examples and documentation at: http://jquery.malsup.com/corner/
 * version 2.01 (08-SEP-2009)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 */

/**
 *  corner() takes a single string argument:  $('#myDiv').corner("effect corners width")
 *
 *  effect:  name of the effect to apply, such as round, bevel, notch, bite, etc (default is round). 
 *  corners: one or more of: top, bottom, tr, tl, br, or bl. 
 *           by default, all four corners are adorned. 
 *  width:   width of the effect; in the case of rounded corners this is the radius. 
 *           specify this value using the px suffix such as 10px (and yes, it must be pixels).
 *
 * @author Dave Methvin (http://methvin.com/jquery/jq-corner.html)
 * @author Mike Alsup   (http://jquery.malsup.com/corner/)
 */
;(function($) { 

var moz = $.browser.mozilla && /gecko/i.test(navigator.userAgent);
var webkit = $.browser.safari && $.browser.version >= 3;

var expr = $.browser.msie && (function() {
    var div = document.createElement('div');
    try { div.style.setExpression('width','0+0'); }
    catch(e) { return false; }
    return true;
})();
    
function sz(el, p) { 
    return parseInt($.css(el,p))||0; 
};
function hex2(s) {
    var s = parseInt(s).toString(16);
    return ( s.length < 2 ) ? '0'+s : s;
};
function gpc(node) {
    for ( ; node && node.nodeName.toLowerCase() != 'html'; node = node.parentNode ) {
        var v = $.css(node,'backgroundColor');
        if (v == 'rgba(0, 0, 0, 0)')
            continue; // webkit
        if (v.indexOf('rgb') >= 0) { 
            var rgb = v.match(/\d+/g); 
            return '#'+ hex2(rgb[0]) + hex2(rgb[1]) + hex2(rgb[2]);
        }
        if ( v && v != 'transparent' )
            return v;
    }
    return '#ffffff';
};

function getWidth(fx, i, width) {
    switch(fx) {
    case 'round':  return Math.round(width*(1-Math.cos(Math.asin(i/width))));
    case 'cool':   return Math.round(width*(1+Math.cos(Math.asin(i/width))));
    case 'sharp':  return Math.round(width*(1-Math.cos(Math.acos(i/width))));
    case 'bite':   return Math.round(width*(Math.cos(Math.asin((width-i-1)/width))));
    case 'slide':  return Math.round(width*(Math.atan2(i,width/i)));
    case 'jut':    return Math.round(width*(Math.atan2(width,(width-i-1))));
    case 'curl':   return Math.round(width*(Math.atan(i)));
    case 'tear':   return Math.round(width*(Math.cos(i)));
    case 'wicked': return Math.round(width*(Math.tan(i)));
    case 'long':   return Math.round(width*(Math.sqrt(i)));
    case 'sculpt': return Math.round(width*(Math.log((width-i-1),width)));
    case 'dog':    return (i&1) ? (i+1) : width;
    case 'dog2':   return (i&2) ? (i+1) : width;
    case 'dog3':   return (i&3) ? (i+1) : width;
    case 'fray':   return (i%2)*width;
    case 'notch':  return width; 
    case 'bevel':  return i+1;
    }
};

$.fn.corner = function(options) {
    // in 1.3+ we can fix mistakes with the ready state
	if (this.length == 0) {
        if (!$.isReady && this.selector) {
            var s = this.selector, c = this.context;
            $(function() {
                $(s,c).corner(options);
            });
        }
        return this;
	}

    return this.each(function(index){
		var $this = $(this);
		var o = (options || $this.attr($.fn.corner.defaults.metaAttr) || '').toLowerCase();
		var keep = /keep/.test(o);                       // keep borders?
		var cc = ((o.match(/cc:(#[0-9a-f]+)/)||[])[1]);  // corner color
		var sc = ((o.match(/sc:(#[0-9a-f]+)/)||[])[1]);  // strip color
		var width = parseInt((o.match(/(\d+)px/)||[])[1]) || 10; // corner width
		var re = /round|bevel|notch|bite|cool|sharp|slide|jut|curl|tear|fray|wicked|sculpt|long|dog3|dog2|dog/;
		var fx = ((o.match(re)||['round'])[0]);
		var edges = { T:0, B:1 };
		var opts = {
			TL:  /top|tl|left/.test(o),       TR:  /top|tr|right/.test(o),
			BL:  /bottom|bl|left/.test(o),    BR:  /bottom|br|right/.test(o)
		};
		if ( !opts.TL && !opts.TR && !opts.BL && !opts.BR )
			opts = { TL:1, TR:1, BL:1, BR:1 };
			
		// support native rounding
		if ($.fn.corner.defaults.useNative && fx == 'round' && (moz || webkit) && !cc && !sc) {
			if (opts.TL)
				$this.css(moz ? '-moz-border-radius-topleft' : '-webkit-border-top-left-radius', width + 'px');
			if (opts.TR)
				$this.css(moz ? '-moz-border-radius-topright' : '-webkit-border-top-right-radius', width + 'px');
			if (opts.BL)
				$this.css(moz ? '-moz-border-radius-bottomleft' : '-webkit-border-bottom-left-radius', width + 'px');
			if (opts.BR)
				$this.css(moz ? '-moz-border-radius-bottomright' : '-webkit-border-bottom-right-radius', width + 'px');
			return;
		}
			
		var strip = document.createElement('div');
		strip.style.overflow = 'hidden';
		strip.style.height = '1px';
		strip.style.backgroundColor = sc || 'transparent';
		strip.style.borderStyle = 'solid';
	
        var pad = {
            T: parseInt($.css(this,'paddingTop'))||0,     R: parseInt($.css(this,'paddingRight'))||0,
            B: parseInt($.css(this,'paddingBottom'))||0,  L: parseInt($.css(this,'paddingLeft'))||0
        };

        if (typeof this.style.zoom != undefined) this.style.zoom = 1; // force 'hasLayout' in IE
        if (!keep) this.style.border = 'none';
        strip.style.borderColor = cc || gpc(this.parentNode);
        var cssHeight = $.curCSS(this, 'height');

        for (var j in edges) {
            var bot = edges[j];
            // only add stips if needed
            if ((bot && (opts.BL || opts.BR)) || (!bot && (opts.TL || opts.TR))) {
                strip.style.borderStyle = 'none '+(opts[j+'R']?'solid':'none')+' none '+(opts[j+'L']?'solid':'none');
                var d = document.createElement('div');
                $(d).addClass('jquery-corner');
                var ds = d.style;

                bot ? this.appendChild(d) : this.insertBefore(d, this.firstChild);

                if (bot && cssHeight != 'auto') {
                    if ($.css(this,'position') == 'static')
                        this.style.position = 'relative';
                    ds.position = 'absolute';
                    ds.bottom = ds.left = ds.padding = ds.margin = '0';
                    if (expr)
                        ds.setExpression('width', 'this.parentNode.offsetWidth');
                    else
                        ds.width = '100%';
                }
                else if (!bot && $.browser.msie) {
                    if ($.css(this,'position') == 'static')
                        this.style.position = 'relative';
                    ds.position = 'absolute';
                    ds.top = ds.left = ds.right = ds.padding = ds.margin = '0';
                    
                    // fix ie6 problem when blocked element has a border width
                    if (expr) {
                        var bw = sz(this,'borderLeftWidth') + sz(this,'borderRightWidth');
                        ds.setExpression('width', 'this.parentNode.offsetWidth - '+bw+'+ "px"');
                    }
                    else
                        ds.width = '100%';
                }
                else {
                	ds.position = 'relative';
                    ds.margin = !bot ? '-'+pad.T+'px -'+pad.R+'px '+(pad.T-width)+'px -'+pad.L+'px' : 
                                        (pad.B-width)+'px -'+pad.R+'px -'+pad.B+'px -'+pad.L+'px';                
                }

                for (var i=0; i < width; i++) {
                    var w = Math.max(0,getWidth(fx,i, width));
                    var e = strip.cloneNode(false);
                    e.style.borderWidth = '0 '+(opts[j+'R']?w:0)+'px 0 '+(opts[j+'L']?w:0)+'px';
                    bot ? d.appendChild(e) : d.insertBefore(e, d.firstChild);
                }
            }
        }
    });
};

$.fn.uncorner = function() { 
	if (moz || webkit)
		this.css(moz ? '-moz-border-radius' : '-webkit-border-radius', 0);
	$('div.jquery-corner', this).remove();
	return this;
};

// expose options
$.fn.corner.defaults = {
	useNative: true, // true if plugin should attempt to use native browser support for border radius rounding
	metaAttr:  'data-corner' // name of meta attribute to use for options
};
    
})(jQuery);


/*
* jQuery Cycle Plugin
* Examples and documentation at: http://malsup.com/jquery/cycle/
* Copyright (c) 2007-2008 M. Alsup
* Version: 2.30 (02-NOV-2008)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
;(function(G){var A="2.30";var B=G.browser.msie&&/MSIE 6.0/.test(navigator.userAgent);function D(){if(window.console&&window.console.log){window.console.log("[cycle] "+Array.prototype.join.call(arguments,""))}}G.fn.cycle=function(I){var J=arguments[1];return this.each(function(){if(I===undefined||I===null){I={}}if(I.constructor==String){switch(I){case"stop":if(this.cycleTimeout){clearTimeout(this.cycleTimeout)}this.cycleTimeout=0;G(this).data("cycle.opts","");return ;case"pause":this.cyclePause=1;return ;case"resume":this.cyclePause=0;if(J===true){I=G(this).data("cycle.opts");if(!I){D("options not found, can not resume");return }if(this.cycleTimeout){clearTimeout(this.cycleTimeout);this.cycleTimeout=0}E(I.elements,I,1,1)}return ;default:I={fx:I}}}else{if(I.constructor==Number){var O=I;I=G(this).data("cycle.opts");if(!I){D("options not found, can not advance slide");return }if(O<0||O>=I.elements.length){D("invalid slide index: "+O);return }I.nextSlide=O;if(this.cycleTimeout){clearTimeout(this.cycleTimeout);this.cycleTimeout=0}E(I.elements,I,1,O>=I.currSlide);return }}if(this.cycleTimeout){clearTimeout(this.cycleTimeout)}this.cycleTimeout=0;this.cyclePause=0;var R=G(this);var P=I.slideExpr?G(I.slideExpr,this):R.children();var L=P.get();if(L.length<2){D("terminating; too few slides: "+L.length);return }var K=G.extend({},G.fn.cycle.defaults,I||{},G.metadata?R.metadata():G.meta?R.data():{});if(K.autostop){K.countdown=K.autostopCount||L.length}R.data("cycle.opts",K);K.container=this;K.elements=L;K.before=K.before?[K.before]:[];K.after=K.after?[K.after]:[];K.after.unshift(function(){K.busy=0});if(K.continuous){K.after.push(function(){E(L,K,0,!K.rev)})}if(B&&K.cleartype&&!K.cleartypeNoBg){C(P)}var T=this.className;K.width=parseInt((T.match(/w:(\d+)/)||[])[1])||K.width;K.height=parseInt((T.match(/h:(\d+)/)||[])[1])||K.height;K.timeout=parseInt((T.match(/t:(\d+)/)||[])[1])||K.timeout;if(R.css("position")=="static"){R.css("position","relative")}if(K.width){R.width(K.width)}if(K.height&&K.height!="auto"){R.height(K.height)}if(K.startingSlide){K.startingSlide=parseInt(K.startingSlide)}if(K.random){K.randomMap=[];for(var M=0;M<L.length;M++){K.randomMap.push(M)}K.randomMap.sort(function(V,U){return Math.random()-0.5});K.randomIndex=0;K.startingSlide=K.randomMap[0]}else{if(K.startingSlide>=L.length){K.startingSlide=0}}var N=K.startingSlide||0;P.css({position:"absolute",top:0,left:0}).hide().each(function(U){var V=N?U>=N?L.length-(U-N):N-U:L.length-U;G(this).css("z-index",V)});G(L[N]).css("opacity",1).show();if(G.browser.msie){L[N].style.removeAttribute("filter")}if(K.fit&&K.width){P.width(K.width)}if(K.fit&&K.height&&K.height!="auto"){P.height(K.height)}if(K.pause){R.hover(function(){this.cyclePause=1},function(){this.cyclePause=0})}var S=G.fn.cycle.transitions[K.fx];if(G.isFunction(S)){S(R,P,K)}else{if(K.fx!="custom"){D("unknown transition: "+K.fx)}}P.each(function(){var U=G(this);this.cycleH=(K.fit&&K.height)?K.height:U.height();this.cycleW=(K.fit&&K.width)?K.width:U.width()});K.cssBefore=K.cssBefore||{};K.animIn=K.animIn||{};K.animOut=K.animOut||{};P.not(":eq("+N+")").css(K.cssBefore);if(K.cssFirst){G(P[N]).css(K.cssFirst)}if(K.timeout){K.timeout=parseInt(K.timeout);if(K.speed.constructor==String){K.speed=G.fx.speeds[K.speed]||parseInt(K.speed)}if(!K.sync){K.speed=K.speed/2}while((K.timeout-K.speed)<250){K.timeout+=K.speed}}if(K.easing){K.easeIn=K.easeOut=K.easing}if(!K.speedIn){K.speedIn=K.speed}if(!K.speedOut){K.speedOut=K.speed}K.slideCount=L.length;K.currSlide=N;if(K.random){K.nextSlide=K.currSlide;if(++K.randomIndex==L.length){K.randomIndex=0}K.nextSlide=K.randomMap[K.randomIndex]}else{K.nextSlide=K.startingSlide>=(L.length-1)?0:K.startingSlide+1}var Q=P[N];if(K.before.length){K.before[0].apply(Q,[Q,Q,K,true])}if(K.after.length>1){K.after[1].apply(Q,[Q,Q,K,true])}if(K.click&&!K.next){K.next=K.click}if(K.next){G(K.next).bind("click",function(){return F(L,K,K.rev?-1:1)})}if(K.prev){G(K.prev).bind("click",function(){return F(L,K,K.rev?1:-1)})}if(K.pager){H(L,K)}K.addSlide=function(V,W){var U=G(V),X=U[0];if(!K.autostopCount){K.countdown++}L[W?"unshift":"push"](X);if(K.els){K.els[W?"unshift":"push"](X)}K.slideCount=L.length;U.css("position","absolute");U[W?"prependTo":"appendTo"](R);if(W){K.currSlide++;K.nextSlide++}if(B&&K.cleartype&&!K.cleartypeNoBg){C(U)}if(K.fit&&K.width){U.width(K.width)}if(K.fit&&K.height&&K.height!="auto"){P.height(K.height)}X.cycleH=(K.fit&&K.height)?K.height:U.height();X.cycleW=(K.fit&&K.width)?K.width:U.width();U.css(K.cssBefore);if(K.pager){G.fn.cycle.createPagerAnchor(L.length-1,X,G(K.pager),L,K)}if(typeof K.onAddSlide=="function"){K.onAddSlide(U)}};if(K.timeout||K.continuous){this.cycleTimeout=setTimeout(function(){E(L,K,0,!K.rev)},K.continuous?10:K.timeout+(K.delay||0))}})};function E(N,I,M,O){if(I.busy){return }var L=I.container,Q=N[I.currSlide],P=N[I.nextSlide];if(L.cycleTimeout===0&&!M){return }if(!M&&!L.cyclePause&&((I.autostop&&(--I.countdown<=0))||(I.nowrap&&!I.random&&I.nextSlide<I.currSlide))){if(I.end){I.end(I)}return }if(M||!L.cyclePause){if(I.before.length){G.each(I.before,function(R,S){S.apply(P,[Q,P,I,O])})}var J=function(){if(G.browser.msie&&I.cleartype){this.style.removeAttribute("filter")}G.each(I.after,function(R,S){S.apply(P,[Q,P,I,O])})};if(I.nextSlide!=I.currSlide){I.busy=1;if(I.fxFn){I.fxFn(Q,P,I,J,O)}else{if(G.isFunction(G.fn.cycle[I.fx])){G.fn.cycle[I.fx](Q,P,I,J)}else{G.fn.cycle.custom(Q,P,I,J,M&&I.fastOnEvent)}}}if(I.random){I.currSlide=I.nextSlide;if(++I.randomIndex==N.length){I.randomIndex=0}I.nextSlide=I.randomMap[I.randomIndex]}else{var K=(I.nextSlide+1)==N.length;I.nextSlide=K?0:I.nextSlide+1;I.currSlide=K?N.length-1:I.nextSlide-1}if(I.pager){G.fn.cycle.updateActivePagerLink(I.pager,I.currSlide)}}if(I.timeout&&!I.continuous){L.cycleTimeout=setTimeout(function(){E(N,I,0,!I.rev)},I.timeout)}else{if(I.continuous&&L.cyclePause){L.cycleTimeout=setTimeout(function(){E(N,I,0,!I.rev)},10)}}}G.fn.cycle.updateActivePagerLink=function(I,J){G(I).find("a").removeClass("activeSlide").filter("a:eq("+J+")").addClass("activeSlide")};function F(I,J,M){var L=J.container,K=L.cycleTimeout;if(K){clearTimeout(K);L.cycleTimeout=0}if(J.random&&M<0){J.randomIndex--;if(--J.randomIndex==-2){J.randomIndex=I.length-2}else{if(J.randomIndex==-1){J.randomIndex=I.length-1}}J.nextSlide=J.randomMap[J.randomIndex]}else{if(J.random){if(++J.randomIndex==I.length){J.randomIndex=0}J.nextSlide=J.randomMap[J.randomIndex]}else{J.nextSlide=J.currSlide+M;if(J.nextSlide<0){if(J.nowrap){return false}J.nextSlide=I.length-1}else{if(J.nextSlide>=I.length){if(J.nowrap){return false}J.nextSlide=0}}}}if(J.prevNextClick&&typeof J.prevNextClick=="function"){J.prevNextClick(M>0,J.nextSlide,I[J.nextSlide])}E(I,J,1,M>=0);return false}function H(J,K){var I=G(K.pager);G.each(J,function(L,M){G.fn.cycle.createPagerAnchor(L,M,I,J,K)});G.fn.cycle.updateActivePagerLink(K.pager,K.startingSlide)}G.fn.cycle.createPagerAnchor=function(K,L,I,J,M){var N=(typeof M.pagerAnchorBuilder=="function")?G(M.pagerAnchorBuilder(K,L)):G('<a href="#">'+(K+1)+"</a>");if(N.parents("body").length==0){N.appendTo(I)}N.bind(M.pagerEvent,function(){M.nextSlide=K;var P=M.container,O=P.cycleTimeout;if(O){clearTimeout(O);P.cycleTimeout=0}if(typeof M.pagerClick=="function"){M.pagerClick(M.nextSlide,J[M.nextSlide])}E(J,M,1,M.currSlide<K);return false});if(M.pauseOnPagerHover){N.hover(function(){M.container.cyclePause=1},function(){M.container.cyclePause=0})}};function C(K){function J(L){var L=parseInt(L).toString(16);return L.length<2?"0"+L:L}function I(N){for(;N&&N.nodeName.toLowerCase()!="html";N=N.parentNode){var L=G.css(N,"background-color");if(L.indexOf("rgb")>=0){var M=L.match(/\d+/g);return"#"+J(M[0])+J(M[1])+J(M[2])}if(L&&L!="transparent"){return L}}return"#ffffff"}K.each(function(){G(this).css("background-color",I(this))})}G.fn.cycle.custom=function(T,N,I,K,J){var S=G(T),O=G(N);O.css(I.cssBefore);var L=J?1:I.speedIn;var R=J?1:I.speedOut;var M=J?null:I.easeIn;var Q=J?null:I.easeOut;var P=function(){O.animate(I.animIn,L,M,K)};S.animate(I.animOut,R,Q,function(){if(I.cssAfter){S.css(I.cssAfter)}if(!I.sync){P()}});if(I.sync){P()}};G.fn.cycle.transitions={fade:function(J,K,I){K.not(":eq("+I.startingSlide+")").css("opacity",0);I.before.push(function(){G(this).show()});I.animIn={opacity:1};I.animOut={opacity:0};I.cssBefore={opacity:0};I.cssAfter={display:"none"};I.onAddSlide=function(L){L.hide()}}};G.fn.cycle.ver=function(){return A};G.fn.cycle.defaults={fx:"fade",timeout:4000,continuous:0,speed:1000,speedIn:null,speedOut:null,next:null,prev:null,prevNextClick:null,pager:null,pagerClick:null,pagerEvent:"click",pagerAnchorBuilder:null,before:null,after:null,end:null,easing:null,easeIn:null,easeOut:null,shuffle:null,animIn:null,animOut:null,cssBefore:null,cssAfter:null,fxFn:null,height:"auto",startingSlide:0,sync:1,random:0,fit:0,pause:0,pauseOnPagerHover:0,autostop:0,autostopCount:0,delay:0,slideExpr:null,cleartype:0,nowrap:0,fastOnEvent:0}})(jQuery);


/*
	jQuery List DragSort v0.3.10
	Website: http://dragsort.codeplex.com/
	License: http://dragsort.codeplex.com/license
*/
(function(a){a.fn.dragsort=function(c){var d=a.extend({},a.fn.dragsort.defaults,c);var b=new Array();var f=null,e=null;if(this.selector){a("head").append("<style type='text/css'>"+(this.selector.split(",").join(" "+d.dragSelector+",")+" "+d.dragSelector)+" { cursor: pointer; }</style>")}this.each(function(h,g){if(a(g).is("table")&&a(g).children().size()==1&&a(g).children().is("tbody")){g=a(g).children().get(0)}var j={draggedItem:null,placeHolderItem:null,pos:null,offset:null,offsetLimit:null,container:g,init:function(){a(this.container).attr("listIdx",h).mousedown(this.grabItem).find(d.dragSelector).css("cursor","pointer")},grabItem:function(l){if(l.button==2||a(l.target).is(d.dragSelectorExclude)){return}var n=l.target;while(!a(n).is("[listIdx="+a(this).attr("listIdx")+"] "+d.dragSelector)){if(n==this){return}n=n.parentNode}if(f!=null&&f.draggedItem!=null){f.dropItem()}a(l.target).css("cursor","move");f=b[a(this).attr("listIdx")];f.draggedItem=a(n).closest(d.itemSelector);var i=parseInt(f.draggedItem.css("marginTop"));var m=parseInt(f.draggedItem.css("marginLeft"));f.offset=f.draggedItem.offset();f.offset.top=l.pageY-f.offset.top+(isNaN(i)?0:i)-1;f.offset.left=l.pageX-f.offset.left+(isNaN(m)?0:m)-1;if(!d.dragBetween){var k=a(f.container).outerHeight()==0?Math.max(1,Math.round(0.5+a(f.container).children(d.itemSelector).size()*f.draggedItem.outerWidth()/a(f.container).outerWidth()))*f.draggedItem.outerHeight():a(f.container).outerHeight();f.offsetLimit=a(f.container).offset();f.offsetLimit.right=f.offsetLimit.left+a(f.container).outerWidth()-f.draggedItem.outerWidth();f.offsetLimit.bottom=f.offsetLimit.top+k-f.draggedItem.outerHeight()}f.draggedItem.css({position:"absolute",opacity:0.8,"z-index":999}).after(d.placeHolderTemplate);f.placeHolderItem=f.draggedItem.next().css("height",f.draggedItem.height()).attr("placeHolder",true);a(b).each(function(p,o){o.ensureNotEmpty();o.buildPositionTable()});f.setPos(l.pageX,l.pageY);a(document).bind("selectstart",f.stopBubble);a(document).bind("mousemove",f.swapItems);a(document).bind("mouseup",f.dropItem);return false},setPos:function(i,m){var l=m-this.offset.top;var k=i-this.offset.left;if(!d.dragBetween){l=Math.min(this.offsetLimit.bottom,Math.max(l,this.offsetLimit.top));k=Math.min(this.offsetLimit.right,Math.max(k,this.offsetLimit.left))}this.draggedItem.parents().each(function(){if(a(this).css("position")!="static"&&(!a.browser.mozilla||a(this).css("display")!="table")){var n=a(this).offset();l-=n.top;k-=n.left;return false}});this.draggedItem.css({top:l,left:k})},buildPositionTable:function(){var i=this.draggedItem==null?null:this.draggedItem.get(0);var k=new Array();a(this.container).children(d.itemSelector).each(function(l,n){if(n!=i){var m=a(n).offset();m.right=m.left+a(n).width();m.bottom=m.top+a(n).height();m.elm=n;k.push(m)}});this.pos=k},dropItem:function(){if(f.draggedItem==null){return}a(f.container).find(d.dragSelector).css("cursor","pointer");f.placeHolderItem.before(f.draggedItem);f.draggedItem.css({position:"",top:"",left:"",opacity:"","z-index":""});f.placeHolderItem.remove();a("*[emptyPlaceHolder]").remove();d.dragEnd.apply(f.draggedItem);f.draggedItem=null;a(document).unbind("selectstart",f.stopBubble);a(document).unbind("mousemove",f.swapItems);a(document).unbind("mouseup",f.dropItem);return false},stopBubble:function(){return false},swapItems:function(n){if(f.draggedItem==null){return false}f.setPos(n.pageX,n.pageY);var m=f.findPos(n.pageX,n.pageY);var l=f;for(var k=0;m==-1&&d.dragBetween&&k<b.length;k++){m=b[k].findPos(n.pageX,n.pageY);l=b[k]}if(m==-1||a(l.pos[m].elm).attr("placeHolder")){return false}if(e==null||e.top>f.draggedItem.offset().top||e.left>f.draggedItem.offset().left){a(l.pos[m].elm).before(f.placeHolderItem)}else{a(l.pos[m].elm).after(f.placeHolderItem)}a(b).each(function(p,o){o.ensureNotEmpty();o.buildPositionTable()});e=f.draggedItem.offset();return false},findPos:function(k,m){for(var l=0;l<this.pos.length;l++){if(this.pos[l].left<k&&this.pos[l].right>k&&this.pos[l].top<m&&this.pos[l].bottom>m){return l}}return -1},ensureNotEmpty:function(){if(!d.dragBetween){return}var i=this.draggedItem==null?null:this.draggedItem.get(0);var l=null,k=true;a(this.container).children(d.itemSelector).each(function(m,n){if(a(n).attr("emptyPlaceHolder")){l=n}else{if(n!=i){k=false}}});if(k&&l==null){a(this.container).append(d.placeHolderTemplate).children(":last").attr("emptyPlaceHolder",true)}else{if(!k&&l!=null){a(l).remove()}}}};j.init();b.push(j)});return this};a.fn.dragsort.defaults={itemSelector:"li",dragSelector:"li",dragSelectorExclude:"input, a[href]",dragEnd:function(){},dragBetween:false,placeHolderTemplate:"<li>&nbsp;</li>"}})(jQuery);

/*
  VERSION: Drop Shadow jQuery Plugin 1.6  12-13-2007

  REQUIRES: jquery.js (verified for 1.3.2)

  SYNTAX: $(selector).dropShadow(options);  // Creates new drop shadows
          $(selector).redrawShadow();       // Redraws shadows on elements
          $(selector).removeShadow();       // Removes shadows from elements
          $(selector).shadowId();           // Returns an existing shadow's ID

  OPTIONS:

    left    : integer (default = 4)
    top     : integer (default = 4)
    blur    : integer (default = 2)
    opacity : decimal (default = 0.5)
    color   : string (default = "black")
    swap    : boolean (default = false)

  The left and top parameters specify the distance and direction, in  pixels, to
  offset the shadow. Zero values position the shadow directly behind the element.
  Positive values shift the shadow to the right and down, while negative values 
  shift the shadow to the left and up.
  
  The blur parameter specifies the spread, or dispersion, of the shadow. Zero 
  produces a sharp shadow, one or two produces a normal shadow, and three or four
  produces a softer shadow. Higher values increase the processing load.
  
  The opacity parameter should be a decimal value, usually less than one. You can
  use a value higher than one in special situations, e.g. with extreme blurring. 
  
  Color is specified in the usual manner, with a color name or hex value. The
  color parameter does not apply with transparent images.
  
  The swap parameter reverses the stacking order of the original and the shadow.
  This can be used for special effects, like an embossed or engraved look.

  EXPLANATION:
  
  This jQuery plug-in adds soft drop shadows behind page elements. It is only
  intended for adding a few drop shadows to mostly stationary objects, like a
  page heading, a photo, or content containers.

  The shadows it creates are not bound to the original elements, so they won't
  move or change size automatically if the original elements change. A window
  resize event listener is assigned, which should re-align the shadows in many
  cases, but if the elements otherwise move or resize you will have to handle
  those events manually. Shadows can be redrawn with the redrawShadow() method
  or removed with the removeShadow() method. The redrawShadow() method uses the
  same options used to create the original shadow. If you want to change the
  options, you should remove the shadow first and then create a new shadow.
  
  The dropShadow method returns a jQuery collection of the new shadow(s). If
  further manipulation is required, you can store it in a variable like this:

    var myShadow = $("#myElement").dropShadow();

  You can also read the ID of the shadow from the original element at a later
  time. To get a shadow's ID, either read the shadowId attribute of the
  original element or call the shadowId() method. For example:

    var myShadowId = $("#myElement").attr("shadowId");  or
    var myShadowId = $("#myElement").shadowId();

  If the original element does not already have an ID assigned, a random ID will
  be generated for the shadow. However, if the original does have an ID, the 
  shadow's ID will be the original ID and "_dropShadow". For example, if the
  element's ID is "myElement", the shadow's ID would be "myElement_dropShadow".

  If you have a long piece of text and the user resizes the window so that the
  text wraps or unwraps, the shape of the text changes and the words are no
  longer in the same positions. In that case, you can either preset the height
  and width, so that it becomes a fixed box, or you can shadow each word
  separately, like this:

    <h1><span>Your</span> <span>Page</span> <span>Title</span></h1>

    $("h1 span").dropShadow();

  The dropShadow method attempts to determine whether the selected elements have
  transparent backgrounds. If you want to shadow the content inside an element,
  like text or a transparent image, it must not have a background-color or
  background-image style. If the element has a solid background it will create a
  rectangular shadow around the outside box.

  The shadow elements are positioned absolutely one layer below the original 
  element, which is positioned relatively (unless it's already absolute).

  *** All shadows have the "dropShadow" class, for selecting with CSS or jQuery.

  ISSUES:
  
    1)  Limited styling of shadowed elements by ID. Because IDs must be unique,
        and the shadows have their own ID, styles applied by ID won't transfer
        to the shadows. Instead, style elements by class or use inline styles.
    2)  Sometimes shadows don't align properly. Elements may need to be wrapped
        in container elements, margins or floats changed, etc. or you may just 
        have to tweak the left and top offsets to get them to align. For example,
        with draggable objects, you have to wrap them inside two divs. Make the 
        outer div draggable and set the inner div's position to relative. Then 
        you can create a shadow on the element inside the inner div.
    3)  If the user changes font sizes it will throw the shadows off. Browsers 
        do not expose an event for font size changes. The only known way to 
        detect a user font size change is to embed an invisible text element and
        then continuously poll for changes in size.
    4)  Safari support is shaky, and may require even more tweaks/wrappers, etc.
    
    The bottom line is that this is a gimick effect, not PFM, and if you push it
    too hard or expect it to work in every possible situation on every browser,
    you will be disappointed. Use it sparingly, and don't use it for anything 
    critical. Otherwise, have fun with it!
        
  AUTHOR: Larry Stevens.  This work is in the public domain,
          and is not supported in any way. Use it at your own risk.
*/


(function($){

  var dropShadowZindex = 1;  //z-index counter

  $.fn.dropShadow = function(options)
  {
    // Default options
    var opt = $.extend({
      left: 4,
      top: 4,
      blur: 2,
      opacity: .5,
      color: "black",
      swap: false
      }, options);
    var jShadows = $([]);  //empty jQuery collection
    
    // Loop through original elements
    this.not(".dropShadow").each(function()
    {
      var jthis = $(this);
      var shadows = [];
      var blur = (opt.blur <= 0) ? 0 : opt.blur;
      var opacity = (blur == 0) ? opt.opacity : opt.opacity / (blur * 8);
      var zOriginal = (opt.swap) ? dropShadowZindex : dropShadowZindex + 1;
      var zShadow = (opt.swap) ? dropShadowZindex + 1 : dropShadowZindex;
      
      // Create ID for shadow
      var shadowId;
      if (this.id) {
        shadowId = this.id + "_dropShadow";
      }
      else {
        shadowId = "ds" + (1 + Math.floor(9999 * Math.random()));
      }

      // Modify original element
      $.data(this, "shadowId", shadowId); //store id in expando
      $.data(this, "shadowOptions", options); //store options in expando
      jthis
        .attr("shadowId", shadowId)
        .css("zIndex", zOriginal);
      if (jthis.css("position") != "absolute") {
        jthis.css({
          position: "relative",
          zoom: 1 //for IE layout
        });
      }

      // Create first shadow layer
      bgColor = jthis.css("backgroundColor");
      if (bgColor == "rgba(0, 0, 0, 0)") bgColor = "transparent";  //Safari
      if (bgColor != "transparent" || jthis.css("backgroundImage") != "none" 
          || this.nodeName == "SELECT" 
          || this.nodeName == "INPUT"
          || this.nodeName == "TEXTAREA") {   
        shadows[0] = $("<div></div>")
          .css("background", opt.color);                
      }
      else {
        shadows[0] = jthis
          .clone()
          .removeAttr("id")
          .removeAttr("name")
          .removeAttr("shadowId")
          .css("color", opt.color);
      }
      shadows[0]
        .addClass("dropShadow")
        .css({
          height: jthis.outerHeight(),
          left: blur,
          opacity: opacity,
          position: "absolute",
          top: blur,
          width: jthis.outerWidth(),
          zIndex: zShadow
        });
        
      // Create other shadow layers
      var layers = (8 * blur) + 1;
      for (i = 1; i < layers; i++) {
        shadows[i] = shadows[0].clone();
      }

      // Position layers
      var i = 1;      
      var j = blur;
      while (j > 0) {
        shadows[i].css({left: j * 2, top: 0});           //top
        shadows[i + 1].css({left: j * 4, top: j * 2});   //right
        shadows[i + 2].css({left: j * 2, top: j * 4});   //bottom
        shadows[i + 3].css({left: 0, top: j * 2});       //left
        shadows[i + 4].css({left: j * 3, top: j});       //top-right
        shadows[i + 5].css({left: j * 3, top: j * 3});   //bottom-right
        shadows[i + 6].css({left: j, top: j * 3});       //bottom-left
        shadows[i + 7].css({left: j, top: j});           //top-left
        i += 8;
        j--;
      }

      // Create container
      var divShadow = $("<div></div>")
        .attr("id", shadowId) 
        .addClass("dropShadow")
        .css({
          left: jthis.position().left + opt.left - blur,
          marginTop: jthis.css("marginTop"),
          marginRight: jthis.css("marginRight"),
          marginBottom: jthis.css("marginBottom"),
          marginLeft: jthis.css("marginLeft"),
          position: "absolute",
          top: jthis.position().top + opt.top - blur,
          zIndex: zShadow
        });

      // Add layers to container  
      for (i = 0; i < layers; i++) {
        divShadow.append(shadows[i]);
      }
      
      // Add container to DOM
      jthis.after(divShadow);

      // Add shadow to return set
      jShadows = jShadows.add(divShadow);

      // Re-align shadow on window resize
      $(window).resize(function()
      {
        try {
          divShadow.css({
            left: jthis.position().left + opt.left - blur,
            top: jthis.position().top + opt.top - blur
          });
        }
        catch(e){}
      });
      
      // Increment z-index counter
      dropShadowZindex += 2;

    });  //end each
    
    return this.pushStack(jShadows);
  };


  $.fn.redrawShadow = function()
  {
    // Remove existing shadows
    this.removeShadow();
    
    // Draw new shadows
    return this.each(function()
    {
      var shadowOptions = $.data(this, "shadowOptions");
      $(this).dropShadow(shadowOptions);
    });
  };


  $.fn.removeShadow = function()
  {
    return this.each(function()
    {
      var shadowId = $(this).shadowId();
      $("div#" + shadowId).remove();
    });
  };


  $.fn.shadowId = function()
  {
    return $.data(this[0], "shadowId");
  };


  $(function()  
  {
    // Suppress printing of shadows
    var noPrint = "<style type='text/css' media='print'>";
    noPrint += ".dropShadow{visibility:hidden;}</style>";
    $("head").append(noPrint);
  });

})(jQuery);

/*
 * jQuery Tools 1.2.3 - The missing UI library for the Web
 * 
 * [tabs, tooltip, scrollable, overlay, validator, toolbox.expose]
 * 
 * NO COPYRIGHTS OR LICENSES. DO WHAT YOU LIKE.
 * 
 * http://flowplayer.org/tools/
 * 
 * File generated: Fri Jun 18 12:59:02 GMT 2010
 */
(function(c){function p(e,b,a){var d=this,l=e.add(this),h=e.find(a.tabs),i=b.jquery?b:e.children(b),j;h.length||(h=e.children());i.length||(i=e.parent().find(b));i.length||(i=c(b));c.extend(this,{click:function(f,g){var k=h.eq(f);if(typeof f=="string"&&f.replace("#","")){k=h.filter("[href*="+f.replace("#","")+"]");f=Math.max(h.index(k),0)}if(a.rotate){var n=h.length-1;if(f<0)return d.click(n,g);if(f>n)return d.click(0,g)}if(!k.length){if(j>=0)return d;f=a.initialIndex;k=h.eq(f)}if(f===j)return d;
g=g||c.Event();g.type="onBeforeClick";l.trigger(g,[f]);if(!g.isDefaultPrevented()){o[a.effect].call(d,f,function(){g.type="onClick";l.trigger(g,[f])});j=f;h.removeClass(a.current);k.addClass(a.current);return d}},getConf:function(){return a},getTabs:function(){return h},getPanes:function(){return i},getCurrentPane:function(){return i.eq(j)},getCurrentTab:function(){return h.eq(j)},getIndex:function(){return j},next:function(){return d.click(j+1)},prev:function(){return d.click(j-1)},destroy:function(){h.unbind(a.event).removeClass(a.current);
i.find("a[href^=#]").unbind("click.T");return d}});c.each("onBeforeClick,onClick".split(","),function(f,g){c.isFunction(a[g])&&c(d).bind(g,a[g]);d[g]=function(k){c(d).bind(g,k);return d}});if(a.history&&c.fn.history){c.tools.history.init(h);a.event="history"}h.each(function(f){c(this).bind(a.event,function(g){d.click(f,g);return g.preventDefault()})});i.find("a[href^=#]").bind("click.T",function(f){d.click(c(this).attr("href"),f)});if(location.hash)d.click(location.hash);else if(a.initialIndex===
0||a.initialIndex>0)d.click(a.initialIndex)}c.tools=c.tools||{version:"1.2.3"};c.tools.tabs={conf:{tabs:"a",current:"current",onBeforeClick:null,onClick:null,effect:"default",initialIndex:0,event:"click",rotate:false,history:false},addEffect:function(e,b){o[e]=b}};var o={"default":function(e,b){this.getPanes().hide().eq(e).show();b.call()},fade:function(e,b){var a=this.getConf(),d=a.fadeOutSpeed,l=this.getPanes();d?l.fadeOut(d):l.hide();l.eq(e).fadeIn(a.fadeInSpeed,b)},slide:function(e,b){this.getPanes().slideUp(200);
this.getPanes().eq(e).slideDown(400,b)},ajax:function(e,b){this.getPanes().eq(0).load(this.getTabs().eq(e).attr("href"),b)}},m;c.tools.tabs.addEffect("horizontal",function(e,b){m||(m=this.getPanes().eq(0).width());this.getCurrentPane().animate({width:0},function(){c(this).hide()});this.getPanes().eq(e).animate({width:m},function(){c(this).show();b.call()})});c.fn.tabs=function(e,b){var a=this.data("tabs");if(a){a.destroy();this.removeData("tabs")}if(c.isFunction(b))b={onBeforeClick:b};b=c.extend({},
c.tools.tabs.conf,b);this.each(function(){a=new p(c(this),e,b);c(this).data("tabs",a)});return b.api?a:this}})(jQuery);
(function(f){function p(a,b,c){var h=c.relative?a.position().top:a.offset().top,e=c.relative?a.position().left:a.offset().left,i=c.position[0];h-=b.outerHeight()-c.offset[0];e+=a.outerWidth()+c.offset[1];var j=b.outerHeight()+a.outerHeight();if(i=="center")h+=j/2;if(i=="bottom")h+=j;i=c.position[1];a=b.outerWidth()+a.outerWidth();if(i=="center")e-=a/2;if(i=="left")e-=a;return{top:h,left:e}}function t(a,b){var c=this,h=a.add(c),e,i=0,j=0,m=a.attr("title"),q=n[b.effect],k,r=a.is(":input"),u=r&&a.is(":checkbox, :radio, select, :button, :submit"),
s=a.attr("type"),l=b.events[s]||b.events[r?u?"widget":"input":"def"];if(!q)throw'Nonexistent effect "'+b.effect+'"';l=l.split(/,\s*/);if(l.length!=2)throw"Tooltip: bad events configuration for "+s;a.bind(l[0],function(d){clearTimeout(i);if(b.predelay)j=setTimeout(function(){c.show(d)},b.predelay);else c.show(d)}).bind(l[1],function(d){clearTimeout(j);if(b.delay)i=setTimeout(function(){c.hide(d)},b.delay);else c.hide(d)});if(m&&b.cancelDefault){a.removeAttr("title");a.data("title",m)}f.extend(c,{show:function(d){if(!e){if(m)e=
f(b.layout).addClass(b.tipClass).appendTo(document.body).hide().append(m);else if(b.tip)e=f(b.tip).eq(0);else{e=a.next();e.length||(e=a.parent().next())}if(!e.length)throw"Cannot find tooltip for "+a;}if(c.isShown())return c;e.stop(true,true);var g=p(a,e,b);d=d||f.Event();d.type="onBeforeShow";h.trigger(d,[g]);if(d.isDefaultPrevented())return c;g=p(a,e,b);e.css({position:"absolute",top:g.top,left:g.left});k=true;q[0].call(c,function(){d.type="onShow";k="full";h.trigger(d)});g=b.events.tooltip.split(/,\s*/);
e.bind(g[0],function(){clearTimeout(i);clearTimeout(j)});g[1]&&!a.is("input:not(:checkbox, :radio), textarea")&&e.bind(g[1],function(o){o.relatedTarget!=a[0]&&a.trigger(l[1].split(" ")[0])});return c},hide:function(d){if(!e||!c.isShown())return c;d=d||f.Event();d.type="onBeforeHide";h.trigger(d);if(!d.isDefaultPrevented()){k=false;n[b.effect][1].call(c,function(){d.type="onHide";k=false;h.trigger(d)});return c}},isShown:function(d){return d?k=="full":k},getConf:function(){return b},getTip:function(){return e},
getTrigger:function(){return a}});f.each("onHide,onBeforeShow,onShow,onBeforeHide".split(","),function(d,g){f.isFunction(b[g])&&f(c).bind(g,b[g]);c[g]=function(o){f(c).bind(g,o);return c}})}f.tools=f.tools||{version:"1.2.3"};f.tools.tooltip={conf:{effect:"toggle",fadeOutSpeed:"fast",predelay:0,delay:30,opacity:1,tip:0,position:["top","center"],offset:[0,0],relative:false,cancelDefault:true,events:{def:"mouseenter,mouseleave",input:"focus,blur",widget:"focus mouseenter,blur mouseleave",tooltip:"mouseenter,mouseleave"},
layout:"<div/>",tipClass:"tooltip"},addEffect:function(a,b,c){n[a]=[b,c]}};var n={toggle:[function(a){var b=this.getConf(),c=this.getTip();b=b.opacity;b<1&&c.css({opacity:b});c.show();a.call()},function(a){this.getTip().hide();a.call()}],fade:[function(a){var b=this.getConf();this.getTip().fadeTo(b.fadeInSpeed,b.opacity,a)},function(a){this.getTip().fadeOut(this.getConf().fadeOutSpeed,a)}]};f.fn.tooltip=function(a){var b=this.data("tooltip");if(b)return b;a=f.extend(true,{},f.tools.tooltip.conf,a);
if(typeof a.position=="string")a.position=a.position.split(/,?\s/);this.each(function(){b=new t(f(this),a);f(this).data("tooltip",b)});return a.api?b:this}})(jQuery);
(function(e){function n(f,c){var a=e(c);return a.length<2?a:f.parent().find(c)}function t(f,c){var a=this,l=f.add(a),g=f.children(),k=0,m=c.vertical;j||(j=a);if(g.length>1)g=e(c.items,f);e.extend(a,{getConf:function(){return c},getIndex:function(){return k},getSize:function(){return a.getItems().size()},getNaviButtons:function(){return o.add(p)},getRoot:function(){return f},getItemWrap:function(){return g},getItems:function(){return g.children(c.item).not("."+c.clonedClass)},move:function(b,d){return a.seekTo(k+
b,d)},next:function(b){return a.move(1,b)},prev:function(b){return a.move(-1,b)},begin:function(b){return a.seekTo(0,b)},end:function(b){return a.seekTo(a.getSize()-1,b)},focus:function(){return j=a},addItem:function(b){b=e(b);if(c.circular){e(".cloned:last").before(b);e(".cloned:first").replaceWith(b.clone().addClass(c.clonedClass))}else g.append(b);l.trigger("onAddItem",[b]);return a},seekTo:function(b,d,h){if(c.circular&&b===0&&k==-1&&d!==0)return a;if(!c.circular&&b<0||b>a.getSize()||b<-1)return a;
var i=b;if(b.jquery)b=a.getItems().index(b);else i=a.getItems().eq(b);var q=e.Event("onBeforeSeek");if(!h){l.trigger(q,[b,d]);if(q.isDefaultPrevented()||!i.length)return a}i=m?{top:-i.position().top}:{left:-i.position().left};k=b;j=a;if(d===undefined)d=c.speed;g.animate(i,d,c.easing,h||function(){l.trigger("onSeek",[b])});return a}});e.each(["onBeforeSeek","onSeek","onAddItem"],function(b,d){e.isFunction(c[d])&&e(a).bind(d,c[d]);a[d]=function(h){e(a).bind(d,h);return a}});if(c.circular){var r=a.getItems().slice(-1).clone().prependTo(g),
s=a.getItems().eq(1).clone().appendTo(g);r.add(s).addClass(c.clonedClass);a.onBeforeSeek(function(b,d,h){if(!b.isDefaultPrevented())if(d==-1){a.seekTo(r,h,function(){a.end(0)});return b.preventDefault()}else d==a.getSize()&&a.seekTo(s,h,function(){a.begin(0)})});a.seekTo(0,0)}var o=n(f,c.prev).click(function(){a.prev()}),p=n(f,c.next).click(function(){a.next()});!c.circular&&a.getSize()>1&&a.onBeforeSeek(function(b,d){setTimeout(function(){if(!b.isDefaultPrevented()){o.toggleClass(c.disabledClass,
d<=0);p.toggleClass(c.disabledClass,d>=a.getSize()-1)}},1)});c.mousewheel&&e.fn.mousewheel&&f.mousewheel(function(b,d){if(c.mousewheel){a.move(d<0?1:-1,c.wheelSpeed||50);return false}});c.keyboard&&e(document).bind("keydown.scrollable",function(b){if(!(!c.keyboard||b.altKey||b.ctrlKey||e(b.target).is(":input")))if(!(c.keyboard!="static"&&j!=a)){var d=b.keyCode;if(m&&(d==38||d==40)){a.move(d==38?-1:1);return b.preventDefault()}if(!m&&(d==37||d==39)){a.move(d==37?-1:1);return b.preventDefault()}}});
e(a).trigger("onBeforeSeek",[c.initialIndex])}e.tools=e.tools||{version:"1.2.3"};e.tools.scrollable={conf:{activeClass:"active",circular:false,clonedClass:"cloned",disabledClass:"disabled",easing:"swing",initialIndex:0,item:null,items:".items",keyboard:true,mousewheel:false,next:".next",prev:".prev",speed:400,vertical:false,wheelSpeed:0}};var j;e.fn.scrollable=function(f){var c=this.data("scrollable");if(c)return c;f=e.extend({},e.tools.scrollable.conf,f);this.each(function(){c=new t(e(this),f);e(this).data("scrollable",
c)});return f.api?c:this}})(jQuery);
(function(a){function t(d,b){var c=this,i=d.add(c),o=a(window),k,f,m,g=a.tools.expose&&(b.mask||b.expose),n=Math.random().toString().slice(10);if(g){if(typeof g=="string")g={color:g};g.closeOnClick=g.closeOnEsc=false}var p=b.target||d.attr("rel");f=p?a(p):d;if(!f.length)throw"Could not find Overlay: "+p;d&&d.index(f)==-1&&d.click(function(e){c.load(e);return e.preventDefault()});a.extend(c,{load:function(e){if(c.isOpened())return c;var h=q[b.effect];if(!h)throw'Overlay: cannot find effect : "'+b.effect+
'"';b.oneInstance&&a.each(s,function(){this.close(e)});e=e||a.Event();e.type="onBeforeLoad";i.trigger(e);if(e.isDefaultPrevented())return c;m=true;g&&a(f).expose(g);var j=b.top,r=b.left,u=f.outerWidth({margin:true}),v=f.outerHeight({margin:true});if(typeof j=="string")j=j=="center"?Math.max((o.height()-v)/2,0):parseInt(j,10)/100*o.height();if(r=="center")r=Math.max((o.width()-u)/2,0);h[0].call(c,{top:j,left:r},function(){if(m){e.type="onLoad";i.trigger(e)}});g&&b.closeOnClick&&a.mask.getMask().one("click",
c.close);b.closeOnClick&&a(document).bind("click."+n,function(l){a(l.target).parents(f).length||c.close(l)});b.closeOnEsc&&a(document).bind("keydown."+n,function(l){l.keyCode==27&&c.close(l)});return c},close:function(e){if(!c.isOpened())return c;e=e||a.Event();e.type="onBeforeClose";i.trigger(e);if(!e.isDefaultPrevented()){m=false;q[b.effect][1].call(c,function(){e.type="onClose";i.trigger(e)});a(document).unbind("click."+n).unbind("keydown."+n);g&&a.mask.close();return c}},getOverlay:function(){return f},
getTrigger:function(){return d},getClosers:function(){return k},isOpened:function(){return m},getConf:function(){return b}});a.each("onBeforeLoad,onStart,onLoad,onBeforeClose,onClose".split(","),function(e,h){a.isFunction(b[h])&&a(c).bind(h,b[h]);c[h]=function(j){a(c).bind(h,j);return c}});k=f.find(b.close||".close");if(!k.length&&!b.close){k=a('<a class="close"></a>');f.prepend(k)}k.click(function(e){c.close(e)});b.load&&c.load()}a.tools=a.tools||{version:"1.2.3"};a.tools.overlay={addEffect:function(d,
b,c){q[d]=[b,c]},conf:{close:null,closeOnClick:true,closeOnEsc:true,closeSpeed:"fast",effect:"default",fixed:!a.browser.msie||a.browser.version>6,left:"center",load:false,mask:null,oneInstance:true,speed:"normal",target:null,top:"10%"}};var s=[],q={};a.tools.overlay.addEffect("default",function(d,b){var c=this.getConf(),i=a(window);if(!c.fixed){d.top+=i.scrollTop();d.left+=i.scrollLeft()}d.position=c.fixed?"fixed":"absolute";this.getOverlay().css(d).fadeIn(c.speed,b)},function(d){this.getOverlay().fadeOut(this.getConf().closeSpeed,
d)});a.fn.overlay=function(d){var b=this.data("overlay");if(b)return b;if(a.isFunction(d))d={onBeforeLoad:d};d=a.extend(true,{},a.tools.overlay.conf,d);this.each(function(){b=new t(a(this),d);s.push(b);a(this).data("overlay",b)});return d.api?b:this}})(jQuery);
(function(d){function v(a,b,c){var k=a.offset().top,f=a.offset().left,l=c.position.split(/,?\s+/),g=l[0];l=l[1];k-=b.outerHeight()-c.offset[0];f+=a.outerWidth()+c.offset[1];c=b.outerHeight()+a.outerHeight();if(g=="center")k+=c/2;if(g=="bottom")k+=c;a=a.outerWidth();if(l=="center")f-=(a+b.outerWidth())/2;if(l=="left")f-=a;return{top:k,left:f}}function w(a){function b(){return this.getAttribute("type")==a}b.key="[type="+a+"]";return b}function s(a,b,c){function k(g,e,j){if(!(!c.grouped&&g.length)){var h;
if(j===false||d.isArray(j)){h=i.messages[e.key||e]||i.messages["*"];h=h[c.lang]||i.messages["*"].en;(e=h.match(/\$\d/g))&&d.isArray(j)&&d.each(e,function(n){h=h.replace(this,j[n])})}else h=j[c.lang]||j;g.push(h)}}var f=this,l=b.add(f);a=a.not(":button, :image, :reset, :submit");d.extend(f,{getConf:function(){return c},getForm:function(){return b},getInputs:function(){return a},invalidate:function(g,e){if(!e){var j=[];d.each(g,function(h,n){h=a.filter("[name="+h+"]");if(h.length){h.trigger("OI",[n]);
j.push({input:h,messages:[n]})}});g=j;e=d.Event()}e.type="onFail";l.trigger(e,[g]);e.isDefaultPrevented()||q[c.effect][0].call(f,g,e);return f},reset:function(g){g=g||a;g.removeClass(c.errorClass).each(function(){var e=d(this).data("msg.el");if(e){e.remove();d(this).data("msg.el",null)}}).unbind(c.errorInputEvent||"");return f},destroy:function(){b.unbind(c.formEvent).unbind("reset.V");a.unbind(c.inputEvent||"").unbind("change.V");return f.reset()},checkValidity:function(g,e){g=g||a;g=g.not(":disabled");
if(!g.length)return true;e=e||d.Event();e.type="onBeforeValidate";l.trigger(e,[g]);if(e.isDefaultPrevented())return e.result;var j=[],h=c.errorInputEvent+".v";g.each(function(){var p=[],m=d(this).unbind(h).data("messages",p);d.each(t,function(){var o=this,r=o[0];if(m.filter(r).length){o=o[1].call(f,m,m.val());if(o!==true){e.type="onBeforeFail";l.trigger(e,[m,r]);if(e.isDefaultPrevented())return false;var u=m.attr(c.messageAttr);if(u){p=[u];return false}else k(p,r,o)}}});if(p.length){j.push({input:m,
messages:p});m.trigger("OI",[p]);c.errorInputEvent&&m.bind(h,function(o){f.checkValidity(m,o)})}if(c.singleError&&j.length)return false});var n=q[c.effect];if(!n)throw'Validator: cannot find effect "'+c.effect+'"';if(j.length){f.invalidate(j,e);return false}else{n[1].call(f,g,e);e.type="onSuccess";l.trigger(e,[g]);g.unbind(h)}return true}});d.each("onBeforeValidate,onBeforeFail,onFail,onSuccess".split(","),function(g,e){d.isFunction(c[e])&&d(f).bind(e,c[e]);f[e]=function(j){d(f).bind(e,j);return f}});
c.formEvent&&b.bind(c.formEvent,function(g){if(!f.checkValidity(null,g))return g.preventDefault()});b.bind("reset.V",function(){f.reset()});a[0]&&a[0].validity&&a.each(function(){this.oninvalid=function(){return false}});if(b[0])b[0].checkValidity=f.checkValidity;c.inputEvent&&a.bind(c.inputEvent,function(g){f.checkValidity(d(this),g)});a.filter(":checkbox, select").filter("[required]").bind("change.V",function(g){var e=d(this);if(this.checked||e.is("select")&&d(this).val())q[c.effect][1].call(f,
e,g)})}d.tools=d.tools||{version:"1.2.3"};var x=/\[type=([a-z]+)\]/,y=/^-?[0-9]*(\.[0-9]+)?$/,z=/^([a-z0-9_\.\-\+]+)@([\da-z\.\-]+)\.([a-z\.]{2,6})$/i,A=/^(https?:\/\/)?([\da-z\.\-]+)\.([a-z\.]{2,6})([\/\w \.\-]*)*\/?$/i,i;i=d.tools.validator={conf:{grouped:false,effect:"default",errorClass:"invalid",inputEvent:null,errorInputEvent:"keyup",formEvent:"submit",lang:"en",message:"<div/>",messageAttr:"data-message",messageClass:"error",offset:[0,0],position:"center right",singleError:false,speed:"normal"},
messages:{"*":{en:"Please correct this value"}},localize:function(a,b){d.each(b,function(c,k){i.messages[c]=i.messages[c]||{};i.messages[c][a]=k})},localizeFn:function(a,b){i.messages[a]=i.messages[a]||{};d.extend(i.messages[a],b)},fn:function(a,b,c){if(d.isFunction(b))c=b;else{if(typeof b=="string")b={en:b};this.messages[a.key||a]=b}if(b=x.exec(a))a=w(b[1]);t.push([a,c])},addEffect:function(a,b,c){q[a]=[b,c]}};var t=[],q={"default":[function(a){var b=this.getConf();d.each(a,function(c,k){c=k.input;
c.addClass(b.errorClass);var f=c.data("msg.el");if(!f){f=d(b.message).addClass(b.messageClass).appendTo(document.body);c.data("msg.el",f)}f.css({visibility:"hidden"}).find("span").remove();d.each(k.messages,function(l,g){d("<span/>").html(g).appendTo(f)});f.outerWidth()==f.parent().width()&&f.add(f.find("p")).css({display:"inline"});k=v(c,f,b);f.css({visibility:"visible",position:"absolute",top:k.top,left:k.left}).fadeIn(b.speed)})},function(a){var b=this.getConf();a.removeClass(b.errorClass).each(function(){var c=
d(this).data("msg.el");c&&c.css({visibility:"hidden"})})}]};d.each("email,url,number".split(","),function(a,b){d.expr[":"][b]=function(c){return c.getAttribute("type")===b}});d.fn.oninvalid=function(a){return this[a?"bind":"trigger"]("OI",a)};i.fn(":email","Please enter a valid email address",function(a,b){return!b||z.test(b)});i.fn(":url","Please enter a valid URL",function(a,b){return!b||A.test(b)});i.fn(":number","Please enter a numeric value.",function(a,b){return y.test(b)});i.fn("[max]","Please enter a value smaller than $1",
function(a,b){if(d.tools.dateinput&&a.is(":date"))return true;a=a.attr("max");return parseFloat(b)<=parseFloat(a)?true:[a]});i.fn("[min]","Please enter a value larger than $1",function(a,b){if(d.tools.dateinput&&a.is(":date"))return true;a=a.attr("min");return parseFloat(b)>=parseFloat(a)?true:[a]});i.fn("[required]","Please complete this mandatory field.",function(a,b){if(a.is(":checkbox"))return a.is(":checked");return!!b});i.fn("[pattern]",function(a){var b=new RegExp("^"+a.attr("pattern")+"$");
return b.test(a.val())});d.fn.validator=function(a){var b=this.data("validator");if(b){b.destroy();this.removeData("validator")}a=d.extend(true,{},i.conf,a);if(this.is("form"))return this.each(function(){var c=d(this);b=new s(c.find(":input"),c,a);c.data("validator",b)});else{b=new s(this,this.eq(0).closest("form"),a);return this.data("validator",b)}}})(jQuery);
(function(b){function k(){if(b.browser.msie){var a=b(document).height(),d=b(window).height();return[window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,a-d<20?d:a]}return[b(document).width(),b(document).height()]}function h(a){if(a)return a.call(b.mask)}b.tools=b.tools||{version:"1.2.3"};var l;l=b.tools.expose={conf:{maskId:"exposeMask",loadSpeed:"slow",closeSpeed:"fast",closeOnClick:true,closeOnEsc:true,zIndex:9998,opacity:0.8,startOpacity:0,color:"#fff",onLoad:null,
onClose:null}};var c,i,f,g,j;b.mask={load:function(a,d){if(f)return this;if(typeof a=="string")a={color:a};a=a||g;g=a=b.extend(b.extend({},l.conf),a);c=b("#"+a.maskId);if(!c.length){c=b("<div/>").attr("id",a.maskId);b("body").append(c)}var m=k();c.css({position:"absolute",top:0,left:0,width:m[0],height:m[1],display:"none",opacity:a.startOpacity,zIndex:a.zIndex});a.color&&c.css("backgroundColor",a.color);if(h(a.onBeforeLoad)===false)return this;a.closeOnEsc&&b(document).bind("keydown.mask",function(e){e.keyCode==
27&&b.mask.close(e)});a.closeOnClick&&c.bind("click.mask",function(e){b.mask.close(e)});b(window).bind("resize.mask",function(){b.mask.fit()});if(d&&d.length){j=d.eq(0).css("zIndex");b.each(d,function(){var e=b(this);/relative|absolute|fixed/i.test(e.css("position"))||e.css("position","relative")});i=d.css({zIndex:Math.max(a.zIndex+1,j=="auto"?0:j)})}c.css({display:"block"}).fadeTo(a.loadSpeed,a.opacity,function(){b.mask.fit();h(a.onLoad)});f=true;return this},close:function(){if(f){if(h(g.onBeforeClose)===
false)return this;c.fadeOut(g.closeSpeed,function(){h(g.onClose);i&&i.css({zIndex:j})});b(document).unbind("keydown.mask");c.unbind("click.mask");b(window).unbind("resize.mask");f=false}return this},fit:function(){if(f){var a=k();c.css({width:a[0],height:a[1]})}},getMask:function(){return c},isLoaded:function(){return f},getConf:function(){return g},getExposed:function(){return i}};b.fn.mask=function(a){b.mask.load(a);return this};b.fn.expose=function(a){b.mask.load(a,this);return this}})(jQuery);


// simple wrapper functions for different slideshow effects
(function($){
  $.fn.extend({ 
    //plugin name - simpleSlide
    simpleSlide: function(options) {

      //Settings list and the default values
      var defaults = {
        fx:    'fade',
        pause:  1,
        showLinks: false,
        navid: 123,
      };

      var options = $.extend(defaults, options);

      return this.each(function() {
        var o =options;

        //Assign current element to variable, in this case is UL element
        var obj = $(this);				

        $(obj).after('<div id=\"'+o.navid+'\" class=\"slide_nav\" style=\"display: inline;\"/>').cycle({ 
          fx:    o.fx,
          // next:  '{$nav_id}_next'      , //  null,  // id of element to use as click trigger for next slide 
          // prev:  '{$nav_id}_prev'      , //  null,  // id of element to use as click trigger for previous slide 
          // 
          // pager:  '#$nav_id',
          // pagerEvent: 'click', 
          pause:  o.pause  
        });
        // $('#$tag_list_id').hover(
          //   function() { $('#$nav_id').fadeIn(); },
          //   function() { $('#$nav_id').fadeOut(); }
          // );
          // 
          // function onBefore() {
            // 	$('#title').html(this.alt);
            // }
            // };




            // //Get all LI in the UL
            // var items = $("li", obj);
            // 
            // //Change the color according to odd and even rows
            // $("li:even", obj).css('background-color', o.evenColor);				
            // $("li:odd", obj).css('background-color', o.oddColor);					  
            // 
            // //Attach mouseover and mouseout event to the LI  
            // items.mouseover(function() {
              // 	$(this).animate({paddingLeft: o.animatePadding}, 300);
              // 
              // }).mouseout(function() {
                // 	$(this).animate({paddingLeft: o.defaultPadding}, 300);
                // });

              });
            }
          });
          })(jQuery);





