﻿function get_cookie(cookie_name) {
    var results = document.cookie.match('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');

    if (results)
        return (unescape(results[2]));
    else
        return null;
}

$(document).ready(function() {
    var twitterFeeds = new Array();

    twitterFeeds["austin"] = "http://twitter.com/LoneStarBeerATX/";
    twitterFeeds["san_antonio"] = "http://twitter.com/LoneStarBeerSA/";
    twitterFeeds["dallas"] = "http://twitter.com/lonestardallas/";
    twitterFeeds["houston"] = "http://twitter.com/lonestargrrl/";

    var defaultCity = (get_cookie("city") != null) ? get_cookie("city") : "austin";
    $(".subcontent_block .nav2 .tabs a." + defaultCity).addClass("active");
    $("#twitter_feed #" + defaultCity).attr("style", "display: block");
    $("#twitter_link").attr("href", twitterFeeds[defaultCity]);

    jQuery("span.timeago").timeago();

    $(".nav2 .tabs a").bind("click", function() {
        $(".subcontent_block .nav2 .tabs a").removeClass("active");
        $("#twitter_feed .tweet_container").attr("style", "display: none;");

        var newCity = $(this).attr("class").replace(" active", "");
        $(".subcontent_block .nav2 .tabs a." + $(this).attr("class")).addClass("active");
        $("#" + newCity).attr("style", "display: block;");
        $("#twitter_link").attr("href", twitterFeeds[newCity]);
        document.cookie = "city=" + newCity + "; expires=01/01/2020";

        return false;
    });
});
