var q = jQuery.noConflict();
q(document).ready(function () {
    q("ul.subnav").parent().append("<span></span>");
    q("ul.nav_left li span, ul.nav_right li span, ul.nav_left li a, ul.nav_right li a").click(function () {
        q(this).parent().find("ul.subnav").slideDown('fast').show();
        q(this).parent().hover(function () {}, function () {
            q(this).parent().find("ul.subnav").slideUp('slow')
        });
    }).hover(function () {
        q(this).addClass("subhover")
    }, 
	function () {
        q(this).removeClass("subhover")
    })
});

var z = jQuery.noConflict();
z(document).ready(function () {
    z(".facebook img").hover(function () {
        this.src = this.src.replace("_off", "_on")
    }, function () {
        this.src = this.src.replace("_on", "_off")
    });
    z(".twitter img").hover(function () {
        this.src = this.src.replace("_off", "_on")
    }, function () {
        this.src = this.src.replace("_on", "_off")
    });
    z(".urban img").hover(function () {
        this.src = this.src.replace("_off", "_on")
    }, function () {
        this.src = this.src.replace("_on", "_off")
    })
});
var p = jQuery.noConflict();
p(document).ready(function () {
    p(".tab_content").hide();
    p("ul.tabs li:first").addClass("active").show();
    p(".tab_content:first").show();
    p("ul.tabs li").click(function () {
        p("ul.tabs li").removeClass("active");
        p(this).addClass("active");
        p(".tab_content").hide();
        var b = p(this).find("a").attr("href");
        p(b).fadeIn();
        return false
    })
});
var j = jQuery.noConflict();
j(document).ready(function () {
    j("#slide_show").coinslider()
});
(function (x) {
    var y = new Array;
    var B = new Array;
    var t = new Array;
    var r = new Array;
    var A = new Array;
    var v = new Array;
    var C = new Array;
    var w = new Array;
    var s = new Array;
    var D = new Array;
    var u = new Array;
    x.fn.coinslider = x.fn.CoinSlider = function (a) {
        init = function (b) {
            B[b.id] = new Array();
            t[b.id] = new Array();
            r[b.id] = new Array();
            A[b.id] = new Array();
            v[b.id] = new Array();
            w[b.id] = 0;
            D[b.id] = 0;
            u[b.id] = 1;
            y[b.id] = x.extend({}, x.fn.coinslider.defaults, a);
            x.each(x("#" + b.id + " img"), function (d, c) {
                t[b.id][d] = x(c).attr("src");
                r[b.id][d] = x(c).parent().is("a") ? x(c).parent().attr("href") : "";
                A[b.id][d] = x(c).parent().is("a") ? x(c).parent().attr("target") : "";
                v[b.id][d] = x(c).next().is("span") ? x(c).next().html() : "";
                x(c).hide();
                x(c).next().hide()
            });
            x(b).css({
                "background-image": "url(" + t[b.id][0] + ")",
                width: y[b.id].width,
                height: y[b.id].height,
                position: "relative",
                "background-position": "top left"
            }).wrap("<div class='coin-slider' id='coin-slider-" + b.id + "' />");
            x("#" + b.id).append("<div class='cs-title' id='cs-title-" + b.id + "' style='position: absolute; bottom:0; left: 0; z-index: 1000;'></div>");
            x.setFields(b);
            if (y[b.id].navigation) {
                x.setNavigation(b)
            }
            x.transition(b, 0);
            x.transitionCall(b)
        };
        x.setFields = function (b) {
            tWidth = sWidth = parseInt(y[b.id].width / y[b.id].spw);
            tHeight = sHeight = parseInt(y[b.id].height / y[b.id].sph);
            counter = sLeft = sTop = 0;
            tgapx = gapx = y[b.id].width - y[b.id].spw * sWidth;
            tgapy = gapy = y[b.id].height - y[b.id].sph * sHeight;
            for (i = 1; i <= y[b.id].sph; i++) {
                gapx = tgapx;
                if (gapy > 0) {
                    gapy--;
                    sHeight = tHeight + 1
                } else {
                    sHeight = tHeight
                }
                for (j = 1; j <= y[b.id].spw; j++) {
                    if (gapx > 0) {
                        gapx--;
                        sWidth = tWidth + 1
                    } else {
                        sWidth = tWidth
                    }
                    B[b.id][counter] = i + "" + j;
                    counter++;
                    if (y[b.id].links) {
                        x("#" + b.id).append("<a href='" + r[b.id][0] + "' class='cs-" + b.id + "' id='cs-" + b.id + i + j + "' style='width:" + sWidth + "px; height:" + sHeight + "px; float: left; position: absolute;'></a>")
                    } else {
                        x("#" + b.id).append("<div class='cs-" + b.id + "' id='cs-" + b.id + i + j + "' style='width:" + sWidth + "px; height:" + sHeight + "px; float: left; position: absolute;'></div>")
                    }
                    x("#cs-" + b.id + i + j).css({
                        "background-position": -sLeft + "px " + (-sTop + "px"),
                        left: sLeft,
                        top: sTop
                    });
                    sLeft += sWidth
                }
                sTop += sHeight;
                sLeft = 0
            }
            x(".cs-" + b.id).mouseover(function () {
                x("#cs-navigation-" + b.id).show()
            });
            x(".cs-" + b.id).mouseout(function () {
                x("#cs-navigation-" + b.id).hide()
            });
            x("#cs-title-" + b.id).mouseover(function () {
                x("#cs-navigation-" + b.id).show()
            });
            x("#cs-title-" + b.id).mouseout(function () {
                x("#cs-navigation-" + b.id).hide()
            });
            if (y[b.id].hoverPause) {
                x(".cs-" + b.id).mouseover(function () {
                    y[b.id].pause = true
                });
                x(".cs-" + b.id).mouseout(function () {
                    y[b.id].pause = false
                });
                x("#cs-title-" + b.id).mouseover(function () {
                    y[b.id].pause = true
                });
                x("#cs-title-" + b.id).mouseout(function () {
                    y[b.id].pause = false
                })
            }
        };
        x.transitionCall = function (b) {
            clearInterval(C[b.id]);
            delay = y[b.id].delay + y[b.id].spw * y[b.id].sph * y[b.id].sDelay;
            C[b.id] = setInterval(function () {
                x.transition(b)
            }, delay)
        };
        x.transition = function (c, b) {
            if (y[c.id].pause == true) {
                return
            }
            x.effect(c);
            D[c.id] = 0;
            s[c.id] = setInterval(function () {
                x.appereance(c, B[c.id][D[c.id]])
            }, y[c.id].sDelay);
            x(c).css({
                "background-image": "url(" + t[c.id][w[c.id]] + ")"
            });
            if (typeof(b) == "undefined") {
                w[c.id]++
            } else {
                if (b == "prev") {
                    w[c.id]--
                } else {
                    w[c.id] = b
                }
            }
            if (w[c.id] == t[c.id].length) {
                w[c.id] = 0
            }
            if (w[c.id] == -1) {
                w[c.id] = t[c.id].length - 1
            }
            x(".cs-button-" + c.id).removeClass("cs-active");
            x("#cs-button-" + c.id + "-" + (w[c.id] + 1)).addClass("cs-active");
            if (v[c.id][w[c.id]]) {
                x("#cs-title-" + c.id).css({
                    opacity: 0
                }).animate({
                    opacity: y[c.id].opacity
                }, y[c.id].titleSpeed);
                x("#cs-title-" + c.id).html(v[c.id][w[c.id]])
            } else {
                x("#cs-title-" + c.id).css("opacity", 0)
            }
        };
        x.appereance = function (b, c) {
            x(".cs-" + b.id).attr("href", r[b.id][w[b.id]]).attr("target", A[b.id][w[b.id]]);
            if (D[b.id] == y[b.id].spw * y[b.id].sph) {
                clearInterval(s[b.id]);
                return
            }
            x("#cs-" + b.id + c).css({
                opacity: 0,
                "background-image": "url(" + t[b.id][w[b.id]] + ")"
            });
            x("#cs-" + b.id + c).animate({
                opacity: 1
            }, 300);
            D[b.id]++
        };
        x.setNavigation = function (b) {
            x(b).append("<div id='cs-navigation-" + b.id + "'></div>");
            x("#cs-navigation-" + b.id).hide();
            x("#cs-navigation-" + b.id).append("<a href='#' id='cs-prev-" + b.id + "' class='cs-prev'>&nbsp;</a>");
            x("#cs-navigation-" + b.id).append("<a href='#' id='cs-next-" + b.id + "' class='cs-next'>&nbsp;</a>");
            x("#cs-prev-" + b.id).css({
                position: "absolute",
                top: "271px",
                left: "357px",
                "z-index": 1001,
                "line-height": "30px",
                opacity: y[b.id].opacity
            }).click(function (c) {
                c.preventDefault();
                x.transition(b, "prev");
                x.transitionCall(b)
            }).mouseover(function () {
                x("#cs-navigation-" + b.id).show()
            });
            x("#cs-next-" + b.id).css({
                position: "absolute",
                top: "271px",
                right: "355px",
                "z-index": 1001,
                "line-height": "30px",
                opacity: y[b.id].opacity
            }).click(function (c) {
                c.preventDefault();
                x.transition(b);
                x.transitionCall(b)
            }).mouseover(function () {
                x("#cs-navigation-" + b.id).show()
            });
            x("<div id='cs-buttons-" + b.id + "' class='cs-buttons'></div>").appendTo(x("#coin-slider-" + b.id));
            for (k = 1; k < t[b.id].length + 1; k++) {
                x("#cs-buttons-" + b.id).append("<a href='#' class='cs-button-" + b.id + "' id='cs-button-" + b.id + "-" + k + "'>" + k + "</a>")
            }
            x.each(x(".cs-button-" + b.id), function (d, c) {
                x(c).click(function (e) {
                    x(".cs-button-" + b.id).removeClass("cs-active");
                    x(this).addClass("cs-active");
                    e.preventDefault();
                    x.transition(b, d);
                    x.transitionCall(b)
                })
            });
            x("#cs-navigation-" + b.id + " a").mouseout(function () {
                x("#cs-navigation-" + b.id).hide();
                y[b.id].pause = false
            });
            x("#cs-buttons-" + b.id).css({
                left: "48%",
                "margin-left": -t[b.id].length * 15 / 2 - 5,
                position: "relative"
            })
        };
        x.effect = function (b) {
            effA = ["random", "swirl", "rain", "straight"];
            if (y[b.id].effect == "") {
                eff = effA[Math.floor(Math.random() * (effA.length))]
            } else {
                eff = y[b.id].effect
            }
            B[b.id] = new Array();
            if (eff == "random") {
                counter = 0;
                for (i = 1; i <= y[b.id].sph; i++) {
                    for (j = 1; j <= y[b.id].spw; j++) {
                        B[b.id][counter] = i + "" + j;
                        counter++
                    }
                }
                x.random(B[b.id])
            }
            if (eff == "rain") {
                x.rain(b)
            }
            if (eff == "swirl") {
                x.swirl(b)
            }
            if (eff == "straight") {
                x.straight(b)
            }
            u[b.id] *= -1;
            if (u[b.id] > 0) {
                B[b.id].reverse()
            }
        };
        x.random = function (f) {
            var d = f.length;
            if (d == 0) {
                return false
            }
            while (--d) {
                var e = Math.floor(Math.random() * (d + 1));
                var b = f[d];
                var c = f[e];
                f[d] = c;
                f[e] = b
            }
        };
        x.swirl = function (c) {
            var m = y[c.id].sph;
            var l = y[c.id].spw;
            var d = 1;
            var e = 1;
            var b = 0;
            var h = 0;
            var f = 0;
            var g = true;
            while (g) {
                h = (b == 0 || b == 2) ? l : m;
                for (i = 1; i <= h; i++) {
                    B[c.id][f] = d + "" + e;
                    f++;
                    if (i != h) {
                        switch (b) {
                        case 0:
                            e++;
                            break;
                        case 1:
                            d++;
                            break;
                        case 2:
                            e--;
                            break;
                        case 3:
                            d--;
                            break
                        }
                    }
                }
                b = (b + 1) % 4;
                switch (b) {
                case 0:
                    l--;
                    e++;
                    break;
                case 1:
                    m--;
                    d++;
                    break;
                case 2:
                    l--;
                    e--;
                    break;
                case 3:
                    m--;
                    d--;
                    break
                }
                check = x.max(m, l) - x.min(m, l);
                if (l <= check && m <= check) {
                    g = false
                }
            }
        };
        x.rain = function (e) {
            var b = y[e.id].sph;
            var g = y[e.id].spw;
            var c = 0;
            var d = to2 = from = 1;
            var f = true;
            while (f) {
                for (i = from; i <= d; i++) {
                    B[e.id][c] = i + "" + parseInt(to2 - i + 1);
                    c++
                }
                to2++;
                if (d < b && to2 < g && b < g) {
                    d++
                }
                if (d < b && b >= g) {
                    d++
                }
                if (to2 > g) {
                    from++
                }
                if (from > d) {
                    f = false
                }
            }
        };
        x.straight = function (b) {
            counter = 0;
            for (i = 1; i <= y[b.id].sph; i++) {
                for (j = 1; j <= y[b.id].spw; j++) {
                    B[b.id][counter] = i + "" + j;
                    counter++
                }
            }
        };
        x.min = function (b, c) {
            if (b > c) {
                return c
            } else {
                return b
            }
        };
        x.max = function (b, c) {
            if (b < c) {
                return c
            } else {
                return b
            }
        };
        this.each(function () {
            init(this)
        })
    };
    x.fn.coinslider.defaults = {
        width: 855,
        height: 299,
        spw: 1,
        sph: 1,
        delay: 3000,
        sDelay: 30,
        opacity: 0.7,
        titleSpeed: 500,
        effect: "random",
        navigation: true,
        links: true,
        hoverPause: true
    }
})(jQuery);
