﻿/*!
 * Accordion Gallery
 *
 * Copyright 2011,
 * Licensed under the flcomponents.net license
 * http://flcomponents.net

 */
(function (a) {
    a.fn.FLCAccordion = function (p) {
        var o = a.extend({}, a.fn.FLCAccordion.defaults, p);
        var m = "Can not load configuration XML, please check the path.";
        var g = this.selector;
        var j = 0;
        var h = false;
        jQuery.extend(jQuery.easing, {
            easeOutBounce: function (v, w, y, z, i) {
                if ((w /= i) < (1 / 2.75)) {
                    return z * (7.5625 * w * w) + y
                } else {
                    if (w < (2 / 2.75)) {
                        return z * (7.5625 * (w -= (1.5 / 2.75)) * w + 0.75) + y
                    } else {
                        if (w < (2.5 / 2.75)) {
                            return z * (7.5625 * (w -= (2.25 / 2.75)) * w + 0.9375) + y
                        } else {
                            return z * (7.5625 * (w -= (2.625 / 2.75)) * w + 0.984375) + y
                        }
                    }
                }
            },
            easeInOutBounce: function (C, w, y, z, D) {
                var i = 1.70158;
                var v = 0;
                var B = z;
                if (w == 0) {
                    return y
                }
                if ((w /= D / 2) == 2) {
                    return y + z
                }
                if (!v) {
                    v = D * (0.3 * 1.5)
                }
                if (B < Math.abs(z)) {
                    B = z;
                    var i = v / 4
                } else {
                    i = v / (2 * Math.PI) * Math.asin(z / B)
                }
                if (w < 1) {
                    return -0.5 * (B * Math.pow(2, 10 * (w -= 1)) * Math.sin((w * D - i) * (2 * Math.PI) / v)) + y
                }
                return B * Math.pow(2, -10 * (w -= 1)) * Math.sin((w * D - i) * (2 * Math.PI) / v) * 0.5 + z + y
            }
        });
        accordion = new Div("container");
        accordion.AddInlineStyle("position", "relative");
        ul = new Ul();
        accordion.AddChild(ul);
        var e = null;
        var d = 0;
        var u;
        if (o.htmlConfig == true) {
            e = a(g + " ul");
            u = a(e).find("li").length;
            l(e)
        } else {
            a.ajax({
                type: "GET",
                url: o.assetsPath + "/data.xml",
                dataType: "xml",
                success: function (i) {
                    u = a(i).find("li").length;
                    l(a(i))
                },
                error: function (i, w, v) {
                    alert(m)
                }
            })
        }
        function l(i) {
            i.find("li").each(function () {
                var B;
                var z;
                var x;
                var w;
                var v;
                B = jQuery.trim(a(this).find("img").attr("src"));
                if (o.htmlConfig) {
                    z = a.trim(a(this).find('div.posleft').html());
                    x = a.trim(a(this).find('div.posbottom > p').html());
                    w = a.trim(a(this).find('a[name="link"]').attr("href"))
                } else {
                    z = a(this).find('div.posleft').text();
                    x = a(this).find('div.posbottom').text();
                    w = a(this).find('a[name="link"]').attr("href")
                }
                v = jQuery.trim(a(this).find('a[name="link"]').attr("target"));
                li = new Li();
                ul.AddChild(li);
                divTitle = new Div();
                divTitle.AddAttributesWithValue("class", "title");
                divTitle.AddHtml(z);
                if (o.showLeftText == true) {
                    li.AddChild(divTitle)
                }
                divItem = new Div();
                divItem.AddAttributesWithValue("class", "item");
                li.AddChild(divItem);
                divBottomText = new Div();
                divBottomText.AddAttributesWithValue("class", "bottom-text");
                divBottomText.AddHtml(x);
                if (o.showBottomText == true) {
                    divItem.AddChild(divBottomText)
                }
                image = new Img();
                image.AddAttributesWithValue("src", B);
                if (w != "") {
                    var y = new A();
                    y.AddAttributesWithValue("href", w);
                    if (v != "undefined" && v != "") {
                        y.AddAttributesWithValue("target", v)
                    }
                    divItem.AddChild(y);
                    y.AddChild(image)
                } else {
                    divItem.AddChild(image)
                }
                if (d == u - 1) {
                    li.AddAttributesWithValue("class", "last");
                    li.AddInlineStyle("border-right", "none")
                }
                d++
            });
            q(u)
        }
        function q(i) {
            var v = 0;
            v = (o.galleryWidth / i) - 1;
            j = (o.galleryWidth - o.pictureWidth) / (i - 1) - 1;
            var w = '<style type="text/css">' + g + " .title{width:" + o.galleryHeight + "px;height:30px;background-color:" + o.backgroundColor + ';-moz-transform-origin:0 0;-webkit-transform-origin:0 0;-webkit-transform:rotate(-90deg);-moz-transform:rotate(-90deg);color:#fff;font-size:15px;text-align:center;vertical-align:middle;position:absolute;bottom:-30px;left:0;line-height:30px;font-family:Arial}</style> <!--[if IE]><style type="text/css"> .title {top:0;filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);}</style><![endif]--> <style type="text/css"> ' + g + "{position:relative;width:" + o.galleryWidth + "px;height:" + o.galleryHeight + "px;background-color:#000;font-size:16px;overflow:hidden}" + g + " ul{width:" + o.galleryWidth + "px;height:" + o.galleryHeight + "px;margin:0;padding:0}" + g + " li{float:left;height:" + o.galleryHeight + "px;width:" + v + "px;list-style:none;border-right:solid 1px " + o.borderColor + ";position:relative;overflow:hidden}" + g + " li .item{height:" + o.galleryHeight + "px;width:" + o.pictureWidth + "px;position:absolute}" + g + " li img{height:" + o.galleryHeight + "px;width:" + o.pictureWidth + "px; border-width:0;}.last{overflow:visible!important;overflow-x:visible!important;overflow-y:visible!important}" + g + " .bottom-text{background-color:#000;width:" + (o.pictureWidth - 20) + "px;padding:5px 10px 5px 10px; text-align:justify;font-family:Arial;color:#fff;font-weight:400;font-size:14px;position:absolute;bottom:-100px}</style>";
            a("head").append(w);
            if (e != null) {
                e.remove()
            }
            fl = new FLCObject();
            fl.Render(g, accordion);
            a(g + " .item").fadeTo(0, o.imagesOpacity, function () {});
            a(g + " .bottom-text").fadeTo(0, o.bottomTextOpacity, function () {});
            if (!o.autoPlay) {
                s(g)
            } else {
                a(g + " ").mouseenter(function () {
                    h = true;
                    o.autoPlay = false;
                    s(g)
                });
                a(g + " ").mouseleave(function () {
                    h = false;
                    o.autoPlay = true
                })
            }
        }
        function s(i) {
            if (o.eventType == "over") {
                a(i + "  li").mouseenter(function () {
                    b(i, this)
                })
            }
            if (o.eventType == "click") {
                a(i + "  li").click(function () {
                    b(i, this)
                })
            }
            a(i + "  .item").mouseenter(function () {
                r(this)
            });
            a(i + " ").mouseleave(function () {
                a(i + "  li").animate({
                    width: slideWidth
                }, {
                    duration: o.animationTime,
                    queue: false,
                    easing: "swing",
                    complete: function () {}
                })
            });
            a(i + "  .item").mouseleave(function () {
                f(this)
            })
        }
        function b(i, v) {
            var w = v;
            a(i + "  li").animate({
                width: j
            }, {
                duration: o.animationTime,
                queue: false,
                easing: "swing",
                complete: function () {}
            });
            a(w).find(".bottom-text").animate({
                bottom: 10
            }, {
                duration: 1200,
                queue: false,
                easing: "easeInOutBounce"
            });
            a(w).animate({
                width: o.pictureWidth
            }, {
                duration: o.animationTime,
                queue: false,
                easing: "swing",
                complete: function () {}
            })
        }
        function r(i) {
            var v = i;
            a(v).fadeTo(o.animationTime, 1, function () {
                a(v).clearQueue()
            })
        }
        function f(i) {
            var v = i;
            a(v).find(".bottom-text").animate({
                bottom: -a(v).find(".bottom-text").height() - 15
            }, {
                duration: 1200,
                queue: false,
                easing: "easeInOutBounce"
            });
            a(v).fadeTo(o.animationTime, o.imagesOpacity, function () {
                a(v).clearQueue()
            })
        }
        var k = 0;
        var t = a(g + "  li");
        var c = a(g + "  .item");

        function n() {
            if (!h) {
                if (o.switchOrder == "ltr") {
                    if (k != 0) {
                        f(c[k - 1])
                    } else {
                        f(c[u - 1])
                    }
                    b(g, t[k]);
                    r(c[k]);
                    k++;
                    if (k == u) {
                        k = 0
                    }
                }
                if (o.switchOrder == "rtl") {
                    k++;
                    if (k != 1) {
                        f(c[u - k + 1])
                    } else {
                        f(c[0])
                    }
                    b(g, t[u - k]);
                    r(c[u - k]);
                    if (k == u) {
                        k = 0
                    }
                }
            }
            setTimeout(n, o.switchTime * 1000)
        }
        if (o.autoPlay) {
            n()
        }
    };
    a.fn.FLCAccordion.defaults = {
        galleryWidth: 600,
        galleryHeight: 400,
        pictureWidth: 300,
        backgroundColor: "#222",
        borderColor: "#9999aa",
        imagesOpacity: 0.5,
        bottomTextOpacity: 0.6,
        eventType: "over",
        showLeftText: true,
        showBottomText: true,
        animationTime: 600,
        assetsPath: "assets",
        htmlConfig: true,
        autoPlay: false,
        switchTime: 2,
        switchOrder: "ltr"
    }
})(jQuery);

function FLCObject() {}
FLCObject.prototype.Render = function (a, b) {
    $(a).append(b.Definition)
};

function Element() {
    this.Definition = null
}
Element.prototype.AddChild = function (a) {
    this.Definition.append(a.Definition)
};
Element.prototype.AddAttributesWithValue = function (b, a) {
    this.Definition.attr(b, a)
};
Element.prototype.AddText = function (a) {
    this.Definition.text(a)
};
Element.prototype.AddHtml = function (a) {
    this.Definition.html(this.Definition.html() + a)
};
Element.prototype.AddInlineStyle = function (a, b) {
    this.Definition.css(a, b)
};
Element.prototype.Html = function (a) {
    this.Definition = $(a)
};
Div.prototype = new Element;
Div.prototype.constructor = Div;

function Div(a) {
    this.Definition = $("<div></div>");
    if (a != "undefined") {}
    this.Definition.attr("Id", a)
}
Ul.prototype = new Element;
Ul.prototype.constructor = Ul;

function Ul(a) {
    this.Definition = $("<ul></ul>");
    if (this.Id != "undefined") {}
    this.Definition.attr("Id", a)
}
Li.prototype = new Element;
Li.prototype.constructor = Li;

function Li(a) {
    this.Definition = $("<li></li>");
    if (this.Id != "undefined") {}
    this.Definition.attr("Id", a)
}
P.prototype = new Element;
P.prototype.constructor = P;

function P(a) {
    this.Definition = $("<p></p>");
    if (this.Id != "undefined") {}
    this.Definition.attr("Id", a)
}
Img.prototype = new Element;
Img.prototype.constructor = Img;

function Img(c, b, a) {
    this.Definition = $("<Img/>");
    if (this.Id != "undefined") {}
    this.Definition.attr("Id", c);
    this.Definition.attr("src", b);
    this.Definition.attr("alt", a)
}
A.prototype = new Element;
A.prototype.constructor = A;

function A(a) {
    this.Definition = $("<a></a>");
    if (this.Id != "undefined") {}
    this.Definition.attr("Id", a)
}
YT.prototype = new Element;
YT.prototype.constructor = YT;

function YT(c, d, b, a) {
    if (typeof a == "undefined") {
        a = ""
    }
    if (typeof d == "undefined") {
        d = 640
    }
    if (typeof b == "undefined") {
        b = 480
    }
    if (typeof c == "undefined") {
        c = "jnEqyBofZzM"
    }
    var e = '<!--[if IE ]><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"  width="' + d + '" height="' + b + '" id="' + a + '"><param name="movie" value="http://www.youtube.com/e/' + c + '?enablejsapi=1&version=3&playerapiid=ytplayer" /><param name="allowScriptAccess" value="always"/><![endif]--><!--[if !IE]>--><object id="' + a + '" type="application/x-shockwave-flash" data="http://www.youtube.com/e/' + c + '?enablejsapi=1&version=3&playerapiid=ytplayer" width="' + d + '" height="' + b + '" allowScriptAccess="always"><!--<![endif]--><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a><!--[if !IE]>--></object><!--<![endif]-->';
    this.Definition = $(e)
}
function FLCObject() {}
FLCObject.prototype.Render = function (a, b) {
    $(a).append(b.Definition)
};

function Element() {
    this.Definition = null
}
Element.prototype.AddChild = function (a) {
    this.Definition.append(a.Definition)
};
Element.prototype.AddAttributesWithValue = function (b, a) {
    this.Definition.attr(b, a)
};
Element.prototype.AddText = function (a) {
    this.Definition.text(a)
};
Element.prototype.AddHtml = function (a) {
    this.Definition.html(this.Definition.html() + a)
};
Element.prototype.AddInlineStyle = function (a, b) {
    this.Definition.css(a, b)
};
Element.prototype.Html = function (a) {
    this.Definition = $(a)
};
Div.prototype = new Element;
Div.prototype.constructor = Div;

function Div(a) {
    this.Definition = $("<div></div>");
    if (a != "undefined") {}
    this.Definition.attr("Id", a)
}
Ul.prototype = new Element;
Ul.prototype.constructor = Ul;

function Ul(a) {
    this.Definition = $("<ul></ul>");
    if (this.Id != "undefined") {}
    this.Definition.attr("Id", a)
}
Li.prototype = new Element;
Li.prototype.constructor = Li;

function Li(a) {
    this.Definition = $("<li></li>");
    if (this.Id != "undefined") {}
    this.Definition.attr("Id", a)
}
P.prototype = new Element;
P.prototype.constructor = P;

function P(a) {
    this.Definition = $("<p></p>");
    if (this.Id != "undefined") {}
    this.Definition.attr("Id", a)
}
Img.prototype = new Element;
Img.prototype.constructor = Img;

function Img(c, b, a) {
    this.Definition = $("<Img/>");
    if (this.Id != "undefined") {}
    this.Definition.attr("Id", c);
    this.Definition.attr("src", b);
    this.Definition.attr("alt", a)
}
A.prototype = new Element;
A.prototype.constructor = A;

function A(a) {
    this.Definition = $("<a></a>");
    if (this.Id != "undefined") {}
    this.Definition.attr("Id", a)
}
YT.prototype = new Element;
YT.prototype.constructor = YT;

function YT(c, d, b, a) {
    if (typeof a == "undefined") {
        a = ""
    }
    if (typeof d == "undefined") {
        d = 640
    }
    if (typeof b == "undefined") {
        b = 480
    }
    if (typeof c == "undefined") {
        c = "jnEqyBofZzM"
    }
    var e = '<!--[if IE ]><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"  width="' + d + '" height="' + b + '" id="' + a + '"><param name="movie" value="http://www.youtube.com/e/' + c + '?enablejsapi=1&version=3&playerapiid=ytplayer" /><param name="wmode" value="transparent"/><param name="allowScriptAccess" value="always"/><![endif]--><!--[if !IE]>--><object id="' + a + '" type="application/x-shockwave-flash" data="http://www.youtube.com/e/' + c + '?enablejsapi=1&version=3&playerapiid=ytplayer" width="' + d + '" height="' + b + '" allowScriptAccess="always" wmode="transparent"><!--<![endif]--><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a><!--[if !IE]>--></object><!--<![endif]-->';
    this.Definition = $(e)
};
