$(document).ready(function() {
    $( ' span#close ' ).click(function(){
        $( ' span#close ' ).html('<p id="loading"><img src="images/spinner.gif"/></p>').load('config.php?close');
        $( ' #pranesimas-order ' ).fadeOut();
                    
    });
    $('div.accordionButton').click(function() {
        $('div.accordionContent').slideUp('normal');	
        $(this).next().slideDown('normal');
    });
    $(" #toggle-side ").click(function(){
        $( ' #sidebar .content ' ).stop(true, false).slideToggle();
    });
    
    $('#social .item').hover(function() {
        $(this).stop(true, false).animate({
            "bottom":"+11px"
        });
    },function(){
            $(this).stop(true, false).animate({
            "bottom":"-11px"
        });
        });
    
    $("#login-button").click(function(){
        $("#login-box").stop(false, true).slideToggle();
    });
//    $('#login-box').mouseleave(function() {
//        setTimeout(slideup,2500);
//    });
    
    setTimeout(slideup,10000);
    screenshotPreview();
    areatooltip();
    
    $('a[rel*=facebox]').facebox()
    $('#naujienos .item .footer .komentarai ,.accordionButton,#kategorijos .item div,#naujienos .item #item-header ,#header #cart p,#pranesimas-order,#pamoka #player').corner('5px');
    $('#shop #preke .title,span#order-head').corner(' top 5px');
    $('#tooltip,#cancel').corner('8px');
    $('#shop #preke .buttons , #sidebar .item .shop .shop-button').corner(' bottom 5px');
});
function paging(sk,vs,order){
    $('#naujienos').html('<div id="loader" style="position:relative; top:50px; left:304px;"><img src="img/loading.gif" /></div>');
    $('#naujienos').load('new.php?nuo='+sk+'&viso='+vs+'&ord='+order);
    $('html, body').animate({
        scrollTop:0
    }, 'slow');
}
function sortas(kas){
    $('#kategorijos .item span').removeClass('now');
    if(kas == '0'){
        $('#kategorijos .item .visos').addClass('now');
    }
    if(kas == 'v'){
        $('#kategorijos .item .vidaus').addClass('now');
    }
    if(kas == 'p'){
        $('#kategorijos .item .pasaulio').addClass('now');
    }
    $('#naujienos').html('<div id="loader" style="position:relative; top:50px; left:304px;"><img src="img/loading.gif" /></div>');
    $('#naujienos').load('new.php?ord='+kas);
}
function slideup(){
    $('#pranesimas').slideToggle('slow')
    $('#error').slideToggle('slow');
    $("#login-box").slideUp();
}
function kaka(){
    var option = $('input:radio:checked').val();
    $('#vote').html('<p><img id="loader" src="facebox/loading.gif" /></p>');
    $.ajax({
        type: "POST",
        url: "vote.php",
        data: "option="+option,
        success:function(html) {
            $('#vote').html(html);
        }
    });
}
this.screenshotPreview = function(){
    /* CONFIG */
		
    xOffset = 10;
    yOffset = 30;
		
    // these 2 variable determine popup's distance from the cursor
    // you might want to adjust to get the right result
		
    /* END CONFIG */
    $("a.screenshot").hover(function(e){
        this.t = this.title;
        this.title = "";	
        var c = (this.t != "") ? "<br/>" + this.t : "";
        $("body").append("<p id='screenshot'><img align='center' height='100' width='100' src='"+ this.rel +"' alt='image' />"+ c +"</p>");								 
        $("#screenshot")
        .css("top",(e.pageY - xOffset) + "px")
        .css("left",(e.pageX + yOffset) + "px")
        .fadeIn("slow");						
    },
    function(){
        this.title = this.t;	
        $("#screenshot").remove();
    });	
    $("a.screenshot").mousemove(function(e){
        $("#screenshot")
        .css("top",(e.pageY - xOffset) + "px")
        .css("left",(e.pageX + yOffset) + "px");
    });			
};

this.areatooltip = function(){
    /* CONFIG */		
    xOffseta = 10;
    yOffseta = 20;		
    // these 2 variable determine popup's distance from the cursor
    // you might want to adjust to get the right result		
    /* END CONFIG */		
    $(".areatooltip").hover(function(ea){											  
        this.ta = this.title;
        this.title = "";									  
        $("body").append("<p id='tooltip'>"+ this.ta +"</p>");
        $("#tooltip")
        .css("top",(ea.pageY - xOffseta) + "px")
        .css("left",(ea.pageX + yOffseta) + "px")
        .fadeIn("fast");		
    },
    function(){
        this.title = this.ta;		
        $("#tooltip").remove();
    });	
    $("area.areatooltip").mousemove(function(ea){
        $("#tooltip")
        .css("top",(ea.pageY - xOffseta) + "px")
        .css("left",(ea.pageX + yOffseta) + "px");
    });			
};

