sliderTimer = setInterval(function () {
    var b = jQuery("div#gc_main_top_slider");
    if (typeof (b.loopedSlider) == "function") {
        clearInterval(sliderTimer);
        b.loopedSlider({
            autoStart: 10000

        });
    }
}, 50);


if (typeof (jQuery) != "undefined") {
    jQuery(function (a) {
        a.fn.extend({
            loopedSlider: function (b) {
                var c = a.extend({}, a.fn.loopedSlider.defaults, b);
                return this.each(function () {
                    if (a.fn.jquery < "1.3.2") {
                        return
                    }
                    var t = a(this);
                    var k = a.metadata ? a.extend({}, c, t.metadata()) : c;
                    var f = 0;
                    var j = 1;
                    var n = a(k.slides, t).children().size();
                    var m = a(k.slides, t).children().outerWidth();
                    var v = 0;
                    var i = false;
                    var e = 0;
                    var u = 0;
                    var p = 0;
                    var r = a("." + k.pagination + " li a", t);
                    
                    if (k.addPagination && !a(r).length) 
                    {
                    	//TODO: add pagination support 
                    } 
                    else 
                    {
                        a(r, t).each(function () {
                            e = e + 1;
                            a(this).attr("rel", e);
                            a(r.eq(0), t).parent().addClass("active")
                        })
                    }
                    if (n === 1) {
                        a(k.slides, t).children().css({
                            position: "absolute",
                            left: v,
                            display: "block"
                        });
                        return
                    }
                    a(k.slides, t).css({
                        width: (n * m)
                    });
                    a(k.slides, t).children().each(function () {
                        a(this).css({
                            position: "absolute",
                            left: v,
                            display: "block"
                        });
                        v = v + m
                    });
                    a(k.slides, t).children(":eq(" + (n - 1) + ")").css({
                        position: "absolute",
                        left: -m
                    });
                    if (n > 3) {
                        a(k.slides, t).children(":eq(" + (n - 1) + ")").css({
                            position: "absolute",
                            left: -m
                        })
                    }
                    if (k.autoHeight) {
                        q(j)
                    }
                    a(".next", k.container).click(function () {
                    	if (i === false) {
                            h("next", true);
                            if (k.autoStart) {
                                if (k.restart) {
                                    g()
                                } else {
                                    clearInterval(sliderIntervalID)
                                }
                            }
                        }
                        return false
                    });
                    a(".previous", k.container).click(function () {
                        if (i === false) {
                            h("prev", true);
                            if (k.autoStart) {
                                if (k.restart) {
                                    g()
                                } else {
                                    clearInterval(sliderIntervalID)
                                }
                            }
                        }
                        return false
                    });
                    a(r, t).click(function () {
                        if (a(this).parent().hasClass("active")) {
                            return false
                        } else {
                            j = a(this).attr("rel");
                            a(r, t).parent().siblings().removeClass("active");
                            a(this).parent().addClass("active");
                            h("fade", j);
                            if (k.autoStart) {
                                if (k.restart) {
                                    g()
                                } else {
                                    clearInterval(sliderIntervalID)
                                }
                            }
                        }
                        return false
                    });
                    
                    a(".previous", t).hover(function () {
                        a(this).addClass("previous_hover")
                    }, function () {
                        a(this).removeClass("previous_hover")
                    });
                    a(".next", t).hover(function () {
                        a(this).addClass("next_hover")
                    }, function () {
                        a(this).removeClass("next_hover")
                    });
                    
                    if (k.autoStart) {
                        sliderIntervalID = setInterval(function () {
                            if (i === false) {
                                h("next", true)
                            }
                        }, k.autoStart);

                        function g() {
                            if (k.restart) {
                                clearInterval(sliderIntervalID);
                                clearInterval(u);
                                clearTimeout(p);
                                p = setTimeout(function () {
                                    u = setInterval(function () {
                                        h("next", true)
                                    }, k.autoStart)
                                }, k.restart)
                            } else {
                                sliderIntervalID = setInterval(function () {
                                    if (i === false) {
                                        h("next", true)
                                    }
                                }, k.autoStart)
                            }
                        }
                    }
                    function l(o) {
                        if (o === n + 1) {
                            o = 1
                        }
                        if (o === 0) {
                            o = n
                        }
                        a(r, t).parent().siblings().removeClass("active");
                        a(r + "[rel='" + (o) + "']", t).parent().addClass("active")
                    }
                    function q(w) {
                        if (w === n + 1) {
                            w = 1
                        }
                        if (w === 0) {
                            w = n
                        }
                        var o = a(k.slides, t).children(":eq(" + (w - 1) + ")", t).outerHeight();
                        a(k.container, t).animate({
                            height: o
                        }, k.autoHeight)
                    }
                    function d(o, y, x, w) {}
                    function h(o, w) {
                        i = true;
                        switch (o) {
                        case "next":
                            j = j + 1;
                            break;
                        case "prev":
                            j = j - 1;
                            break;
                        case "fade":
                            j = [j] * 1;
                            break;
                        default:
                            break
                        }
                        f = (-(j * m - m));
                        l(j);
                        if (k.autoHeight) {
                            q(j)
                        }
                        if (n < 3) {
                            if (j === 3) {
                                a(k.slides, t).children(":eq(0)").css({
                                    left: (n * m)
                                })
                            }
                            if (j === 2) {
                                a(k.slides, t).children(":eq(" + (n - 1) + ")").css({
                                    position: "absolute",
                                    left: m
                                })
                            }
                        }
                        if (j === 1) {
                            a(k.slides, t).children(":eq(0)").css({
                                left: 0
                            })
                        }
                        if (j === n) {
                            a(k.slides, t).children(":eq(" + (n - 1) + ")").css({
                                position: "absolute",
                                left: ((n - 1) * m)
                            })
                        }
                        if (j === 0) {
                            a(k.slides, t).children(":eq(" + (n - 1) + ")").css({
                                position: "absolute",
                                left: (-1) * m
                            })
                        }
                        a(k.slides, t).animate({
                            left: f
                        }, k.slidespeed, "easeInOutExpo", function () {
                            if (j === n + 1) {
                                j = 1;
                                a(k.slides, t).css({
                                    left: 0
                                }, function () {
                                    a(k.slides, t).animate({
                                        left: f
                                    })
                                });
                                a(k.slides, t).children(":eq(0)").css({
                                    left: 0
                                });
                                a(k.slides, t).children(":eq(" + (n - 1) + ")").css({
                                    position: "absolute",
                                    left: -m
                                })
                            }
                            if (j === 0) {
                                j = n;
                                a(k.slides, t).children(":eq(" + (n - 1) + ")").css({
                                    position: "absolute",
                                    left: (n * m - m)
                                });
                                a(k.slides, t).css({
                                    left: -(n * m - m)
                                });
                                a(k.slides, t).children(":eq(0)").css({
                                    left: (n * m)
                                })
                            }
                            if (j === n) {
                                a(k.slides, t).children(":eq(0)").css({
                                    left: (n * m)
                                })
                            }
                            if (j === n - 1) {
                                a(k.slides, t).children(":eq(" + (n - 1) + ")").css({
                                    left: (n * m - m)
                                })
                            }
                            i = false
                        })
                    }
                })
            }
        });
        
        jQuery.fn.loopedSlider.defaults = {
            container: "#gc_slider_container",
            slides: ".slides",
            containerClick: true,
            autoStart: 0,
            restart: 0,
            slidespeed: 1000,
            fadespeed: 200,
            autoHeight: 0,
            addPagination: true,
            videos: null,
            font: "Arial",
            color: "#990000"
        }
    })
}
jQuery.easing.jswing = jQuery.easing.swing;
jQuery.extend(jQuery.easing, {
    def: "easeOutQuad",
    easeInOutExpo: function (e, f, a, h, g) {
        if (f == 0) {
            return a
        }
        if (f == g) {
            return a + h
        }
        if ((f /= g / 2) < 1) {
            return h / 2 * Math.pow(2, 10 * (f - 1)) + a
        }
        return h / 2 * (-Math.pow(2, -10 * --f) + 2) + a
    }
});
