﻿/* jQuery GMCarousel Plugin */
(function($) {
    $.fn.GMCarousel = function(options) {
        return this.each(function(i) {
            // Settings
            var el = this;
            el.acceptClicks = true;
            el.curImage = 0;
            el.jqthis = $(this).css({ position: 'relative' });

            el.opts = $.extend({}, GMCarousel, options);

            el.jqchildren = el.jqthis.children();
            el.totalChildren = el.jqchildren.size();

            el.ImageTitles = new Array();

            if (el.totalChildren == 1) {
                el.opts.type = "none";
                el.opts.displayPlayPause = false;
                el.opts.displayNextPrevious = false;
            };

            el.index = i;

            // Set the width and height
            var width, height;
            switch (el.opts.type) {
                case 'vertical':
                    width = el.opts.width;
                    height = el.opts.height;
                    break;
                case 'fade':
                    width = el.opts.width;
                    height = el.opts.height;
                    break;
                default: //Horizontal
                    width = el.totalChildren * el.opts.width;
                    height = el.opts.height;
                    break;
            };

            // The Container
            el.container = $('<div id="GMC' + i + '" class="GMCContainer">').css({ position: 'relative', width: el.opts.width });
            el.ImgContainer = $('<div class="GMCImgContainer" style="height:' + el.opts.height + 'px;position:relative;overflow:hidden">')
                                .css({ height: el.opts.height, width: el.opts.width, position: 'relative', overflow: 'hidden' });
            el.jqthis.css({ height: height, width: width });

            el.jqthis.wrap(el.container);
            el.jqthis.wrap(el.ImgContainer);


            if (el.opts.displayControlPanel) {
                el.controlPanel = $('<div class="GMCControlPanel">');

                /* PAGINATION */
                el.pagination = $('<div class="GMCPagination">');
                el.pagination.appendTo(el.controlPanel);

                if (el.opts.displayCountLabel) {
                    el.label = $('<p id="GMCLabel' + i + '">' + (el.curImage + 1) + ' of ' + el.totalChildren + '</p>').appendTo(el.pagination);
                };

                if (el.opts.displayNextPrevious) {
                    var jqulNP = $('<ul>').appendTo(el.pagination);
                    /* NEXT PREVIOUS*/
                    el.previousButton = $('<a href="javascript:void(0);" title="Move to previous image">Previous</a>').click(function() {
                        var image = (el.curImage == 0) ? el.totalChildren - 1 : el.curImage - 1;
                        $('div.GMCPagination a#c' + el.index + 'link' + image).click();
                    });
                    $('<li class="prev">').appendTo(jqulNP).append(el.previousButton);

                    el.previousButton.tooltip({
                        bodyHandler: function() {
                            var previous = (el.curImage == 0) ? el.totalChildren - 1 : el.curImage - 1;
                            return el.ImageTitles[previous].toString();
                        },
                        showURL: false
                    });

                    el.nextButton = $('<a href="javascript:void(0);" title="Move to next image">Next</a>').click(function() {
                        el.MoveNext();
                    });
                    $('<li class="next">').appendTo(jqulNP).append(el.nextButton);

                    el.nextButton.tooltip({
                        bodyHandler: function() {
                            var next = (el.curImage == el.totalChildren - 1) ? 0 : el.curImage + 1;
                            return el.ImageTitles[next].toString();
                        },
                        showURL: false
                    });

                };

                if (el.opts.displayPagination) {
                    var jqul = $('<ol class="GMCPages">').appendTo(el.pagination);
                };


                /* PLAY PAUSE */
                if (el.opts.displayPlayPause) {
                    el.playPauseContainer = $('<div class="GMCPlayPause">');

                    el.playLink = $('<li class="play"><a href="javascript:void(0);" id="GMCPlay' + el.index + '" title="Play">Play</a></li>').click(function() {
                        el.MoveNext(true);
                        el.StartRotation();
                    });

                    el.playLink.tooltip({ showURL: false });

                    el.pauseLink = $('<li class="pause"><a href="javascript:void(0);" id="GMCPause' + el.index + '" title="Pause">Pause</a></li>').click(function() {
                        el.StopRotation();
                    });

                    el.pauseLink.tooltip({ showURL: false });

                    var playPauseUl = $('<ul>').appendTo(el.playPauseContainer);

                    playPauseUl.append(el.playLink);
                    playPauseUl.append(el.pauseLink);
                    el.playPauseContainer.insertAfter(el.pagination);

                    el.playPauseContainer.appendTo(el.controlPanel);
                };

                if (el.opts.controlPanelAfterCarousel) {
                    el.jqthis.parent().parent().append(el.controlPanel);
                }
                else {
                    el.jqthis.parent().before(el.controlPanel);
                };
            };


            var pos = { x: 0, y: 0 };

            // for each image
            el.jqchildren.each(function(j) {

                if (el.opts.type == 'horizontal') {
                    pos.x = j * el.opts.width;
                }
                else if (el.opts.type == 'vertical') {
                    pos.y = j * el.opts.height;
                };

                var jqchild = $(this).attr("id", "c" + i + "img" + j).css({ height: el.opts.height, width: el.opts.width, position: 'absolute', left: pos.x, top: pos.y });

                if (el.opts.type == 'fade' && j != 0) {
                    // Hide the subsequent images if faded
                    jqchild.hide();
                };

                var jqimg = jqchild.find('img').hide();

                if (jqimg.parent().is('a')) {

                    var p = jqimg.parent();

                    jqimg.linkHref = p.attr('href');
                    jqimg.linkTarget = p.attr('target');
                    jqimg.linkTitle = p.attr('title');
                    p.remove();

                    var $link = $('<a href="' + jqimg.linkHref + '" target="' + jqimg.linkTarget + '" title="' + jqimg.linkTitle + '"></a>');

                    jqimg.appendTo(jqchild);
                    jqimg.wrap($link);

                };

                /* Add to Pagination */
                if (el.opts.displayControlPanel) {
                    var selected = (j == 0) ? 'selected' : '';

                    var $a = $('<a id="c' + (i) + 'link' + (j) + '" href="#' + (j) + '" class="' + selected + '" title="' + jqimg.linkTitle + '">' + (j + 1) + '</a>').click(function() {
                        el.MoveToImage(this.index, false);
                    });
                    if (jqimg.linkTitle == null || jqimg.linkTitle.length < 1)
                        el.ImageTitles[j] = "Image " + (j + 1);
                    else
                        el.ImageTitles[j] = jqimg.linkTitle;

                    $a.tooltip({ showURL: false });
                    var n = $a.get(0);

                    n.index = j;

                    $('<li>').appendTo(jqul).append($a);
                };


                /* TITLE BAR */
                var $loader = $('<div class="GMCLoader">').appendTo(jqchild);
                var image = new Image();
                image.onload = function() {
                    image.onload = null;
                    $loader.fadeOut();
                    jqimg.css({ marginLeft: -image.width * .5, marginTop: -image.height * .5, position: 'absolute', left: '50%', top: '50%' }).fadeIn();
                };
                image.src = jqimg.attr('src');
            });

            el.MoveNext = function(automatic) {
                var image = (el.curImage == el.totalChildren - 1) ? 0 : el.curImage + 1;
                el.MoveToImage(image, automatic);
            };

            el.MoveToImage = function(image, automatic) {
                if (el.acceptClicks) {
                    // Disable clicks
                    el.acceptClicks = false;

                    if (!automatic) el.StopRotation();

                    var href = image; //href.replace(/^.*#/, '');
                    if (el.pagination) {
                        el.pagination.find('.selected').removeClass('selected');
                        $('div.GMCPagination a#c' + el.index + 'link' + image).addClass('selected');
                    };

                    if (el.opts.type == 'fade') {
                        $('div.GMCImgContainer li#c' + el.index + 'img' + el.curImage).fadeOut(el.opts.speed, function() {
                            $('div.GMCImgContainer li#c' + el.index + 'img' + href).fadeIn(el.opts.speed, function() {
                                el.acceptClicks = true;
                            });
                        });
                    }
                    else {
                        var params = {};

                        var firstToLast = (el.curImage == 0 && href == el.totalChildren - 1) ? true : false;
                        var lastToFirst = (el.curImage == el.totalChildren - 1 && href == 0) ? true : false;

                        if (el.totalChildren < 3) firstToLast = lastToFirst = false;

                        if (el.opts.type == 'vertical') {
                            if (firstToLast || lastToFirst) {
                                var $temp = $("li#c" + i + "img" + href).clone().attr("id", "GMC" + i + "_Temp").attr("class", "GMC" + i + "_Temp");

                                if (firstToLast) {
                                    $temp.css({ top: "-" + el.opts.height });
                                    $temp.prependTo($("div#GMC" + i + " div.GMCImgContainer ul"));
                                    params = { bottom: (0 - el.opts.height) };
                                }
                                else {
                                    $temp.css({ top: (el.opts.height * el.totalChildren) + "px" });
                                    $temp.appendTo($("div#GMC" + i + " div.GMCImgContainer ul"));
                                    params = { bottom: (el.opts.height * (el.totalChildren)) };
                                };
                            }
                            else {
                                params = { bottom: (el.opts.height * href) };
                            };
                        }
                        else if (el.opts.type == 'horizontal') {
                            if (firstToLast || lastToFirst) {
                                var $temp = $("li#c" + i + "img" + href).clone().attr("id", "GMC" + i + "_Temp").attr("class", "GMC" + i + "_Temp");

                                if (firstToLast) {
                                    $temp.css("left", "-" + el.opts.width + "px");
                                    $temp.prependTo($("div#GMC" + i + " div.GMCImgContainer ul"));
                                    params = { right: (0 - el.opts.width) };
                                }
                                else {
                                    $temp.css({ left: el.jqthis.css("width") });
                                    $temp.appendTo($("div#GMC" + i + " div.GMCImgContainer ul"));
                                    params = { right: (el.opts.width * (el.totalChildren)) };
                                };
                            }
                            else {
                                params = { right: (el.opts.width * href) };
                            };
                        };

                        el.jqthis.stop().animate(params, el.opts.speed, function() {

                            if (firstToLast || lastToFirst) {
                                if (el.opts.type == 'horizontal')
                                    el.jqthis.css({ right: (el.opts.width * href) });
                                else
                                    el.jqthis.css({ bottom: (el.opts.height * href) });
                            };
                            // Delete the temp
                            $("li.GMC" + i + "_Temp").remove();
                            el.acceptClicks = true;
                        });
                    };

                    index = href;

                    el.curImage = href;

                    if (el.label) {
                        el.label.text((el.curImage + 1) + ' of ' + el.totalChildren);
                    };
                    return false;

                }
            };


            /* AUTO ROTATION AND PLAY PAUSE */

            var autoRotation = 0;

            el.Rotate = function() {
                el.MoveNext(true);
            };

            el.StopRotation = function() {

                if (autoRotation > 0) {
                    window.clearTimeout(autoRotation);
                    autoRotation = 0;
                    if (el.pauseLink) el.pauseLink.hide();
                    if (el.playLink) el.playLink.css({ display: "" });
                };
            };

            el.StartRotation = function() {
                if (autoRotation == 0) {
                    autoRotation = window.setInterval(function() { el.Rotate(); }, el.opts.delay * 1000);
                    if (el.pauseLink) el.pauseLink.css({ display: "" });
                    if (el.playLink) el.playLink.hide();
                };
            };

            if (el.opts.autoRotate) {
                if (el.playLink) {
                    el.playLink.hide();
                };
                el.StartRotation();
            }
            else {
                if (el.pauseLink) {
                    el.pauseLink.hide();
                };
            };
        }); // End function this.each 

    }; // End function $.fn.GMCarousel
    GMCarousel = {
        height: 381,
        width: 462,
        delay: 6,
        titleOpacity: .90,
        autoRotate: true,
        controlPanelAfterCarousel: true, // Determines whether the control panel is rendered after images to allow the control panel to sit on top if necessary
        displayControlPanel: true,
        displayPagination: true,
        displayPlayPause: true,
        displayNextPrevious: true,
        displayCountLabel: false, // Displays a 1 of 12 label
        speed: 800,
        type: 'horizontal' // horizontal vertical fade
    }; // Initial variables
})(jQuery);               // End of function






/* MERGER WEBRESOURCE(1).JS
 * jQuery Tooltip plugin 1.2
 *
 * http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/
 * http://docs.jquery.com/Plugins/Tooltip
 *
 * Copyright (c) 2006 - 2008 Jörn Zaefferer
 *
 * $Id: jquery.tooltip.js 4569 2008-01-31 19:36:35Z joern.zaefferer $
 * 
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */;(function($){var helper={},current,title,tID,IE=$.browser.msie&&/MSIE\s(5\.5|6\.)/.test(navigator.userAgent),track=false;$.tooltip={blocked:false,defaults:{delay:200,showURL:true,extraClass:"",top:15,left:15,id:"tooltip"},block:function(){$.tooltip.blocked=!$.tooltip.blocked;}};$.fn.extend({tooltip:function(settings){settings=$.extend({},$.tooltip.defaults,settings);createHelper(settings);return this.each(function(){$.data(this,"tooltip-settings",settings);this.tooltipText=this.title;$(this).removeAttr("title");this.alt="";}).hover(save,hide).click(hide);},fixPNG:IE?function(){return this.each(function(){var image=$(this).css('backgroundImage');if(image.match(/^url\(["']?(.*\.png)["']?\)$/i)){image=RegExp.$1;$(this).css({'backgroundImage':'none','filter':"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='"+image+"')"}).each(function(){var position=$(this).css('position');if(position!='absolute'&&position!='relative')$(this).css('position','relative');});}});}:function(){return this;},unfixPNG:IE?function(){return this.each(function(){$(this).css({'filter':'',backgroundImage:''});});}:function(){return this;},hideWhenEmpty:function(){return this.each(function(){$(this)[$(this).html()?"show":"hide"]();});},url:function(){return this.attr('href')||this.attr('src');}});function createHelper(settings){if(helper.parent)return;helper.parent=$('<div id="'+settings.id+'"><h3></h3><div class="body"></div><div class="url"></div></div>').appendTo(document.body).hide();if($.fn.bgiframe)helper.parent.bgiframe();helper.title=$('h3',helper.parent);helper.body=$('div.body',helper.parent);helper.url=$('div.url',helper.parent);}function settings(element){return $.data(element,"tooltip-settings");}function handle(event){if(settings(this).delay)tID=setTimeout(show,settings(this).delay);else
show();track=!!settings(this).track;$(document.body).bind('mousemove',update);update(event);}function save(){if($.tooltip.blocked||this==current||(!this.tooltipText&&!settings(this).bodyHandler))return;current=this;title=this.tooltipText;if(settings(this).bodyHandler){helper.title.hide();var bodyContent=settings(this).bodyHandler.call(this);if(bodyContent.nodeType||bodyContent.jquery){helper.body.empty().append(bodyContent)}else{helper.body.html(bodyContent);}helper.body.show();}else if(settings(this).showBody){var parts=title.split(settings(this).showBody);helper.title.html(parts.shift()).show();helper.body.empty();for(var i=0,part;part=parts[i];i++){if(i>0)helper.body.append("<br/>");helper.body.append(part);}helper.body.hideWhenEmpty();}else{helper.title.html(title).show();helper.body.hide();}if(settings(this).showURL&&$(this).url())helper.url.html($(this).url().replace('http://','')).show();else
helper.url.hide();helper.parent.addClass(settings(this).extraClass);if(settings(this).fixPNG)helper.parent.fixPNG();handle.apply(this,arguments);}function show(){tID=null;helper.parent.show();update();}function update(event){if($.tooltip.blocked)return;if(!track&&helper.parent.is(":visible")){$(document.body).unbind('mousemove',update)}if(current==null){$(document.body).unbind('mousemove',update);return;}helper.parent.removeClass("viewport-right").removeClass("viewport-bottom");var left=helper.parent[0].offsetLeft;var top=helper.parent[0].offsetTop;if(event){left=event.pageX+settings(current).left;top=event.pageY+settings(current).top;helper.parent.css({left:left+'px',top:top+'px'});}var v=viewport(),h=helper.parent[0];if(v.x+v.cx<h.offsetLeft+h.offsetWidth){left-=h.offsetWidth+20+settings(current).left;helper.parent.css({left:left+'px'}).addClass("viewport-right");}if(v.y+v.cy<h.offsetTop+h.offsetHeight){top-=h.offsetHeight+20+settings(current).top;helper.parent.css({top:top+'px'}).addClass("viewport-bottom");}}function viewport(){return{x:$(window).scrollLeft(),y:$(window).scrollTop(),cx:$(window).width(),cy:$(window).height()};}function hide(event){if($.tooltip.blocked)return;if(tID)clearTimeout(tID);current=null;helper.parent.hide().removeClass(settings(this).extraClass);if(settings(this).fixPNG)helper.parent.unfixPNG();}$.fn.Tooltip=$.fn.tooltip;})(jQuery);
