var bgFill = false;
$(document).ready(function(){
    $(".uiStyle").addClass("text ui-widget-content ui-corner-all");
    $("button").addClass("ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only");
    $("#loginLink").click(function(){
        bgFill = false;
        if($("#loginLinkWrapper").hasClass("loginLink"))
        {
            bgFill = true;
            $("#loginLinkWrapper").removeClass("loginLink");
            $("#loginLinkWrapper").addClass("loginLinkSelected");
        }
        
        $("#loginPanel").slideToggle(250, function()
        {
            if($("#loginLinkWrapper").hasClass("loginLink") == false)
            {
                if(bgFill == false)
                {
                    $("#loginLinkWrapper").addClass("loginLink");
                    $("#loginLinkWrapper").removeClass("loginLinkSelected");
                }

                $("#loginUsername").focus();
            }
        });
        return false;
    })
});

$(document).keydown(function(e) {
    if (e.keyCode == 27) {
        $("#loginLink").click();
    }
});

function setDefaultPointer()
{
	if(typeof($("#longUrl")) != "undefined")
	{
		$("#longUrl").focus();
	}
}

function bookmarksite(title, url)
{
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}

function setupTerms()
{
    $( "#termsContent" ).dialog({
        width: 650,
        modal: true,
        draggable: false,
        resizable: false,
        buttons: [
            {
                text: "Close",
                click: function() { $(this).dialog("close"); }
            }
        ]
    });
}

function showTerms()
{
    setupTerms();
}

function setupAPI()
{
    $( "#apiContent" ).dialog({
        width: 650,
        modal: true,
        draggable: false,
        resizable: false,
        buttons: [
            {
                text: "Close",
                click: function() { $(this).dialog("close"); }
            }
        ]
    });
}

function showAPI()
{
    setupAPI();
}

function destroyAPIPopup()
{
	var oldInnerHTML = $("apiContent").innerHTML;
	YAHOO.shorturl.apiContent.destroy();
	
	/* create new container */
	var ni 				= document.getElementById('popupContainerAPI');
	var newdiv 			= document.createElement('div');
	newdiv.setAttribute('id', 'apiContent');
	newdiv.innerHTML 	= oldInnerHTML;
	ni.appendChild(newdiv);
	
	/* hide container */
	$("popupContainerAPI").style.display = "none";
}

function destroyPopup()
{
	var oldInnerHTML = $("termsContent").innerHTML;
	YAHOO.shorturl.termsContent.destroy();
	
	/* create new container */
	var ni 				= document.getElementById('popupContainer');
	var newdiv 			= document.createElement('div');
	newdiv.setAttribute('id', 'termsContent');
	newdiv.innerHTML 	= oldInnerHTML;
	ni.appendChild(newdiv);
	
	/* hide container */
	$("popupContainer").style.display = "none";
}

function showHideStatsTab(id)
{
    if($("currentTab").value.length > 0)
    {
            $($("currentTab").value).style.display = "none";
    }
    $("currentTab").value = id;
    $(id).style.display = "block";
    return false;
}

function showHideTip(ele)
{
    $('.formTip').addClass('hidden');
    $('#'+ele.id+'Tip').removeClass('hidden');
}

$(function() {
    $("button, input:submit").button();
});