﻿//center element
jQuery.fn.centerScreen = function(opts) {
    return jQuery(this).each(
    function() {
        if (opts == null || opts.frame == null)
            opts = { frame: jQuery(window) };

        jQuery(this).css("top", (opts.frame.height() / 2) - (jQuery(this).height() / 2)).css("left", (opts.frame.width() / 2) - (jQuery(this).width() / 2));
    });
};
//accordian
jQuery.fn.accordian = function() {
    return jQuery(this).each(function() {

        var hash = document.location.hash;
        hash = hash.replace("#", "");
        jQuery(".accBody", this).hide();

        var accItem = jQuery("a[name='" + hash + "']", this)
                .parent(".accItem")
                .first();

        if (accItem.length > 0) {
            jQuery(".accHead", accItem).hide();
            jQuery(".accBody", accItem).show();
        }

        var maxHeight = 0;
        var headerHeight = 0;
        jQuery(".accHead", this).each(function() {
            headerHeight += jQuery(this).height();
        });

        jQuery(".accBody", this).each(function() {
            var currentHeight = jQuery(this).height();
            if (currentHeight > maxHeight)
                maxHeight = currentHeight;
        });
        //jQuery(this).height(2 * (maxHeight + headerHeight));
        jQuery(".accHead", this).click(function() {
            var accGroup = jQuery(this).parents(".accGroup");

            jQuery(".accHead", accGroup)
                .slideDown();
            jQuery(this).hide();
            jQuery(".accBody", accGroup).slideUp();
            jQuery(this).next(".accBody").slideDown();

        });
    });

};

//image mouseovers
jQuery.fn.imageMouseOver = function(opts) {
    return jQuery(this).each(function() {
        var defaults = { ext: "_o", useSibling: false };
        var settings = jQuery.extend(defaults, opts);
        var src = jQuery(this).attr("src");
        var mo = src;
        if (settings.useSibling) {

            if (jQuery(this).next("img.ui-mosrc").length > 0) {
                mo = jQuery(this).next("img.ui-mosrc").first().attr("src");
            }
        }
        else {
            var imageTypes = [".gif", ".jpg", ".jpeg", ".png"];
            for (var i = 0; i < imageTypes.length; i++) {
                if (src.indexOf(imageTypes[i]) > 0) {
                    mo = src.replace(imageTypes[i], settings.ext + imageTypes[i]);
                }
            }
        }
        if (mo != src) {
            jQuery.preLoadImages(mo);
            jQuery(this).hover(function() { jQuery(this).attr("src", mo); }, function() { jQuery(this).attr("src", src); });
        }
    });
}
var imageCache = [];
jQuery.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--; ) {
        var cacheImage = document.createElement('img');
        cacheImage.src = arguments[i];
        imageCache.push(cacheImage);
    }
};




jQuery(document).ready(function () {
    setTimeout("scrollWinners()", 5000);
});
function scrollWinners() {
    var index = jQuery("#winners_list div:visible").index();
    index++;
    if (index >= jQuery("#winners_list div").length)
        index = 0;


    jQuery("#winners_list div:visible").hide("slow", function () {
        jQuery("#winners_list div").eq(index).show("slow", function () { setTimeout("scrollWinners()", 5000); });
    });

}
