var site_url = site_url();

function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

function loadBox(key,login) {
    tb_show("", site_url + "wordpress/wp-login.php?sub=y&action=rp&key=" + key + "&login=" + login + "&KeepThis=true&TB_iframe=true&height=315&width=500");
}

$(document).ready(function(){
    
    var actionParam = getUrlVars()["action"];
    var loginBoxParam = getUrlVars()["login_box"];
    
    //if reset password
    if (actionParam=='rp') {
        var keyParam = getUrlVars()["key"];
        var loginParam = getUrlVars()["login"];
        loadBox(keyParam,loginParam);
    }
    
    //if login box is true
    if (loginBoxParam=='true') {
        tb_show("","#TB_inline?height=215&width=300&inlineId=login_form");
    }
        
    $('.audio_file').jmp3({
        width: 150,
    	showdownload: "true",
    	showfilename: "false"
    });
    
    $('marquee').marquee();
    
    //this sets the rel to mirror the default value for comparing to value on focus on blur below
    var searchDefault = $('#searchbox').attr('value');
    $('#searchbox').attr('rel', searchDefault);
    
    // on focus check if value has been changed and clear if it hasn't been
    $('#searchbox').focus(function() {
        $this = $(this);
        var def = $this.attr('rel');
        var current = $this.attr('value');
        
        if (current == def) {
            $this.attr('value','');
        }
    });
    
    // on blur check if value is blank, if yes reset back to defaul
    $('#searchbox').blur(function() {
        $this = $(this);
        var def = $this.attr('rel');
        var current = $this.attr('value');
        
        if (current == "") {
            $this.attr('value',def);
        }
    });
    
    /*$('#btn_recover_password').click(function() {
        $('#inner_login').hide('fast', function() {
            $('#inner_recover_password').show('fast');
        });
        return(false);
    });
    
    $('#wp-recover-submit').click(function() {
        var formAction = $('#lostpasswordform').attr('action');
        var userEmail = $('#lostpasswordform input[name="user_login"]').attr('value');
        $.get(formAction, { user_login: userEmail }, function(data){
             alert(data);
             //alert(data.search(/login_error/i));
                //get error massage and display it
            // else
                //get message text and display it
            $('#demo').html(data);
            
        });
        return(false);
    });*/
});