var t; //flash message timeout
var tw;

function hideFlash(){
    if($('flashMessage')){
        $('flashMessage').fade();
    }
}

function closeFlash(){
    clearTimeout(t);
    if($('flashMessage')){
        $('flashMessage').hide();
    }
    return false;
}

function hideWelcome(){
    if($('welcome_pop')){
        $('welcome_pop').fade();
    }
}

function hideTerms(){
    if($('terms')){
        $('terms').fade();
    }
	return false;
}
function closeWelcome(){
    clearTimeout(tw);
    if($('welcome_pop')){
        $('welcome_pop').hide();
    }
    return false;
}

function closeLogin(){
    clearTimeout(tw);
    if($('login_pop')){
        $('login_pop').hide();
    }
    return false;
}

function checkHash(){
    if(location.hash == '#login'){
        //show login layer
        //$('login_layer').show();
        //$('login_form').show();
    }
}

function initPageDOM(){
    checkHash();
}


function fbs_click() {
    u=location.href;
    t=document.title;
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
    return false;
}

function fadeResults(){
    $('criteria_results').fade({ duration:.2 });
}

function fadeinResults(){
    $('criteria_results').appear({ duration:.4 });
}

function myspaceShare(T, C, U, L){
    var targetUrl = 'http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' + encodeURIComponent(T) + '&c=' + encodeURIComponent(C) + '&u=' + encodeURIComponent(U) + '&l=' + L;
    window.open(targetUrl);
}

function hideForm(form){
    if($(form)){
        $(form).setStyle({ 'visibility':'hidden' });
    }
}
    
function setClicked(clickedId, formElement, type){
    // 1. make sure formElement exists
    if($(formElement)){

        // 2. iterate through all of the elements with a class 'type', turning them all 'off', removeClassName('selected')
        var candidates = $$('a.' + type);
        candidates.each(function(item) {
            if($(item).hasClassName('selected')){
                $(item).removeClassName('selected');
            }
        });

        // 3. see if this is the already selected element; if so, set formElement = 0 to effectively make nothing selected, otherwise set the form value to clickedId
        if($(formElement).value == clickedId){
            $(formElement).value = 0;
        } else {
            $(formElement).value = clickedId;
            $(type + '_' + clickedId).addClassName('selected');
        }
    }
    return false;
}

function setLike(update, large){
    if($(update)){
        if(large){
            $(update).innerHTML = '<span class="like_large">add vote</span>';
        } else {
            $(update).innerHTML = '<span class="like">add vote</span>';
        }        
    }
}

//Event.observe(document, 'dom:loaded', initPageDOM);
Event.observe(window, 'load', function(){ t = setTimeout('hideFlash()', 5500); });
Event.observe(window, 'load', function(){ tw = setTimeout('hideWelcome()', 5500); });