jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
jQuery.fn.delay = function(time,func){
    return this.each(function(){
        setTimeout(func,time);
    });
};

lastRequest = "";
requestStatus = "ok";
$.BuzzAjax = function($vars,$config){  
	
	if(!$config){
		$config = {
			dataType: 'html',
			type: 'post',
			data: $($vars.form).serialize(),
			timeout: 10000,
			cache:false
		}	
	}
	
	
	
	if(requestStatus == "ok" ){
		
		try{
			
			$.ajax({ 
					dataType: $config.dataType, 
					url: $vars.url, 
					
					beforeSend: function() 
					{
						
						requestStatus = "sending";
						$($vars.fieldLoading).html($vars.loading);
						lastRequest = $vars.url;
						
					} , 
					
					error: function(event, request, settings) 
					{ 
						
						$($vars.fieldLoading).html($vars.errorMessage);
						requestStatus = "ok";
						
						$(this).delay(2000,function(){
							$($vars.fieldLoading).html($vars.reconectingMessage);
							loadContent(paramUrl);
							requestStatus = "sending";
						});	
						
					} , 
					
					success: function(data) 
					{
						$($vars.fieldContent).html(data);
					} , 
					
					complete: function() 
					{ 
						
						$($vars.fieldLoading).html('');
						//$($vars.campo_conteudo).show();
						requestStatus = "ok";
					},
					timeout : $config.timeout,
					cache : $config.cache
		  });
			
	}catch(e){
		
		//alert($vars.linkError);
		requestStatus = "ok";
		
	}
		
  }else{
	  
	  $($vars.fieldLoading).html($vars.loading+" <strong>J&aacute; est&aacute; sendo executada essa a&ccedil;&atilde;o</strong>!");

  }
}

/*Funcoes especificas*/
/*Indications*/
$.ajaxIndications = function(){
	
	$vars = {
		fieldLoading: "#nehumcampo",
		fieldContent: ".conteiner_indications_ajax",
		loading: "Carregando conte&uacute;do...",
		errorMessage: "Erro! Atualize o navegador ou aguarde.",
		reconectingMessage: "Aguarde... Reconectando!",
		linkError: "Link errado!"
	}
	
	$("a[rel='indicar_livro']").click(function(){
											  
		if(!$.cookie('indicou_livro')){
			$vars.url = $(this).attr("href");
			$.BuzzAjax($vars,false);
		}else{
			$(this).html("Indicado!");
		}
		$.cookie('indicou_livro', 1);
		return false;
		
	});
	
	
	$("a[rel='indicar_musica']").click(function(){
											  
		if(!$.cookie('indicou_musica')){
			$vars.url = $(this).attr("href");
			$.BuzzAjax($vars,false);
		}else{
			$(this).html("Indicado!");
		}
		$.cookie('indicou_musica', 1);
		return false;
		
	});
	
	
	$("a[rel='indicar_filme']").click(function(){
											  
		if(!$.cookie('indicou_filme')){
			$vars.url = $(this).attr("href");
			$.BuzzAjax($vars,false);
		}else{
			$(this).html("Indicado!");
		}
		$.cookie('indicou_filme', 1);
		return false;
		
	});
	
	
}




