/*====== форма поиска ========*/
function getPrompt(e){
    if( LAST_SEARCH == $('#searchStr').val() )
        return;
    LAST_SEARCH = $('#searchStr').val();
    var exp = new Date();
    exp.setTime(exp.getTime() + (60*60*1000));
    setCookie('lastSearch', encodeURIComponent($('#searchStr').val()), exp, '/'); /*encodeURIComponent*/

    if(('none'==$('#prompt').css('display')) ){
        if($('#searchStr').val()){
            $('#prompt').css({  'left':$('#searchFormDiv').offset().left-$('#prompt').width()+$('#searchFormDiv').width(),
                                'top' :$('#searchStr').offset().top+$('#searchStr').height()+4+'px'});
            $('#prompt').fadeIn('slow');
        }
    } else {
        if(!$('#searchStr').val()){
            $('#prompt').fadeOut('slow');
            $('#searchForm').focus();
        }
    }
    $('#prompt').load('/tpl.search.x.php', {'string':$('#searchStr').val()},
        function(){
            LAST_SEARCH=$('#searchStr').val();
            $('#prompt')[0].selectedIndex=-1;
        }
    );
}

function doSelect(){
    $('#searchStr').val($('#prompt').val());
    $('#prompt').fadeOut('slow');
}

$(document).ready(function(){
    LAST_SEARCH=$('#searchStr').val();
    setInterval(getPrompt, 250);
    $('#searchForm').submit(function(){var exp = new Date();exp.setTime(exp.getTime() + (60*60*1000));setCookie('lastSearch', encodeURIComponent($('#searchStr').val()), exp, '/');})
    $('#prompt, #searchStr').keydown(function(e){
        if (13==e.which){
            $('#searchStr').val($('#prompt').val());
            $('#prompt').fadeOut('slow', function(){
                $('#searchForm').submit();
            });
        }
        if((this.id=='searchStr') && (40==e.which) && ('none'!=$('#prompt').css('display'))){ /*down*/
            $('#prompt').focus();
            return;
        }
        if (27==e.which){
            $('#prompt').fadeOut('slow');
            $('#searchForm').focus();
        }
    });
    $(window).keyup(function(e){
        if (27==e.which){
            $('#prompt').fadeOut('slow');
            $('#searchForm').focus();
        }
    });
    if($.browser.msie && parseInt($.browser.version)<7 ){
        $("body").css("filter","xray()");
        $("#ie6-shit").fadeIn(5000);
    }
    

});
/*====== eof форма поиска ========*/

$(document).ready(function(){
   activateGoodiesTree();
   $("*:not(a)", ".boxed").hover(
        function(){$(".title", $(this).parent(".boxed")).css("background-position", "0 -30px")}, 
        function(){$(".title", $(this).parent(".boxed")).css("background-position", "0 0")}
   );
});

function activateGoodiesTree(){
var chOf=op="";
    if(op=getCookie("openedGoodies")){
           do{
               $("#goodiesTree #g-"+op).addClass("expanded");
               chOf="";
               $($("#goodiesTree #g-"+op)[0].className.split(/\s+/))
                   .each( function(i, s){ if( s.indexOf("ch-of-")>=0 ) chOf=s.replace("ch-of-g-", "") });
               op=chOf;
        } while(chOf);
           $("#goodiesTree #g-"+getCookie("openedGoodies")).css("font-weight", "bold");
    }
    $("#goodiesTree").treeTable({indent:15,  childPrefix: "ch-of-"});
    $("#goodiesTree .theRow").hover(function(){$(this).addClass("trHi")}, function(){$(this).removeClass("trHi")} );
    $("#goodiesTree a").click(function(){
        setCookie("openedGoodies", $(this).parents("tr:first").attr("id").replace("g-", ""), 24*60*60, "/" );
    });
}


function showWindow( id ){
	$("#"+id).css({ left:($("body").width()-$("#"+id).width())/2, top :$(document).scrollTop()+50} );
	$("#"+id).fadeIn("slow");
}

function sendToFriend(){
var regex = new RegExp("^[_\\.0-9a-z-]+@([0-9a-z][0-9a-z_-]+\\.)+[a-z]{2,4}$");

    if (!$.trim($('#FF_myMail').val()) || !regex.test($('#FF_myMail').val()) ){
        alert('Введите свой адрес');
        return;
    }
    if (!$.trim($('#FF_friendMail').val()) || !regex.test($('#FF_friendMail').val()) ){
        alert('Введите адрес друга');
        return;
    }
    if (!$.trim($('#FF_Message').val())  ){
        alert('Отказываюсь отправлять пустое сообщение');
        return;
    }
    $().ajaxStop(function(){$.unblockUI();});
    $.blockUI.defaults.overlayCSS={backgroundColor: '#555',opacity:'0.5'};
    $.blockUI("<h1 style='text-align:center'><img src='/design/ext/lb.loading.gif' alt='ожидаем'><br>отправляем...</h1>");
    $('#sendResult').load("/sys.friendSender.x.php", {"myMail":$('#FF_myMail').val(), 'frMail':$('#FF_friendMail').val(), 'frMess':$('#FF_Message').val()},
        function(){
            $('#reminder').show("slow");
    });
}






