// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
$(window).load(function() {
    /*$('.buttonOff').mouseover(function(){
        $('#buttonOn_' + this.id.split("_")[1]).appear(200);
        return false;
    })

    $('.buttonOn').mouseout(function(){
        $(this).fadeOut(200);
    })

*/
    $("ul#main_navigation2 li").each(function(){
        $(this).html('<img src="/images/sl-nav-s.gif" alt="Swindon Link" />' + $(this).html());
    })

    $("ul#main_navigation2 li:not(.active) a").mouseover(function(){
        $(this).prev().fadeIn("fast");
    }).mouseout(function(){
        $(this).prev().fadeOut("fast");
    })



    
});

function imagazine_go() {
    if($("#imagazine").attr("value")!="nogo") {
        document.location = $("#imagazine").attr("value");
    }
}




/*
 * Sending forms with Ajax
 *
 */
jQuery.ajaxSetup({
    'beforeSend': function(xhr) {
        xhr.setRequestHeader("Accept", "text/javascript")
    }
})

/*
 * handler - function passed to handle form response
 */

jQuery.fn.submitWithAjax = function(handler) {
    this.submit(function() {
        $.post(this.action, $(this).serialize(),
            handler);
        return false;
    })
    return this;
};


/*
 * Mouseover popup
 */

tooltipMove = function(object,event) {
    var tPosX = event.pageX+20;
    var tPosY = event.pageY - 20;


    $(object).css({
        top: tPosY,
        left: tPosX
    });
}


$(function(){
    $('.img_wrapper_with_tooltip').mousemove(function(event){
        tooltipMove('#tooltip_preview',event);
        
    }).mouseover(function(event){
        $('#tooltip_status').css("display","block");
        $('#tooltip_content').html("");
        tooltipMove('#tooltip_preview',event);

        
        url = $(this).next().children('h2').children('a').attr('href');

        $.post(url,{
            _method: 'put',
            authenticity_token: window._auth_token
        }, function(data) {
            $data = JSON.parse(data);
            $('#tooltip_status').css("display","none")
            $('#tooltip_content').html("<h1>"+$data.title+"</h1>"+$data.body);
        })
        $('#tooltip_preview').fadeIn("fast");
    }).mouseout(function(){
        $('#tooltip_preview').fadeOut("fast");
        
    });


    
})
