﻿(function ($) {
    jQuery.noConflict(); fusionHoverObj = function (t, opt) { this.defaults = { picWidth: 960, picHeight: 350, offset: 15, speed: 1000, easing: null, wrapClass: null, animationEnter: 'fade', animationLeave: 'fade', layers: null, layersCSS: { image: 'fhover/shadow.png', speed: 500, target: null, enter: 'fade-in', leave: 'fade-out', position: 'top-left', css: { width: '100%', height: '100%', border: 'none', opacity: 1} }, skin: 'default' }; this.wrap; this.offset_w = 0; this.vhe = 0; this.vwi = 0; this.options = {}; this.container = $(t); this.loadReady = false; this.layers = []; this.startTop = 0; this.startLeft = 0; this.options = $.extend(true, this.defaults, opt); this.INITbrowserCheck(); }; $.extend(fusionHoverObj.prototype, { version: "2.0", INITbrowserCheck: function () {
        var t = this; var c = this.container; if ($.browser.mozilla) { c.ready(function () { t.loadImageStuff(c); }); }
        else if ($.browser.webkit) { c.ready(function () { t.loadImageStuff(c); }); c.load(function () { if (t.loadReady == false) { t.loadImageStuff(c); } }); }
        else if ($.browser.opera) { c.ready(function () { t.loadImageStuff(c); }); }
        else if ($.browser.msie) { c.ready(function () { t.loadImageStuff(c); }); }
        else { c.ready(function () { t.loadImageStuff(c); }); } 
    }, setCoords: function (layer) {
        var t = this; var w = this.wrap; var c = this.container; layer.data("startTop", 0).data("startLeft", 0).data("leaveTop", 0).data("leaveLeft", 0).data("posTop", 0).data("posLeft", 0); switch (layer.data('options').position) { case 'bottom': case 'bottom-left': layer.data("posTop", (w.height() - layer.height())); layer.data("posLeft", 0); break; case 'top': case 'left': case 'top-left': layer.data("posTop", 0); layer.data("posLeft", 0); break; case 'bottom-right': layer.data("posTop", (w.height() - layer.height())); layer.data("posLeft", (w.width() - layer.width())); break; case 'top-right': layer.data("posTop", 0); layer.data("posLeft", (w.width() - layer.width())); break; case 'center': layer.data("posTop", ((w.height() / 2) - (layer.height() / 2))); layer.data("posLeft", ((w.width() / 2) - (layer.width() / 2))); layer.data("startTop", ((w.height() / 2) - (layer.height() / 2))); layer.data("startLeft", ((w.width() / 2) - (layer.width() / 2))); layer.data("leaveTop", ((w.height() / 2) - (layer.height() / 2))); layer.data("leaveLeft", ((w.width() / 2) - (layer.width() / 2))); break; }
        switch (layer.data('options').enter) { case 'bottom': layer.data("startTop", (w.height() + 50)); layer.data("startLeft", layer.data("posLeft")); break; case 'top': layer.data("startTop", (-1) * (w.height() + 50)); layer.data("startLeft", layer.data("posLeft")); break; case 'left': layer.data("startLeft", (-1) * (w.width() + 50)); layer.data("startTop", layer.data("posTop")); break; case 'right': layer.data("startLeft", (w.width() + 50)); layer.data("startTop", layer.data("posTop")); break; case 'top-right': layer.data("startTop", (-1) * (w.height() + 50)); layer.data("startLeft", (w.width() + 50)); break; case 'top-left': layer.data("startTop", (-1) * (w.height() + 50)); layer.data("startLeft", (-1) * (w.width() + 50)); break; case 'bottom-right': layer.data("startTop", (w.height() + 50)); layer.data("startLeft", (w.width() + 50)); break; case 'bottom-left': layer.data("startTop", (w.height() + 50)); layer.data("startLeft", (-1) * (w.width() + 50)); break; case 'fade-in': layer.data("startTop", layer.data("posTop")); layer.data("startLeft", layer.data("posLeft")); break; }
        switch (layer.data('options').leave) { case 'bottom': layer.data("leaveTop", (w.height() + 50)); layer.data("leaveLeft", layer.data("posLeft")); break; case 'top': layer.data("leaveTop", (-1) * (w.height() + 50)); layer.data("leaveLeft", layer.data("posLeft")); break; case 'left': layer.data("leaveTop", layer.data("posTop")); layer.data("leaveLeft", (-1) * (w.width() + 50)); break; case 'right': layer.data("leaveTop", layer.data("posTop")); layer.data("leaveLeft", (w.width() + 50)); break; case 'top-right': layer.data("leaveTop", (-1) * (w.height() + 50)); layer.data("leaveLeft", (w.width() + 50)); break; case 'top-left': layer.data("leaveTop", (-1) * (w.height() + 50)); layer.data("leaveLeft", (-1) * (w.width() + 50)); break; case 'bottom-right': layer.data("leaveTop", (w.height() + 50)); layer.data("leaveLeft", (w.width() + 50)); break; case 'bottom-left': layer.data("leaveTop", (w.height() + 50)); layer.data("leaveLeft", (-1) * (w.width() + 50)); break; case 'fade-out': layer.data("leaveTop", layer.data("posTop")); layer.data("leaveLeft", layer.data("posLeft")); break; } 
    }, loadImageStuff: function (t) {
        var t = this; var c = t.container; t.loadReady = true; c.css({ 'position': 'relative', 'overflow': 'hidden' }).after('<div class="fhover_' + t.options.skin + '_wrap">').appendTo(c.next('.fhover_' + t.options.skin + '_wrap')); t.wrap = c.parents('.fhover_' + t.options.skin + '_wrap'); var height_touse = (c.height() > 0) ? c.css('height') : t.options.picHeight; var width_touse = (c.width() > 0) ? c.css('width') : t.options.picWidth; t.wrap.css({ height: height_touse, width: c.css('width') }).addClass(t.options.wrapClass); for (var i in t.options.layers) {
            if (typeof (t.options.layers[i].image) === 'undefined') {
                var selector = t.options.layers[i].target.selector; if (t.wrap.parent().find(selector).length) {
                    t.layers[i] = t.wrap.parent().find(selector).clone().appendTo(t.wrap); t.layers[i].data('type', 'div'); var new_options = $.extend({}, t.options.layersCSS, t.options.layers[i]); t.layers[i].data('options', new_options); if (typeof (t.layers[i].data('options').css.height) === 'undefined') { t.layers[i].data('options').css.height = t.options.layersCSS.css.height; }
                    if (typeof (t.layers[i].data('options').css.width) === 'undefined') { t.layers[i].data('options').css.width = t.options.layersCSS.css.width; }
                    t.layers[i].css({ height: t.layers[i].data('options').css.height, width: t.layers[i].data('options').css.width }); t.setCoords(t.layers[i]);
                } 
            }
            else {
                t.layers[i] = $('<img>', { "class": "fhover_" + t.options.skin + "_shadow", "src": t.options.layers[i].image, "css": { "height": t.options.layers[i].css.height, "width": t.options.layers[i].css.width} }).appendTo(this.wrap); t.layers[i].data('type', 'img'); var new_options = $.extend({}, t.options.layersCSS, t.options.layers[i]); t.layers[i].data('options', new_options); if (typeof (t.layers[i].data('options').css.height) === 'undefined') { t.layers[i].data('options').css.height = t.options.layersCSS.css.height; }
                if (typeof (t.layers[i].data('options').css.width) === 'undefined') { t.layers[i].data('options').css.width = t.options.layersCSS.css.width; }
                t.layers[i].css({ height: t.layers[i].data('options').css.height, width: t.layers[i].data('options').css.width }); t.setCoords(t.layers[i]);
            } 
        }
        t.offset_w = c.width() * (t.options.offset / c.height()); t.vhe = (parseInt(t.wrap.css('height').replace('px', ''), 10) + (t.options.offset * 2)); t.vwi = (parseInt(t.wrap.css('width').replace('px', ''), 10) + (t.offset_w * 2)); c.css({ width: t.vwi, height: t.vhe, 'left': '-' + t.offset_w + 'px', 'top': '-' + t.options.offset + 'px' }); t.setEvents();
    }, setEvents: function () {
        var t = this; var c = t.container; var w = t.wrap; w.mouseenter(function () {
            c.stop().animate({ height: t.wrap.css('height'), width: t.wrap.css('width'), 'top': '0px', 'left': '0px' }, t.options.speed, t.options.easing); for (var i in t.options.layers) {
                if (typeof (t.options.layers[i].image) === 'undefined') {
                    t.layers[i].css({ 'top': t.layers[i].data('startTop'), 'left': t.layers[i].data('startLeft') }); if (($.browser.msie) && ($.browser.version <= 8)) { t.layers[i].css({ 'filter': 'alpha(opacity=' + t.layers[i].data('options').css.opacity * 100 + ')', '-ms-filter': 'Alpha(opacity=' + t.layers[i].data('options').css.opacity * 100 + ')' }).fadeIn(t.layers[i].data('options').speed); t.layers[i].animate({ 'top': t.layers[i].data('posTop'), 'left': t.layers[i].data('posLeft') }, t.layers[i].data('options').speed, function () { }); }
                    else { t.layers[i].show().stop().animate({ 'top': t.layers[i].data('posTop'), 'left': t.layers[i].data('posLeft'), opacity: t.layers[i].data('options').css.opacity, 'filter': 'alpha(opacity=80)', '-ms-filter': 'Alpha(opacity=80)' }, t.layers[i].data('options').speed, function () { }); } 
                }
                else {
                    if (($.browser.msie) && ($.browser.version <= 8)) { t.layers[i].css({ 'filter': 'alpha(opacity=' + t.layers[i].data('options').css.opacity * 100 + ')', '-ms-filter': 'Alpha(opacity=' + t.layers[i].data('options').css.opacity * 100 + ')' }).fadeIn(t.layers[i].data('options').speed); }
                    else { t.layers[i].show().stop().animate({ opacity: t.layers[i].data('options').css.opacity, 'filter': 'alpha(opacity=' + t.layers[i].data('options').css.opacity * 100 + ')', '-ms-filter': 'Alpha(opacity=' + t.layers[i].data('options').css.opacity * 100 + ')' }, t.layers[i].data('options').speed, function () { }); } 
                } 
            } 
        }); w.mouseleave(function () {
            c.stop().animate({ height: t.vhe, width: t.vwi, 'top': '-' + t.options.offset + 'px', 'left': '-' + t.offset_w + 'px' }, t.options.speed, t.options.easing); for (var i in t.options.layers) {
                if (typeof (t.options.layers[i].image) === 'undefined') {
                    if (($.browser.msie) && ($.browser.version <= 8)) { t.layers[i].fadeOut(500); t.layers[i].animate({ 'top': t.layers[i].data('leaveTop'), 'left': t.layers[i].data('leaveLeft') }, t.layers[i].data('options').speed, function () { }); }
                    else { t.layers[i].animate({ 'top': t.layers[i].data('leaveTop'), 'left': t.layers[i].data('leaveLeft'), opacity: 0, 'filter': 'alpha(opacity=0)', '-ms-filter': 'Alpha(opacity=0)' }, t.layers[i].data('options').speed, function () { }); } 
                }
                else {
                    if (($.browser.msie) && ($.browser.version <= 8)) { t.layers[i].fadeOut(500); }
                    else { t.layers[i].show().stop().animate({ opacity: 0, 'filter': 'alpha(opacity=0)', '-ms-filter': 'Alpha(opacity=0)' }, t.options.speed, function () { }); } 
                } 
            } 
        });
    } 
    }); $.fn.fusionHover = function (opt) { $(this).each(function () { new fusionHoverObj($(this), opt); }); };
})(jQuery);
