
/*overstate*/
$(document).ready(function() {
    $(".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() {
                this.src = this.src.replace("_o.jpg", ".jpg");

            });
    }
        );

    $(".ql-item a").hover(function() {
        $(this).find("[class*=bottom]").addClass("ql-item-on");
    },
    function() {
        $(this).find("[class*=bottom]").removeClass("ql-item-on");
    });

    $(".ql-big-item a").hover(function() {
        $(this).find("[class*=bottom]").addClass("ql-big-on");
    },
    function() {
        $(this).find("[class*=bottom]").removeClass("ql-big-on");
    });

    $("#about-gallery a").fancybox();
    $("#sendtofriend").fancybox();

    // slideshow for main genre boxes
    $(".ql-big-item, .ql-item").each(function() {
        var events = $(this).children("a");
        if (events.length > 1) {
            events.hide();
            $(events[0]).show();
            $(events).css("float", "left");
            $(events).css("position", "absolute");
            var index = 0;
            setInterval(function() {
                var newIndex = index + 1;
                if (newIndex == events.length)
                    newIndex = 0;

                $(events[index]).fadeOut(2000);
                $(events[newIndex]).fadeIn(2000);
                index = newIndex;
            }, 6000);
        }
    });

    // attempt to load twitter, facebook and flickr feeds

    $(document).ready(function() {

        $.getJSON('https://twitter.com/status/user_timeline/themaltings.json?count=1&callback=?', function(data) {
            for (var i in data) {
                var date = data[i].created_at.split('GMT')[0].replace('+0000', '');
                var text = data[i].text;

                text = text + ' ';
                text = text.replace(/http:\/\/(.+?)\s/g, '<a href="http://$1">http://$1</a>');
                text = text.replace(/@(.+?)\b/g, "<a href=\"http://www.twitter.com/$1\">@$1</a> ");
                text = text.replace(/#(.+?)\b/g, "<a href=\"http://www.twitter.com/?q=#$1\">#$1</a> ");

                $("#twitter-container").html(text);
            }
        });

        /*
        $.getJSON('https://graph.facebook.com/1431650218/feed?callback=?&limit=3', function(data) {
            var facebookPosts = [];
            for (var i = 0; i < 3 && i < data['data'].length - 1; i++)
                facebookPosts[i] = data['data'][i].message;

            var index = 1;
            $("#facebook-container").html(facebookPosts[0]);

            setInterval(function() {
                $("#facebook-container").fadeOut(500, function() {
                    $("#facebook-container").html(facebookPosts[index]).fadeIn(500);
                });
                index++;
                if (index > facebookPosts.length - 1)
                    index = 0;
            }, 6000);
        });
        */
      
    });
});

