function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}
function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}
/*overstate*/
$(document).ready(function () {
    var toggleStatus = [];
    var contents = [];
    //Created the tabs and hide all but the first
    $("#tab-wrapper").children().each(function (i) {
        contents[i] = $(this);
        if (i > 0)
            $(this).hide();
    });

    $(".tab-top-wrapper").children().each(function (i) {
        toggleStatus[i] = false;
        jQuery(this).click(function () {
            if (toggleStatus[i] == false) {
                for (j = 0; j < toggleStatus.length; j++) {
                    toggleStatus[j] = false;
                    $(contents[j]).hide();
                    $(".tab-top-wrapper").children().removeClass("current");
                }

                $(this).addClass("current");
                toggleStatus[i] = true;
                $(contents[i]).show();
            }
        });
    });

    var innerToggleStatus = [];
    var innerContents = [];
    $("#inner-tab-wrapper").children().each(function (i) {
        innerContents[i] = $(this);
        if (i > 0)
            $(this).hide();
    });

    $(".inner-tab-top-wrapper").children().each(function (i) {
        innerToggleStatus[i] = false;
        jQuery(this).click(function () {
            if (innerToggleStatus[i] == false) {
                for (j = 0; j < innerToggleStatus.length; j++) {
                    innerToggleStatus[j] = false;
                    $(innerContents[j]).hide();
                    $(".inner-tab-top-wrapper").children().removeClass("current");
                }

                $(this).addClass("current");
                innerToggleStatus[i] = true;
                $(innerContents[i]).show();
            }
        });
    });

    var innerToggleStatus2 = [];
    var innerContents2 = [];
    $("#inner-tab-wrapper2").children().each(function (i) {
        innerContents2[i] = $(this);
        if (i > 0)
            $(this).hide();
    });

    $(".inner-tab-top-wrapper2").children().each(function (i) {
        innerToggleStatus2[i] = false;
        jQuery(this).click(function () {
            if (innerToggleStatus2[i] == false) {
                for (j = 0; j < innerToggleStatus2.length; j++) {
                    innerToggleStatus2[j] = false;
                    $(innerContents2[j]).hide();
                    $(".inner-tab-top-wrapper2").children().removeClass("current");
                    $(".inner-tab-top-wrapper2").children().css('opacity', '1');
                }

                $(this).addClass("current");
                $(this).css('opacity', '0.8');
                innerToggleStatus2[i] = true;
                $(innerContents2[i]).show();
            }
        });
    });

    $(".menuoverstate").each(function (i) {

        preload_image = new Image();
        preload_image.src = this.src.replace(".jpg", "_o.jpg");

        $(this).hover(
            function () {
                if (this.src.indexOf("_o.jpg") == -1) {
                    this.src = this.src.replace(".jpg", "_o.jpg");
                }

            },

            function () {
                if (!$(this).hasClass('no-overstate'))
                    this.src = this.src.replace("_o.jpg", ".jpg");

            });

    }
        );

    $(".menuoverstate2").each(function (i) {

        preload_image = new Image();
        preload_image.src = this.src.replace(".gif", "_o.gif");

        $(this).hover(
            function () {
                if (this.src.indexOf("_o.gif") == -1) {
                    this.src = this.src.replace(".gif", "_o.gif");
                }

            },

            function () {
                this.src = this.src.replace("_o.gif", ".gif");

            });

    }
        );

    jQuery("img").hover(function () {
        if (!$(this).hasClass('no-fade'))
            jQuery(this).stop().animate({ opacity: 0.8 }, 200);
    },
        function () {
            if (!$(this).hasClass('current') && !$(this).hasClass('no-fade'))
                jQuery(this).stop().animate({ opacity: 1.0 }, 200);
        });
    jQuery(".fade").hover(function () {
        jQuery(this).stop().animate({ opacity: 0.8 }, 200);
    },
    function () {
        if (!$(this).hasClass('current') && !$(this).hasClass('no-fade'))
            jQuery(this).stop().animate({ opacity: 1.0 }, 200);
    });
    jQuery(".fader").hover(function () {
        jQuery(this).stop().animate({ opacity: 0.8 }, 200);
    },
    function () {
        if (!$(this).hasClass('current') && !$(this).hasClass('no-fade'))
            jQuery(this).stop().animate({ opacity: 1.0 }, 200);
    });
    jQuery(".slideshow-wrapper a img").hover(function () {
        jQuery(this).stop().animate({ opacity: 1.0 }, 200);
    },
        function () {
            jQuery(this).stop().animate({ opacity: 1.0 }, 200);
        });


    /*slideshow
    $(function () {
    var galleries = $('.ad-gallery').adGallery({ number: 1 });
    $('#switch-effect').change(
    function () {
    galleries[0].settings.effect = $(this).val();
    return false;
    }
    );
    $('#toggle-slideshow').click(
    function () {
    galleries[0].slideshow.toggle();
    return false;
    }
    );
    $('#toggle-description').click(
    function () {
    if (!galleries[0].settings.description_wrapper) {
    galleries[0].settings.description_wrapper = $('#descriptions');
    } else {
    galleries[0].settings.description_wrapper = false;
    }
    return false;
    }
    );
    });*/
});


/*hidden text*/
$(document).ready(function () {
    $(".hidden-content").hide();
    $(".q").click(function () {
        $(this).next('.hidden-content').slideToggle('slow');
        $(this).toggleClass('q-close');
    });
});

var slidey;
/*subnav*/
$(document).ready(function () {
    $(".subnav").hide();
    $("#nav-wrapper>.nav>li>a").each(function () {
        var el = $(this);
        var subnav = el.next('.subnav');

        if (subnav.length > 0) {
            el.toggle(function () {
                el.next('.subnav').slideDown('slow');
                el.addClass('current');
            },
            function () {
                el.removeClass('current');
                el.next('.subnav').slideUp('slow');
            });
        }
    });

    $(".slideshow").parents('.fade').hover(function () {
        slidey = $(this).find(".slideshow");
            id = setInterval("slideSwitch()", 2000);
        }, function () { clearInterval(id) }
    );

});

function slideSwitch() {
    var $active = $(slidey).children('IMG.active');
    if ($active.length == 0) $active = $(slidey).children('IMG:last');

    var $next = $active.next().length ? $active.next()
                : $(slidey).children('IMG:first');

    $active.addClass('last-active');

    $next.css({ opacity: 0.0 })
                .addClass('active')
                .animate({ opacity: 1.0 }, 500, function () {
                    $active.removeClass('active last-active');
                });
}
$(document).ready(function () {

    $('.reviewSlideshow').cycle({
        fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
    });
});
