var ChoosePhoneDropdown = {
	containerElem: null, 
	hideRevealElem: null, 
	init: function() {
		var that = this;
		this.containerElem = $("div#phoneChoice");
		this.hideRevealElem = this.containerElem.find("ul:first");
		this.collapse(false);
	},
	expand: function(showAnimation) {
		var that = this;
		if (showAnimation) {
			this.hideRevealElem.slideDown("fast");
		}
		this.containerElem.removeClass("collapsedChoice").removeAttr("tabIndex");
		
		this.containerElem.unbind("click").click(function() {
			that.collapse(true);
		});
	}, 
	collapse: function(showAnimation) {
		var that = this;
		if (showAnimation) {
			this.hideRevealElem.slideUp("fast");
		}
		this.containerElem.addClass("collapsedChoice").addClass("clickable").attr("tabIndex", "0");
		
		this.containerElem.unbind("click").click(function() {
			that.expand(true);
		});
	}

}


// learn.html tabbed content 
var Tabs = {

	init: function() {

		$("div.tabContainer ul.tabs a, div.tabContainer ul.nestedTabs a").click(function(e) {

			var link = $(this);
			link.parents("li:eq(0)").addClass("activeTab").siblings(".activeTab").removeClass("activeTab");
			$(link.attr("href")).addClass("selectedTab").siblings(".selectedTab").removeClass("selectedTab");

			//e.preventDefault();
			return false;

		});

	}

}

// country select
var countrySelect = {
    containerElem: null,
    hideRevealElem: null,
    init: function() {
        var that = this;
        this.containerElem = $("div.countrySelect");
        this.hideRevealElem = this.containerElem.find("div:availableCountryList");
        this.listChangeElem = $("ul.countrySelectLinks");
        this.collapse(false);
    },
    expand: function(showAnimation) {
        var that = this;
        if (showAnimation) {
            this.hideRevealElem.slideDown("fast");
        }
        this.containerElem.removeClass("collapsedChoice").removeAttr("tabIndex");
        this.listChangeElem.addClass("whiteTab");

        this.containerElem.unbind("click").click(function() {
            that.collapse(true);
        });
    },
    collapse: function(showAnimation) {
        var that = this;
        if (showAnimation) {
            this.hideRevealElem.slideUp("fast");
        }
        this.containerElem.addClass("collapsedChoice").addClass("clickable").attr("tabIndex", "0");
        this.listChangeElem.removeClass("whiteTab");
        
        this.containerElem.unbind("click").click(function() {
            that.expand(true);
        });
    }

}


// widget country select
var widgetCountrySelect = {
    containerElem: null,
    hideRevealElem: null,
    init: function() {
        var that = this;
        this.containerElem = $("div.widgetCountrySelect");
        this.listChangeElem = $("ul.widgetCountrySelectLinks");
        this.hideRevealElem = this.containerElem.find("div:widgetAvailableCountryList");
        this.collapse(false);
    },
    expand: function(showAnimation) {
        var that = this;
        if (showAnimation) {
            this.hideRevealElem.slideDown("fast");
        }
        
        this.containerElem.removeClass("collapsedChoice").removeAttr("tabIndex");
        this.listChangeElem.addClass("whiteTab");
        
        this.containerElem.unbind("click").click(function() {
            that.collapse(true);
        });
    },
    collapse: function(showAnimation) {
        var that = this;
        if (showAnimation) {
            this.hideRevealElem.slideUp("fast");
        }
        this.containerElem.addClass("collapsedChoice").addClass("clickable").attr("tabIndex", "0");
        this.listChangeElem.removeClass("whiteTab");
        
        this.containerElem.unbind("click").click(function() {
            that.expand(true);
        });
    }

}

// country availability
var textAvailability = {
    init: function() {
        $("#textAvailabilityLink").click(function() {
            $("iframe#textAvailability").attr("src", $(this).attr("href"));
            return false;
        });
    }
}

jQuery().ready(function() {

	Tabs.init();
	ChoosePhoneDropdown.init();
	textAvailability.init();
	countrySelect.init();
	widgetCountrySelect.init();

});