jQuery.ajaxSetup({ 'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")} })

function _ajax_request(url, data, callback, type, method) {
    if (jQuery.isFunction(data)) {
        callback = data;
        data = {};
    }
    return jQuery.ajax({
        type: method,
        url: url,
        data: data,
        success: callback,
        dataType: type
        });
}

jQuery.extend({
    put: function(url, data, callback, type) {
        return _ajax_request(url, data, callback, type, 'PUT');
    },
    delete_: function(url, data, callback, type) {
        return _ajax_request(url, data, callback, type, 'DELETE');
    }
});

jQuery.fn.submitWithAjax = function() {
  this.unbind('submit', false);
  this.submit(function() {
    $.post(this.action, $(this).serialize(), null, "script");
    return false;
  })

  return this;
};

//Send data via get if <ACRONYM title="JavaScript">JS</ACRONYM> enabled
jQuery.fn.getWithAjax = function() {
  this.unbind('click', false);
  this.click(function() {        
    $.get($(this).attr("href"), $(this).serialize(), null, "script");
    return false;
  })
  return this;
};

//Send data via Post if <ACRONYM title="JavaScript">JS</ACRONYM> enabled
jQuery.fn.postWithAjax = function() {
  this.unbind('click', false);
  this.click(function() {
    $.post($(this).attr("href"), $(this).serialize(), null, "script");
    return false;
  })
  return this;
};

jQuery.fn.putWithAjax = function() {
  this.unbind('click', false);
  this.click(function() {
    $.put($(this).attr("href"), $(this).serialize(), null, "script");
    return false;
  })
  return this;
};

jQuery.fn.deleteWithAjax = function() {
  this.removeAttr('onclick');
  this.unbind('click', false);
  this.click(function() {
    $.delete_($(this).attr("href"), $(this).serialize(), null, "script");
    return false;
  })
  return this;
};

//This will "ajaxify" the links
function ajaxLinks(){
    $('.ajaxForm').submitWithAjax();
    $('a.get').getWithAjax();
    $('a.post').postWithAjax();
    $('a.put').putWithAjax();
    $('a.delete').deleteWithAjax();
}

jQuery.fn.showInfo = function() {
  this
  .mouseover( function() {
    $("#d"+$(this).attr("id")).show(); } )
  .mouseout( function() {
    $("#d"+$(this).attr("id")).hide(); } )
  ;
};

$(document).ready(function() {

// All non-GET requests will add the authenticity token
  // if not already present in the data packet
 $(document).ajaxSend(function(event, request, settings) {
       if (typeof(window.AUTH_TOKEN) == "undefined")  return;
       // <ACRONYM title="Internet Explorer 6">IE6</ACRONYM> fix for http://dev.jquery.com/ticket/3155
       if (settings.type == 'GET' || settings.type == 'get') return;

       settings.data = settings.data || "";
       settings.data += (settings.data ? "&" : "") + "authenticity_token=" +
       encodeURIComponent(window.AUTH_TOKEN);
     });

  ajaxLinks();
});
////////////////////////////////////////////////////////////////////////////
$(function() {
  $("menu.main.tabs").tabs("div.main.panes > div", {tabs: 'a.main'}); 
  $("menu.nested.tabs").tabs("div.nested.panes > div", {tabs: 'a.nested'});
});
$(function(){
	$(".t").simpletooltip();
  $(".pi").showInfo();
  $(".cel img").simpletooltip();
  $("div.scrollable").scrollable().mousewheel();
  $("#account a").overlay();
}); 
$(function() {
  $(".items img").click(function() {  
    var src = $(this).attr("src").replace("thumbnail_", "normal_");
    var url = $(this).attr("alt");
    $("#picwrap h2").html($(this).attr("title"));
    var wrap = $("#picwrap").fadeTo("medium", 0.5); 
    var img = new Image(); 
    img.onload = function() { 
        wrap.fadeTo("fast", 1);  
        var foundimg = wrap.find("img");
        wrap.find("a").attr("href", "/"+foundimg.attr("alt")+"/"+url); 
        foundimg.attr("src", src);     
    };  
    img.src = src;  
  }).filter(":first").click();
});

