// steve@damionhickman.com 06/15/11 10:50:13
$(document).ready(function () {
    var $shimmers = $("button.shimmer");
    if ($shimmers.length > 0) {
        $shimmers.each(function () {
            var href = $(this).attr('href');
            var text = $(this).html();
            
            var $div = $("<div />").addClass("shimmer-contain").append("<div class='shimmer-button'></div><div class='shimmer-box shimmer-overlay'><table style='height: 130px; margin-left: 3px'><tr><td align=center valign=center>"+text+"</td></tr></table></div>").data("href",href);
            $(this).after($div);
            $(this).remove();
            $div.click(function () {
                //determine if it's a popup window we need to execute
                if ($(this).data("href").indexOf("popup://") == 0) {
                    var thehref = $(this).data("href").split("popup://").join('');
                    
                    /*
                     $.fancybox({
                                'width': '70%',
                                'height': '70%',
                                'autoScale': true,
                                'transitionIn': 'fade',
                                'transitionOut': 'fade',
                                'type': 'iframe',
                                'href': thehref
                      });
                    */
                    
                    window.open(thehref,'mywindow');
                } else {
                    
                    window.location.href = $(this).data("href");
                }
            }).find(".shimmer-box").mouseenter(function () {
                $(this).prev().addClass("shimmer-button-over");
            }).mouseleave(function () {
                $(this).prev().removeClass("shimmer-button-over");
            });
            setTimeout(function () {
            setInterval(function () {
                $div.find(".shimmer-overlay").animate({backgroundPosition:'0px -160px'}, 500, function () {
                    $(this).removeAttr('style');
                });
            }, 2000);
            }, Math.round(Math.random() * 1000));
        });
    }
});

